默认情况下,在视图页面中magento显示关联产品的最低价格。
我需要显示关联产品的最高价格。任何人都知道逻辑驻留在哪里。如何自定义此行为。
更新:
Magento \ ConfigurableProduct \ Pricing \ Price \ ConfigurablePriceResolver
/**
* @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
* @return float
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
{
$price = null;
foreach ($this->configurable->getUsedProducts($product) as $subProduct) {
$productPrice = $this->priceResolver->resolvePrice($subProduct);
$price = $price ? min($price, $productPrice) : $productPrice;
}
if (!$price) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Configurable product "%1" do not have sub-products', $product->getName())
);
}
return (float)$price;
}
我正在尝试覆盖此核心文件,但无法正常工作。
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver" type="Kensium\Catalog\Pricing\Price\ConfigurablePriceResolver" />
<?php
namespace Kensium\Catalog\Pricing\Price;
class ConfigurablePriceResolver extends \Magento\ConfigurableProduct\Pricing\Price\ConfigurablePriceResolver
{
/**
* @param \Magento\Framework\Pricing\SaleableInterface|\Magento\Catalog\Model\Product $product
* @return float
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function resolvePrice(\Magento\Framework\Pricing\SaleableInterface $product)
{
$price = null;
$assPrice=array();
foreach ($this->configurable->getUsedProducts($product) as $subProduct) {
$productPrice = $this->priceResolver->resolvePrice($subProduct);
$assPrice[]=$productPrice;
$price = $price ? min($price, $productPrice) : $productPrice;
}
if (!$price) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Configurable product "%1" do not have sub-products', $product->getName())
);
}
return (float)(max($assPrice));
//return (float)$price;
}
}
您是否要在详细信息页面中显示最高价格?
—
Rakesh Jesadiya
是的,详细信息并列出。当他们在那时照常更改选项时。
—
sivakumar
上市价格没有变化,您是否已检查过,仅显示一个价格
—
Rakesh Jesadiya
没关系。客户应该看到可配置产品的最高价格。
—
sivakumar
这对你有用吗?我在下面给出了您的要求的示例
—
Rakesh Jesadiya