Implementing Estimated Delivery Date on Magento Product Grid & Page
Hello! I understand you’re looking to display an estimated delivery date on both your product grid (category page) and individual product pages in Magento. You want the delivery estimate to vary based on location and update automatically each day, as demonstrated by India Bazaar Online.
Let’s dive into how you can achieve this functionality without needing to select a specific delivery date manually.
Understanding the Requirement
You’ve specified that:
- The estimated delivery date should appear as a label on category pages when hovering over an icon.
- On individual product pages, it should display directly below the product name.
- For international customers (T+20 days) and local Indian customers (T+6 days), the dates should update automatically each day.
Magento Solution Approach
To implement this feature, we’ll use a combination of core Magento functionality and custom code snippets. Here’s an outline of the steps involved:
Step 1: Create a Custom Helper Function for Delivery Estimates
First, let’s create a helper function to calculate the estimated delivery date based on the location.
In your app/code/local/YourCompanyName/DeliveryEstimate/etc/config.xml file, add the following code:
<config>
<modules>
<DeliveryEstimate>
<version>1.0</version>
</DeliveryEstimate>
</modules>
<helpers>
<deliveryestimate>
<class>YourCompanyName_DeliveryEstimate_Helper_Data</class>
</deliveryestimate>
</helpers>
</config>
Then, in your app/code/local/YourCompanyName/DeliveryEstimate/Helper/Data.php file, add the following PHP code:
<?php
class YourCompanyName_DeliveryEstimate_Helper_Data extends Mage_Core_Helper_Abstract
{
public function getEstimatedDeliveryDate($country)
{
$estimatedDays = ($country == 'IN') ? 6 : 20;
return date('d F, Y', strtotime("+$estimatedDays days"));
}
}
This helper function getEstimatedDeliveryDate calculates the estimated delivery date based on the provided country code. It returns a formatted date string (e.g., “21st September,2024”) for either Indian or international customers.
Step 2: Add Estimated Delivery Date to Product Pages
To display the estimate delivery date on individual product pages, you’ll need to modify the core template files.
In your app/design/frontend/default/yourtheme/template/catalog/product/view.phtml file:
Find the line where the product name is displayed and add the following code right below it:
<h3 class="product-name">
<span class="label"><?php echo $this->__('Estimated Delivery:') ?></span>
<?php echo Mage::helper('deliveryestimate')->getEstimatedDeliveryDate(Mage::helper('core)->getCountryId()); ?>
</h3>
This will display the estimated delivery date just below the product name on each individual product page.
Step 3: Add Estimated Delivery Date to Category Pages
To show the estimated delivery date as a label when hovering over an icon in the category grid, you’ll need to modify your theme’s product listing template files (usually located under app/design/frontend/default/yourtheme/template/catalog/product/list.phtml).
Add the following code inside the loop that displays each product:
<div class="delivery-date">
<span class="icon-aeroplane"></span>
<?php echo Mage::helper('deliveryestimate')->getEstimatedDeliveryDate(Mage::helper('core')->getCountryId()); ?>
</div>
Step 4: Add CSS for Styling
Finally, add some basic styling to make the delivery date label visible and attractive. You can do this in your theme’s CSS file (usually located under skin/frontend/default/yourtheme/css/styles.css):
.delivery-date {
font-size: 12px;
color: #666;
}
Conclusion
By implementing these steps, you should now have the estimated delivery date functionality working on both your product grid and individual product pages in Magento.
The custom helper function calculates the estimate based on location, and the modified template files display this information. The dates will automatically update each day without requiring any manual selection by customers.
Remember to replace “YourCompanyName” with your actual company name throughout the code examples provided.
If you found this solution helpful or have any further questions, feel free to reach out! We’re here to help you optimize your Magento store’s user experience. For more tips and tricks on Magento development, check out our blog at Laravel Company.
Happy coding!