2016-12-15 13 views
0

設定可能なすべての製品のサイズをlist.phtmlグリッド内で取得しようとしています。Magento - 設定可能な製品を入手可能なサイズ

以下のコードでは、すべてのサイズを正常に取得できますが、使用できないサイズも表示されます。

<?php if($_product->isSaleable()): ?> 
    <div class="taglie"> 
    <?php $cProduct = Mage::getModel('catalog/product')->load($_product->getId()); 
    //check if product is a configurable type or not 
    if ($cProduct->getData('type_id') == "configurable") { 
     //get the configurable data from the product 
     $config = $cProduct->getTypeInstance(true); 
     //loop through the attributes 
     foreach($config->getConfigurableAttributesAsArray($cProduct) as $attributes) { ?> 
      <?php foreach($attributes["values"] as $values) { 
       echo "<span>".$values["label"]."</span>"; 
      } ?> 
     <?php 
     } 
    } ?> 
</div> 
<?php else: ?> 
    <?php echo $this->__('Out of Stock') ?> 
<?php endif; ?> 

私がしようとしているのは、利用できないサイズのオプションを非表示にすることです。

答えて

0
<p style="margin-top: 8px;">  
    <?php 
     $sizes = array(); 
     if($_product->isConfigurable()){ 
      $allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product); 
      foreach ($allProducts as $subproduct) { 
       if ($subproduct->isSaleable()) { 
        $sizes[] = $subproduct->getAttributeText('size'); 
       } 
      } 
      if(count($sizes)>0) { 
      echo implode(", ", $sizes); 
      } 
     } 
    ?> 
</p> 
関連する問題