Magento – Magento – Expected Delivery date on Product Page

deliveryproduct

In magento, how to setup Expected Delivery date option in the product page itself. Choosing this date(Expected Delivery) and then add the product to cart.

If the customer has order more than 1 products,(ie) if the cart have 3 products then 3 products may have different delivery date.

The customers can able to place a single order with multiple different dispatch dates? I.E Product A, B & C dispatched on Tuesday, Thursday & Friday.

If the delivery date is selected from the customer then it(delivery date) should display in cart / checkout and order pages.

The Customer can choose their delivery date as they prefered in the product page.

Any Ideas?

Best Answer

Your question is a little vague. Would you like the customer to select a delivery date that THEY would prefer or are the ADMIN to be able to indicate a delivery date that the customer can expect to receive his/her order.

I'm assuming the latter:

You can set up a custom attribute via:

  1. Catalog->Attributes->Manage Attributes
  2. Click Create New Attribute on the top right hand side of the page
  3. Set up the attribute as Date under Catalogue Input Type for Shop Owner
  4. Visible on Product View Page on Front-end should be set to Yes
  5. Used in Product Listing should be set to Yes
  6. Give it an appropriate label under Label Options

Obviously managing this attribute over your whole catalogue isn't really going to be a viable option, and as such it would be wiser to set up a Cron Job which runs daily to populate the date fields.

Your cron job script should look something like (note that the $mageFilename should be the directory path to your Mage.php file under the app directory)

<?php
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$date = Mage::getModel('core/date')->timestamp(time());
$date = date('Y/m/d H:i:s', strtotime($date . ' + x days')); //x should be the numeric value of how many days from now delivery would be possible
$connection = _getConnection('core_read');
$sql = 'SELECT * FROM catalog_product_entity';
$products = $connection->fetchAll($sql);
$connection = _getConnection('core_write');
foreach ($products as $product){
    $sql = 'UPDATE catalog_product_entity_date SET value = ? WHERE attribute_id = ? AND entity_id = ?';
    $connection->query($sql, array($date, your_attribute_id, $product['entity_id']));
}

function _getConnection($type = 'core_read'){
    return Mage::getSingleton('core/resource')->getConnection($type);
}


?>

You can figure out what your_attribute_id is after saving the attribute and looking at the URL on the page, it'll be something like:

catalog_product_attribute/edit/attribute_id/599/key/

In the above EXAMPLE the attribute_id is 599, you must find out what YOUR attribute ID is.

The reason you should use SQL like this to perform the task as opposed to ORM is because using ORM across your whole catalog selection will probably be quite time & resource intensive, this script on the other hand will function very efficiently.

You'll need to make this attribute visible on your product template page as well. (https://stackoverflow.com/questions/3110076/magento-echo-attribute-on-product-page)

You'll also want to edit your default templates to reflect this value on the order confirmation/delivery & invoice email template (http://www.magentocommerce.com/boards/viewthread/15411/)

Good luck.

Related Topic