简体   繁体   中英

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 . I select M and order it. 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

 <?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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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