cancel
Showing results for 
Search instead for 
Did you mean: 

Backorder Message - Can it be customized?

Backorder Message - Can it be customized?

backorder message.PNGCan the above message notification of back-order be customized? If so, where?

 

I've seen multiple posts saying

"This backorder message is comes from Item.php file 

file path:-app/code/core/Mage/CatalogInventory/Model/Stock/Item.php" 

but I am unable to locate that file path within our cPanel File manager. 

What could I be missing? Is there a plugin to customize this that would make things simpler? 

Thanks!

Bradie

DEQOnline

5 REPLIES 5

Re: Backorder Message - Can it be customized?

You need to check below location to find your text message,

vendor/magento/module-catalog-inventory/Model/StockStateProvider.php at line no. 197


Translation Message:
vendor/magento/module-catalog-inventory/i18n/en_US.csv

 

You can also override using en_US.csv file in your theme or module level by below line,
At theme level,

app/design/frontend/{Vendor}/{themename}/i18n/en_US.csv file,

"We don't have as many ""%1"" as you requested, but we'll back order the remaining %2.","string to change your message"

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Backorder Message - Can it be customized?

Hello @Rakesh Jesadiya ,

I need to show different message for error and notice, right now same text is displaying for both error and warning, How can we show different message for error and notice message?

Thanks

Re: Backorder Message - Can it be customized?

I used your method and it worked with simple products. But now I'm trying with configurable products and it showing the default Magento message. What code do I need to change for configurable child products? 

Re: Backorder Message - Can it be customized?

Hi Rakesh,

 

This is interesting. I am using Magento 2.4 and your solution doesn't seem to be working there.

For some reason, the Model file you are mentioning is not responsible for the message.

The model that creates this message for me is here:

vendor/magento/module-inventory-sales/Model/IsProductSalableCondition/BackOrderNotifyCustomerCondition.php

 

If I change the text directly in the class I can see it appearing in the mini-cart warning. 

But none of the methods you are suggesting to override it are working for me.

I've created the i18n folder in my theme using en_AU.csv and en_US.csv (my locales are set to en_AU) with no success.

I've also tried to override the Model above by creating an extension under app/code/ but nothing happens (the page simply reloads without adding anything to the cart. No warning message appears).

Here my code for the Model override.

 

registration.php:

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'MyVendor_VariousOverrides',
__DIR__
);

 

etc/di.xml:

<?xml version="1.0"?> 

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> 
<preference for="Magento\InventorySales\Model\IsProductSalableCondition\BackOrderNotifyCustomerCondition" type="MyVendor\VariousOverrides\Model\InventorySales\IsProductSalableCondition\BackOrderNotifyCustomerCondition" /> 
</config>

 

etc/module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="MyVendor_VariousOverrides" setup_version="1.0.0"></module>
</config>

 

Model/InventorySales/IsProductSalableCondition/BackOrderNotifyCustomerCondition.php:

<?php
namespace MyVendor\VariousOverrides\Model\InventorySales\IsProductSalableCondition;


/**
* Get back order notify for customer condition
*
* @inheritdoc
*/
class BackOrderNotifyCustomerCondition extends Magento\InventorySales\Model\IsProductSalableCondition\BackOrderNotifyCustomerCondition
{


/**
* @inheritdoc
*/
public function execute(string $sku, int $stockId, float $requestedQty): ProductSalableResultInterface
{
$stockItemConfiguration = $this->getStockItemConfiguration->execute($sku, $stockId);

if ($stockItemConfiguration->isManageStock()
&& $stockItemConfiguration->getBackorders() === StockItemConfigurationInterface::BACKORDERS_YES_NOTIFY
) {
$stockItemData = $this->getStockItemData->execute($sku, $stockId);
if (null === $stockItemData) {
return $this->productSalableResultFactory->create(['errors' => []]);
}

$salableQty = $this->getProductSalableQty->execute($sku, $stockId);
$backOrderQty = $requestedQty - $salableQty;
$displayQty = $this->getDisplayQty($backOrderQty, $salableQty, $requestedQty);

if ($displayQty > 0) {
$errors = [
$this->productSalabilityErrorFactory->create([
'code' => 'back_order-not-enough',
'message' => __(
'THIS IS MY TEST TEXT TO OVERRIDE',
$displayQty * 1
)])
];
return $this->productSalableResultFactory->create(['errors' => $errors]);
}
}

return $this->productSalableResultFactory->create(['errors' => []]);
}

}

 

Anything I am doing wrong here?

 

Thanks for your help 

Re: Backorder Message - Can it be customized?

Thanks, It' working.