# Magento 2 Product Shelf Life

### <span style="color: #3b82f6;">Installation and User Guide for Magento 2 Product Shelf life Extension</span>

**Table of Contents**

1. [*Installation* ](#bkmrk-installation)
    - *Installation via app/code*
    - *Installation via Composer*
2. [*Configuration Settings for Product Shelf Life Expiration* ](#bkmrk-configuration-settin)
    - *General Settings*
    - *Batch Settings*
    - *Product Batches Grid*
    - *Add Sources at Product Level*
    - *Add New Product Batch*
    - *Un-Associate / Delete Product Batch*
    - *Product Batches at Product Level*
    - *Add Specific Batch to Product*
    - *Select Batches During Shipment*
    - *Batch Details on the Order View Page*
    - *Deleting or Un- Associating a Product Batch*
    - *Deleting*
    - *Un-Associating*
    - *Batch Report*
    - *Import / Export Product Batches*
    - *Batch Expiration Email Notification*
3. [*API - Application Programming Interface* ](#bkmrk-api---application-pr)
    - *Authentication Token*
    - *Creating a Batch using API*
    - *Retrieve all Batches using API*
    - *Retrieve Date of Batch using ID 1 Using API*
    - *Delete Batch with ID 1 Using API*

### <span style="color: #3b82f6;">Installation</span> [](#bkmrk-)

- <span style="color: #f97316;">**Installation via app/code:**</span> Upload the content of the module to your root folder. This will not overwrite the existing Magento folder or files, only the new contents will be added. After the successful upload of the package, run below commands on Magento 2 root directory.
    
    ```php
    php bin/magento setup:upgrade
    php bin/magento setup:di:compile
    php bin/magento setup:static-content:deploy
    ```
- <span style="color: #f97316;">**Installation via Composer:**</span> Please follow the guide provided in the below link to complete the installation via composer.

<p class="callout success">[https://docs.scommerce-mage.com/magento-2-extensions/installation-via-composer/installation-via-composer](https://docs.scommerce-mage.com/magento-2-extensions/installation-via-composer/installation-via-composer)</p>

### <span style="color: #3b82f6;">Configuration Settings for Product Shelf Life Expiration</span> [](#bkmrk--1)

Go to **Admin &gt; Stores &gt; Configuration &gt; Scommerce Configuration &gt; Product Shelf Life Expiration**

#### <span style="color: #f97316;">General Settings</span> [](#bkmrk--2)

- **Enabled -** Select "Yes" or "No" to enable or disable the module.
- **License Key –**Please add the license for the extension which is provided in the order confirmation email. Please note license keys are site URL specific. If you require license keys for dev/staging sites then please email us at <support@scommerce-mage.com>.

[![image (51).jpg](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-51.jpg)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-51.jpg)

### Batch Settings [](#bkmrk--4)

- **Batch expiry email notification period (number of days) -** Please define batch expiry email notification period. This setting will check the batch expiry date and will send an email notification to the admin for the same.
- **Batch expiry email notification (Yes/No) -** Please select "Yes" or "No" to "Enable" or "Disable" the email notification regarding batch expiration.
- **Disable batch once expired -** Please select "Yes" or "No" to disable the batch. It disables the batch automatically once their expiry date is passed and runs as part of cron job at midnight.
- **Email Addresses -** Please provide email addresses (comma separated) to send the batch expiration email notification.
- **Email Sender –** Please select sender/ from email addresses for Batch expiry updated.
- **Select Email Template -**Please select the email template for batch expiry email notification.
- **Cron Scheduler for expiry batch notification -** This setting will be used to send the email through the cron.
- **Batch Selection Attribute –** This setting will determine how batches are selected automatically.
- **Batch Selection Attribute Direction –** As per the batch selection attribute you can choose the direction for example Ascending(ASC) or Descending(DSC).
- **Batch Selection –** You can choose to select batches automatically based on batch selection attribute or you can set it to Manual. When Manual you will be able to select batches during shipment.

[![image (52).jpg](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-52.jpg)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-52.jpg)

[![image (53).jpg](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-53.jpg)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-53.jpg)

#### <span style="color: #f97316;">Product Batches Grid</span> [](#bkmrk--7)

You can create and manage product batches from, **Admin&gt; Product Batches**. This grid will have all the details about batches like ID, Batch Code, Product SKU, Batch Status, Batch Qty, Batch Expiry, Action/Edit and Source Inventory.

[![image (69).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-69.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-69.png)

- <span style="color: #f97316;">**Add Sources at Product Level -**</span>You can add product source from **Admin &gt; Catalog &gt; Select Products &gt;** Click **"Assign Sources"&gt;** Select **"Source"&gt;** Click **"Done"** .

[![image (70).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-70.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-70.png)

- <span style="color: #f97316;">**Add New Product Batch -**</span>To create new product batch, go to **Admin &gt; Product Batches&gt;**click **'Add New Batch'.** It will take you to the new product batch page and by providing all the required details; you can create the new batch.

[![image (54).jpg](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-54.jpg)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-54.jpg)

- <span style="color: #f97316;">**Un-Associate / Delete Product Batch -**</span>Toun-associate and delete product batch, go to**Admin &gt; Product Batches&gt; Select Batch &gt; Edit &gt;**Click **"Un-Associate with Product''** and for **Delete** click on **"Delete"** button**.**

**[![image (55).jpg](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-55.jpg)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-55.jpg)**

#### <span style="color: #f97316;">Product Batches at Product Level</span> [](#bkmrk--12)

When user enables the module then Product Batches section appears at, **Admin&gt;Catalog&gt;Product&gt;Select Product&gt;Edit&gt;Product Batches.** From this section, users can add new batch or can associate specific existing batch to a product.

[![image (71).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-71.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-71.png)

#### <span style="color: #f97316;">Add Specific Batch to Product</span> [](#bkmrk--14)

You can also add specific batches to a product from, **Admin &gt; Catalog &gt; Product &gt; Select Product &gt;Edit &gt;Product Batches &gt;**Click**"Add Specific Batch"**. It redirects to **Batch Grid** and by selecting batch **ID** you can associate active batches to a product.

[![image (72).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-72.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-72.png)

- <span style="color: #f97316;">**Select Batches During Shipment -**</span>To select the batch during shipment make sure **Batch Selection** is set to **manual** in the configuration then navigate to **Admin&gt; Sales &gt; Order &gt; Select Order &gt; View&gt;Generate Invoice&gt;Click on Ship.** When you scroll down on the page you will see the option to select the batches manually. The product quantity will be deducted from the selected batch. Please refer to the image below:-

[![image (31) (1).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/f36image-31-1.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/f36image-31-1.png)

- <span style="color: #f97316;">**Batch Details on the Order View Page -**</span>To view theproduct batch related details, go to **Admin &gt; Sales &gt; Order &gt; Select Order &gt; View**.

[![image (73).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-73.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-73.png)

#### <span style="color: #f97316;">Deleting or Un- Associating a Product Batch</span> [](#bkmrk--18)

- **Deleting: -**To delete a product batch, go to Catalog&gt;Product Batches then select the product batch that you want to delete. From Action coloumn click Edit. Here you will see the option to delete the Product batch.

#### <span style="color: red;">Note:- If an order has been shipped then you won't be able to delete that product batch. You will see an error.</span>

<span style="color: red;">[![image (32) (1).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/XhSimage-32-1.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/XhSimage-32-1.png)</span>

- **Un-Associating:-** To Un-Associate a product batch, go to Catalog&gt;Product Batches then select the product batch that you want to delete. From Action column click Edit. Here you will see the option to Un-Associate the Product batch.

[![image (33) (1).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-33-1.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-33-1.png)

#### <span style="color: red;">Note:- If an order has been shipped then you won't be able to delete that product batch. You will see an error.</span>

- <span style="color: #f97316;">**Batch Report**</span><span style="color: #f97316;">:-</span> To view the detailed batch report go to your admin panel then **Reports&gt;Sales&gt;Batches**. Here you can see all the orders associated with a product batch with the following information:-
- Order Number
- Purchase Date
- Customer
- Customer Group
- Product Name
- Batch code
- Batch Quantity
- Expiry Date

[![image (35) (1).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/H8Vimage-35-1.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/H8Vimage-35-1.png)

#### <span style="color: #f97316;">Import / Export Product Batches</span> [](#bkmrk--22)

To import and export product batches, go to **Admin &gt; System &gt;Import / Export**.

- **Import -** It updates the stock quantity and disables the batches if they are expired.
- **Export-**It exports the batches in the selected file format, e.g. CSV**.**

#### <span style="color: #3b82f6;">Import Settings</span>

<span style="color: #3b82f6;">[![image (56).jpg](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-56.jpg)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-56.jpg)</span>

<span style="color: #3b82f6;">**CSV File Format for Import -**</span> CSV file will have batch\_code, batch\_qty, batch\_status, batch\_expiry, product\_sku and source\_inventory.

[![image (74).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-74.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-74.png)

#### Export Settings

[![image (36) (1).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/VqUimage-36-1.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/VqUimage-36-1.png)

- <span style="color: #f97316;">**Batch Expiration Email Notification -**</span> When you select "Yes" for **"**Batch expiry email notification"from **Admin &gt; Stores &gt; Configuration &gt; Scommerce Configuration &gt; Product Shelf Life Expiration &gt; Batch Settings**, then it sends an email notification for batch expiration.

[![image (75).png](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/scaled-1680-/image-75.png)](https://docs.scommerce-mage.com/uploads/images/gallery/2025-05/image-75.png)

### <span style="color: #3b82f6;">API - Application Programming Interface</span> [](#bkmrk--27)

#### <span style="color: #f97316;">Authentication Token</span> [](#bkmrk--28)

#### auth\_token can be received using the following: -

**You would need credentials to your store with admin rights Parameters:-**.Admin credentials

- Username
- Password

**POST URL:-** [http://baseurl/index.php/rest/V1/integration/admin/token](http://baseurl/index.php/rest/V1/integration/admin/token) Content-Type: application/json

{

"username": "admin", "password": "admin"

}

#### <span style="color: #f97316;">Creating a Batch using API</span> [](#bkmrk--29)

#### Parameters:-

- Authorization token received from the above step
- Batch code
- Batch quantity
- Batch status
- Batch expiry
- Product SKU

**POSTURL:-**[http://baseurl/index.php/rest/V1/productbatches/createbatch](http://baseurl/index.php/rest/V1/productbatches/createbatch) Content-Type: application/json

Authorization: Bearer {{auth\_token}}

{

"batch\_code": "batchcode\_001", "batch\_qty": "10",

"batch\_status": "1",

"batch\_expiry": "2020-12-06", "product\_sku": "MH0001"

}

#### <span style="color: #f97316;">Retrieve all Batches using API</span> [](#bkmrk--30)

#### Parameters:-

Authorization token

**GET URL:-**[http://baseurl/index.php/rest/V1/productbatches/getcollection](http://baseurl/index.php/rest/V1/productbatches/getcollection) Content-Type: application/json

Authorization: Bearer {{auth\_token}}

#### <span style="color: #f97316;">Retrieve Date of Batch using ID 1 Using API: -</span> [](#bkmrk--31)

#### Parameters: -

- Authorization token
- Batch ID in URL

**GET URL:-**[http://baseurl/index.php/rest/V1/productbatches/getbatch?batchId=1](http://baseurl/index.php/rest/V1/productbatches/getbatch?batchId=1) Content-Type: application/json

Authorization: Bearer {{auth\_token}}

#### <span style="color: #f97316;">Delete Batch with ID 1 Using API: -</span> [](#bkmrk--32)

#### Parameters: -

- Authorization token
- Batch ID

**PUT URL: -** [http://baseurl/index.php/rest/V1/productbatches/deletebatch](http://baseurl/index.php/rest/V1/productbatches/deletebatch) Content-Type: application/json

Authorization: Bearer {{auth\_token}}

{

"batchId": 1

}

If you have a question related to this extension please check out our[ **FAQ Section**](https://www.scommerce-mage.com/magento-2-product-shelf-life.html#customfaq) first. If you can't find the answer you are looking for then please contact [**support@scommerce-mage.com**](mailto:core@scommerce-mage.com)**.**