首页 > 解决方案 > 如何以编程方式从 phtml 中的可配置产品中获取选项 ID 和值?

问题描述

如果我可以访问,我正在修改 phtml 代码

$this 恰好是 Mage_Checkout_Block_Cart_Item_Renderer_Configurable 类

$_item = $this->getItem();
$_product = $_item->getProduct(); 

其中产品是购物车中的可配置产品。

基于此,我需要获取选项 ID(样本)及其值的列表。

标签: magentomagento-1.9

解决方案


例如,要获取特定尺寸选项 id :

$product = $_item->getProduct();
$idStore = $_item->getOrder()->getStoreId();
$sizeSpecificAttributeCode = 'specific_size';
$sizeAttributeOptionId = $product->getResource()
->getAttributeRawValue($product->getId(), $sizeSpecificAttributeCode,$idStore);

从相同的逻辑你可以得到样本或其他选项


推荐阅读