This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace Esun\ProductInquiry\Plugin\ConfigurableProduct\Helper;
use Magento\Catalog\Model\Product;
use Magento\ConfigurableProduct\Helper\Data;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\App\RequestInterface;
/**
* Keeps configurable variation data available for product inquiries.
*/
class DataPlugin
{
private const PRODUCT_VIEW_ACTION = 'catalog_product_view';
/**
* @param RequestInterface $request
*/
public function __construct(
private readonly RequestInterface $request
) {
}
/**
* Include enabled out-of-stock variations in the PDP configuration only.
*
* Magento normally removes these options when the global "Display Out of
* Stock Products" setting is disabled. Inquiry selection needs the complete
* variation matrix without changing that setting for category/search pages.
*
* @param Data $subject
* @param array $result
* @param Product $currentProduct
* @param array $allowedProducts
* @return array
*/
public function afterGetOptions(
Data $subject,
array $result,
Product $currentProduct,
array $allowedProducts
): array {
if ($this->request->getFullActionName() !== self::PRODUCT_VIEW_ACTION
|| $currentProduct->getTypeId() !== Configurable::TYPE_CODE
) {
return $result;
}
$options = [
'index' => [],
'salable' => [],
'canDisplayShowOutOfStockStatus' => true,
];
$allowAttributes = $subject->getAllowAttributes($currentProduct);
foreach ($allowAttributes as $attribute) {
$attributeId = (int)$attribute->getProductAttribute()->getId();
$options['salable'][$attributeId] = [];
}
foreach ($allowedProducts as $product) {
$productId = (int)$product->getId();
foreach ($allowAttributes as $attribute) {
$productAttribute = $attribute->getProductAttribute();
$attributeId = (int)$productAttribute->getId();
$attributeValue = $product->getData($productAttribute->getAttributeCode());
$options[$attributeId][$attributeValue][] = $productId;
$options['index'][$productId][$attributeId] = $attributeValue;
if ($product->isSalable()) {
$options['salable'][$attributeId][$attributeValue][] = $productId;
}
}
}
return $options;
}
}