0
A
回答
0
最後我發現它,也許它會幫助別人的未來:
$productAttributeOptions = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
//in this case the attribute color that I needed is in [0] position
$available_colors = sizeof($productAttributeOptions[0]["values"]);
if ($available_colors >1):
//custom code
endif;
編輯:該解決方案適用於一個產品,或者至少幾個產品,但如果你需要它在每個產品中運行該代碼真的很慢的產品列表。有時它驅動到超時並關閉數據庫連接,所以Web崩潰時出現錯誤。
最後,我得到了一個解決方案,也許它不是最好的,但它是相當快比我之前使用的一個:
$_idsForTheQuery = $_productCollection->getAllIds();
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql_query = "SELECT parent_id, COUNT(parent_id) AS colors FROM
(SELECT cpr.parent_id FROM `eav_attribute` a
LEFT JOIN `catalog_product_entity_int` cpei ON cpei.attribute_id=a.attribute_id
LEFT JOIN `catalog_product_relation` cpr ON cpr.child_id=cpei.entity_id
WHERE attribute_code = 'color' AND cpr.parent_id IN (".implode (", ", $_idsForTheQuery).")
GROUP BY cpr.parent_id, cpei.value) colors
GROUP BY parent_id";
$results = $read->query($sql_query);
$number_of_colors_by_id_array = array();
foreach($results as $r)
{
$number_of_colors_by_id_array[$r["parent_id"]] = $r["colors"];
}
,然後在產品的foreach循環
<?php if ($number_of_colors_by_id_array[$_product->getId()]>1): ?>
<div class="aditional-colors-message">
<?php echo __('more colors available'); ?>
</div>
<?php endif; ?>
相關問題
- 1. Woocommerce - 獲取具有特定屬性的產品類別
- 2. Magento - 按屬性獲取產品數量
- 3. Magento:從沒有產品的屬性集中獲取屬性
- 4. SQL獲得具有更多的共同屬性的產品與其他產品
- 5. 獲得一個組裝的產品屬性只具有的AssemblyName
- 6. Prestashop - 當產品具有屬性時無法添加產品(parsererror)
- 7. Woocommerce REST API按屬性獲取產品
- 8. 從所有類別的magento中獲取屬性的產品
- 9. Magento可配置色板顯示「是」和「否」的產品屬性
- 10. Magento - 具有值數組的單個定製產品屬性
- 11. 數據庫設計 - 具有屬性的多類產品
- 12. 獲取數組中物品的屬性
- 13. 產品數據庫屬性
- 14. 在WooCommerce訂單中獲取物品/產品屬性
- 15. 導出產品的所有屬性
- 16. 具有多個屬性的產品庫存
- 17. 使用XML僅顯示具有特定屬性的產品
- 18. magento:加入具有屬性值的產品
- 19. Magento - 檢索具有特定屬性值的產品
- 20. 存儲具有不同屬性的類似產品
- 21. 查找具有屬性列表的產品
- 22. Magento 1.7:導入具有多選屬性的產品
- 23. 獲取具有min屬性的元素
- 24. 產品屬性的數據庫模式
- 25. 如何使用Magento中的超級屬性獲取產品ID?
- 26. 無法根據Woocommerce中的屬性獲取產品
- 27. 獲取WooCommerce變量產品屬性選定的值
- 28. Magento - 從當前查看的產品獲取集合屬性
- 29. 具有固定的最大產品數量的清單產品
- 30. 獲取具有另一個屬性的類的屬性