[英]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.