简体   繁体   English

Magento将可配置产品从订单项添加到购物车

[英]Magento add configurable product to cart from order items

I want to add a product to cart with selected option of a ordered product. 我想使用订购产品的选定选项将产品添加到购物车。 As Example I have ordered a configurable product where available options are S,M,L . 作为示例,我订购了一个可配置产品,其中可用选项为S,M,L I select M and order it. 我选择M并订购。 Now I want to pull this order and programmatically move to cart again. 现在,我要下订单并以编程方式再次移动到购物车。 I try this in many different process but not success by me yet. 我尝试了许多不同的方法,但还没有成功。 Please anyone suggest to me how to do this? 请有人向我建议如何做?

Supravat, Please try to get option id of size of size using eav attibute the programically create an cart url 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM