My issue is that I can’t get my different frontends to show different “Display out of Stock Products” options.
Does anyone have any tips on which stock Magento module I need to look into to build a plugin or extension off of?
I have a Magento 2.4.6 site setup like this:
- Customer Group defines store view
- Shared inventory added to both websites through backend
- Website View 1 (default) – Logged in and not logged in customers
Should show only in stock items in frontend store view. - Website View 2 – Logged in customers that have been changed to customer group 2
Should show in stock and out of stock items in the frontend store view
Frontend view is defined by customer group
This is working correctly using this extension:
https://stackoverflow.com/questions/60206046/change-store-view-automatically-for-different-customer-groups-in-magento-2
I’ve changed the Scope of the “Display out of Stock Products” from global to website based scopes using this extension:
https://community.magento.com/t5/Magento-2-x-Programming/Change-scope-of-Display-Out-of-Stock-Products-from-global-to/td-p/452846
I am able to apply the “Display out of Stock Products” dropdown selector to either website view in the backend but “Website View 2” is still dependent on the selection of the default “Website View 1” and doesn’t change.
My question as stated above:
Does anyone have any tips on which stock Magento module I need to look into to build a plugin or extension off of?
I had thought maybe the Magento / CatalogInventory / Helper / Stock.php function below might be right since it’s doesn’t specify the $store or $website scope after the ScopeInterface::SCOPE_STORE
public function addIsInStockFilterToCollection($collection)
{
$stockFlag = 'has_stock_status_filter';
if (!$collection->hasFlag($stockFlag)) {
$isShowOutOfStock = $this->scopeConfig->getValue(
MagentoCatalogInventoryModelConfiguration::XML_PATH_SHOW_OUT_OF_STOCK,
MagentoStoreModelScopeInterface::SCOPE_STORE
);
$resource = $this->getStockStatusResource();
$resource->addStockDataToCollection(
$collection,
!$isShowOutOfStock
);
$collection->setFlag($stockFlag, true);
}
}
or the Magento / CatalogInventory / Model /Configuration.php but this file does list the $store ScopeInterface::SCOPE_STORE, $store
:
/**
* Display out of stock products option
*
* @param null|string|bool|int|MagentoStoreModelStore $store
* @return bool
*/
public function isShowOutOfStock($store = null)
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_SHOW_OUT_OF_STOCK,
ScopeInterface::SCOPE_STORE,
$store
);
}
Any pointers, tips or corrections are much appreciated! Thanks!