0

I want to get the status of customer cart for a particular products that is products added in his cart or removed. I have loop of products and each products have customer and i have customer_id , product_id now i want to check that is this products added in customer cart or not.

0

Ad the following method to needed class:

public function getProductInCart($customer, $productId, $storeId = null)
{
    if (!$customer instanceof Mage_Customer_Model_Customer) {
        $customer = Mage::getModel('customer/customer')->load($customer);
    }

    if (!$customer->getId()) {
        return false;
    }

    if ($storeId === null) {
        $storeId = Mage::app()->getWebsite(true)->getDefaultGroup()->getDefaultStoreId();
    }
    $quote = Mage::getModel('sales/quote')->setStoreId($storeId)->loadByCustomer($customer);

    if (!$quote->getId()) {
        return false;
    }

    foreach ($quote->getAllVisibleItems() as $item) {
        if($item->getProductId() == $productId) {
            return true;
        }

    }
    return false;
}

Using example:

$this->getProductsInCart(customer_id, product_id, store_id)
  • Not working for me i have create a custom module for admin section to verify the products that customer reserve before checkout and i will approve that i try user function and i dont have any storeId and default is is showing 1 so can you please let me know in which table the cart is saved Then i can check directory from that tables using custom query based on productId and customerId – kantsverma Jul 11 '16 at 20:16

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.