如何从Magento可配置选项中隐藏无图像项?
我想隐藏没有任何图像关联的可配置选项。我试图重写可配置的产品块,但不起作用。有人知道吗?我认为一个好的解决方案是将所有没有图片的简单产品设置为缺货,并将配置如何从Magento可配置选项中隐藏无图像项?,magento,magento-1.9,Magento,Magento 1.9,我想隐藏没有任何图像关联的可配置选项。我试图重写可配置的产品块,但不起作用。有人知道吗?我认为一个好的解决方案是将所有没有图片的简单产品设置为缺货,并将配置系统->目录->库存->股票期权->显示缺货产品设置为否 如果您有产品导入逻辑,您可以将该代码集成到该逻辑中。我找到了解决方案。 我注意到,可配置的产品选项来自函数$this->getJsonConfig()位于Mage\u Catalog\u Block\u Product\u View\u Type\u ConfigurableBlock
系统->目录->库存->股票期权->显示缺货产品设置为否
如果您有产品导入逻辑,您可以将该代码集成到该逻辑中。我找到了解决方案。
我注意到,可配置的产品选项来自函数$this->getJsonConfig()代码>位于Mage\u Catalog\u Block\u Product\u View\u Type\u Configurable
Block。我所做的是,在我的模块中重写这个块,并通过将下面的代码放入其中来修改函数
public function getJsonConfig()
{
$attributes = array();
$options = array();
$store = $this->getCurrentStore();
$taxHelper = Mage::helper('tax');
$currentProduct = $this->getProduct();
$preconfiguredFlag = $currentProduct->hasPreconfiguredValues();
if ($preconfiguredFlag) {
$preconfiguredValues = $currentProduct->getPreconfiguredValues();
$defaultValues = array();
}
foreach ($this->getAllowProducts() as $product) {
if($product->getImage() && $product->getImage() != 'no_selection'){
$productId = $product->getId();
foreach ($this->getAllowAttributes() as $attribute) {
$productAttribute = $attribute->getProductAttribute();
$productAttributeId = $productAttribute->getId();
$attributeValue = $product->getData($productAttribute->getAttributeCode());
if (!isset($options[$productAttributeId])) {
$options[$productAttributeId] = array();
}
if (!isset($options[$productAttributeId][$attributeValue])) {
$options[$productAttributeId][$attributeValue] = array();
}
$options[$productAttributeId][$attributeValue][] = $productId;
}
}
}
我刚刚添加了if($product->getImage()&&&$product->getImage()!='no_selection'){
在允许的products foreach循环中。这将仅将图像项筛选到可配置选项json对象数组。很抱歉延迟重播。我已经从产品列表中删除了无图像项。现在我需要从可配置中删除选项。假设一个可配置项有两个子项,大小分别为S和M。S有图像和M不显示。在本例中,我只想显示S。目前,两者都显示,当我单击M时,它不显示图像占位符。抱歉,您提到的上述解决方案在这里不起作用。@JicksonJohnson Koottala解决方案仍然是相关的。如果简单产品缺货,则它不会显示在带有sett的可配置选项上我提到过的问题。@shemaya抱歉,这仍然不是一个好的解决方案。因为如果我这样做,我需要提出另一个问题,比如,如何根据图像状态使简单的产品脱销。?这需要在详细信息页面上实时完成。我已经找到了答案并发布在上面。如果您将产品作为脱销产品-股票,这不会显示在可配置的期权上,这是正确的。但这不是一个好主意,使股票,只是为了隐藏它从这个领域。我希望你的想法。