0

I want to add bundle product to add to cart from external php file and it is successfully adding but it is taking long time approx 30sec.

<?php 

include 'app/Mage.php';
Mage::app('default'); 
umask(0);

$size = 2;

$productId = 123; // bundle product

$product = Mage::getModel('catalog/product')
->setStoreId(Mage::app()->getStore()->getId())
->load($productId);

$product->addCustomOption('size',$size);
$session =  Mage::getSingleton("core/session", array("name" => "frontend")); // frontend session

//cart params
$cartParams = array(
            'product' => $productId,
            'related_product' => null,
            'bundle_option' => array(
                '3'=> '176399802',
                '4' => '176420135'
            ),
            'qty' => 1,
        );
try{
    $cart = Mage::getModel('checkout/cart'); // cart object
    $cart->init();
    $cart->addProduct($product, $cartParams);
    $cart->save();
    $session->setCartWasUpdated(true);
    echo Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
}catch(Exception $e){
    echo $e->getMessage(); 
}

and when I perform any action to cart page it is also taking time. Actions like ( load cart page, delete items etc )

Please look into this and help me to sort out this problem.

Any help would be appreciated

Thanks.

0

I have fixed slow add to cart issue for bundle product.

As I have gone through deeply and found that there are lot of bundle selection products( approx 20,000). I have created another bundle product with 10 bundle selection product and it worked fine and took 5 second.

As we know that when we add to cart the product, we call $cart->addProduct($product,$params);

where $product is object of product and $params is an array with respective selections product.

Due to lot of selection product, it is taking time during add to cart.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.