1

I want to separate (or we can say Marge) cart product on the basis on dynamic option. For this i am using following approach -

$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');

$productID = $_POST['productId']; //-- Clicked Product Id
$storeID = $_POST['productStoreId']; //-- Current Selected VendorStore Id
$selectedQty = $_POST['selectedQty']; //-- Quentity selected for add to card

//-- Get Special Price according selected vendor store
$sql = "SELECT special_price FROM cr_stores_product WHERE AND cr_store_id = " . $storeID . " AND product_id = " . $productID;
$result = $readConnection->fetchRow($sql);
$price = $result["special_price"];

//-- Create parameter for add to cart
$params = array('qty' => $selectedQty, 'price' => $price);
Mage::getSingleton('core/session', array('name' => 'frontend'));

//-- Add to cart functionality
$product = Mage::getModel('catalog/product')->load($productID);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$cart->addProduct($product, $params);
$cart->save();
foreach ($cart->getQuote()->getAllItems() as $item) {
    if ($item->getProduct() == $product) {
        $item->setData('cr_store_id', $storeID);
        $item->setCustomPrice($price);
        $item->setOriginalCustomPrice($price);

        //-- Add 'cr_store_id' as custom option for managing/diffrentiate cart product accodting vendor_store
        $item->addOption(array(
            "code" => "cr_store_id",
            "value" => serialize(array($storeID))
        ));
    }
    $item->save();
}

Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
Mage::getSingleton('core/session')->addSuccess('Product added successfully');

But it's create different-different row for every cart product. But i want a bit differ. I want to create one row for each product from a store. If user add more qty for product with same store this will increase quantity in cart instead of creating new row. And if user add same product from different store this will create a new row.

In Detail - I want to add cart product in different – different row but on the basis Vendor Store Id (i.e custom option). Means i setup custom multi vendor functionality. So user can add same product multiple times with different – different seller/vendors. If i am using above code this will create separate row for each seller. But the problem is, when user choose items multiple times with same seller. I need to increasing quantity of item at corresponding seller-item row.

Can anyone please guide me how could i achieve this functionality?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.