X hide

Magento 2 Estimated Delivery Date v2.x Developers Guide and API Reference

From Plumrocket Documentation

You are viewing:  Magento-estimated-delivery-date-wiki-32.png  Estimated Delivery Date

Magento 2 Estimated Delivery Date Manual Configuration

Estimated Delivery Date module will automatically add "Delivery Dates" on Product Page if enabled in back-end. However, you can change standard "Delivery Date" display or position in the front-end. To do this follow the instructions below.

Product Page

In order to have the Delivery Date displayed on the product page - please make the following steps on your server :
1. Create file:

app/design/frontend/<Vendor>/<theme>/Plumrocket_Estimateddelivery/layout/catalog_product_view.xml

2. Paste the code below into the created file:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="estimateddelivery_product" destination="CONTAINER_OR_BLOCK_NAME" after="-"/>
</body>
</page>

CONTAINER_OR_BLOCK_NAME - name of one of the containers or blocks on the product page. You can check them in the theme layout.

Go to:

app/design/frontend/<Vendor>/<theme>/Magento_Catalog/layout/catalog_product_view.xml 

or:

vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml

after="-" means that block with estimated delivery dates has been placed into container.
CONTAINER_OR_BLOCK_NAME after all the blocks.
before=”-” can be used, if you need to place it before other blocks. Instead of “-” you can use name of specific block, if you need to place estimated delivery dates before or after it.

Example :
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
 <move element="estimateddelivery_product" destination="product.info.extrahint" after="-"/>
</body>
</page>


Category Page

In order to add the Estimated Delivery dates to the products on the category page, make the following steps on your server:

1. Create file:

app/design/frontend/<Vendor>/<theme>/Plumrocket_Estimateddelivery/layout/catalog_category_view.xml

2. Paste the code below into the created file:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="estimateddelivery_category" destination="CONTAINER_OR_BLOCK_NAME" after="-"/>
</body>
</page>

CONTAINER_OR_BLOCK_NAME - name of one of the containers or blocks on the product page. You can check them in the theme layout.

Go to

app/design/frontend/<Vendor>/<theme>/Magento_Catalog/layout/catalog_product_view.xml 

or here:

vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml


Display Estimated Delivery Dates and Shipping Dates in Magento for Specific Categories & Products

The following methods in "Plumrocket_Estimateddelivery_Block_Product" block allow to show shipping and delivery dates for specific products:

setProduct($product)

Allows to set the product the dates will be shown for.

Example :

Let's show the date for "related" products on Product Page:

  1. $relatedProducts = get_related_products(); // where get_related_products() is some custom method to retrieve related products
  2. $estimatedBlock = $this->getLayout()->createBlock("Plumrocket\Estimateddelivery\Block\Product")->setTemplate("Plumrocket_Estimateddelivery::product.phtml");
  3. foreach ($relatedProducts as $_product) {
  4. echo $estimatedBlock->setProduct($_product)->toHtml();
  5. }
Example:

On Product Page with custom design we can display dates for "related" products and immediately after that display dates for the current product:

  1. <div class="related_dates">
  2. <?php
  3. $relatedProducts = get_related_products(); // where get_related_products() is some custom method to retrieve related products
  4. foreach ($relatedProducts as $_product) {
  5. echo $this->getChild('estimateddelivery')->setProduct($_product)->toHtml();
  6. }
  7. ?>
  8. </div>
  9. <div class="main_date">
  10. <?php $this->getChild('estimateddelivery')->reset()->toHtml(); ?>
  11. </div>
setCategory($category)

Allows to set the category for which the dates will be shown.

Example :

Let's display html block that contains delivery date for the set category:

  1. $customCategory = \Magento\Framework\App\ObjectManager::getInstance()->create('Magento\Catalog\Model\Category')->load(<any id>);
  2. echo $this->getLayout()
  3. ->createBlock('Plumrocket\Estimateddelivery\Block\Product')
  4. ->setTemplate('Plumrocket_Estimateddelivery::product.phtml')
  5. ->setCategory($customCategory)
  6. ->toHtml();
getProduct()

Allows to get the product for which the dates will be shown. Note: If no product was indicated manually - current product will be returned on Product Page.

getCategory()

Allows to get the category the dates will be shown for. Note: If no category was indicated manually - current category will be returned on Product Page or Category Page.

reset()

Allows to clear all current settings. After calling this method, the other methods (getProduct and getCategory) will return current product (on Product Page) and current category (on Product Page or Category Page) accordingly. This method comes handy for displaying dates of custom products (categories) on the product (category) page, and for returning to default settings.

Example code of layout.xml file:

Let's display block with date for the product by inserting it into the layout:

  1. <catalog_product_default>
  2. <body>
  3. <referenceContainer name="category.view.container">
  4.  <block class="Plumrocket\Estimateddelivery\Block\Product" name="estimateddelivery_product" as="estimateddelivery" template="Plumrocket_Estimateddelivery::product.phtml" cacheable="false" />
  5. </referenceContainer>
  6. </body>

Estimated Delivery Date Extension for Magento 2 Estimated Delivery Date Extension for Magento 2

Buy Magento 2 Estimated Delivery Date Extension on Plumrocket Store
Click below to check key features of this extension, view live demo and screenshots:
Navigation