2016-12-27 60 views

回答

0

我認爲一個好的解決方案是將所有沒有任何圖片的簡單產品設置爲缺貨,並將配置system->catalog->inventory->stock options->Display Out of Stock Products設置爲no。

如果您有產品導入邏輯,則可以將該代碼集成到該代碼中。

+0

對不起,重播晚了。我已經從產品列表中刪除了無圖像的項目。現在我需要從可配置中刪除選項。假設一個可配置的有兩個子項目的大小爲S和M. S有圖像,而M沒有。在這種情況下,我只想顯示S.目前,兩者都顯示,當我點擊M時,它顯示無圖像的佔位符。 對不起,您提到的上述解決方案在此不起作用。 –

+0

@JicksonJohnsonKoottala解決方案仍然相關。如果簡單產品缺貨,那麼它將不會顯示在我提到的設置的可配置選項上。 – shemaya

+0

@ shemaya對不起,仍然不是一個好的解決方案。因爲如果我這樣做,我需要提出另一個問題,如何根據圖像狀態來製作缺貨的簡單產品。 ?並且需要在詳細信息頁面上實時完成。我已經自己找到了答案,並在上面發佈。 如果您將產品缺貨,則不會顯示在可配置選項上,這是正確的。但是爲了將它從這個領域隱藏起來而不是一個好的想法。我希望你明白了。 –

0

我得到了解決方案。 我注意到,可配置的產品選項來自位於Mage_Catalog_Block_Product_View_Type_Configurable區塊的功能$this->getJsonConfig();。我所做的是,我在我的模塊中重寫了這個塊,並通過在其中放置下面的代碼來改變函數。

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; 
       } 
      } 
     } 

我只是讓產品foreach循環添加if($product->getImage() && $product->getImage() != 'no_selection'){。這隻會將圖像項目過濾到可配置選項json對象數組。