[英]Magento add configurable product to cart from order items
我想使用訂購產品的選定選項將產品添加到購物車。 作為示例,我訂購了一個可配置產品,其中可用選項為S,M,L 。 我選擇M並訂購。 現在,我要下訂單並以編程方式再次移動到購物車。 我嘗試了許多不同的方法,但還沒有成功。 請有人向我建議如何做?
Supravat,請嘗試使用eav attibute以編程方式創建購物車網址的方式獲取大小尺寸的選項ID
<?php
$ConfigProduct=Mage::getModel('catalog/product')->load($cpid);
$GetAllowAttributes=$ConfigProduct->getTypeInstance(true)
->getConfigurableAttributes($ConfigProduct);
foreach ($GetAllowAttributes() as $attribute) {
$productAttribute = $attribute->getProductAttribute();
$attribute_code= $productAttribute->getAttributeCode();
$attributeid=$productAttribute->getId();
break;
}
$attribute_details = Mage::getSingleton("eav/config")->getAttribute("catalog_product", $attribute_code);
$options = $attribute_details->getSource()->getAllOptions(false);
foreach($options as $option){
// print_r($option) and find all the elements
//echo $option["value"];
//echo $option["label"];
if($option["label"]==$youlabel){
$opid=$option["value"];
$cartUrl=Mage::helper('checkout/cart')->getAddUrl($ConfigProduct).'?super_attribute['.$attributeid.']='.$option["value"].'&qty=1';
break;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.