I want to add two variable in specific product using observer event controller_action_predispatch_checkout_cart_add. These two variable are use in checkout/cart page for display prupose.

Following config.xml.


Following Observer.php

public function logCartAdd($event)

        new Varien_Object(array(
            'productId' => Mage::app()->getRequest()->getPost('product'),
            'rentalDays' => Mage::app()->getRequest()->getPost('rentalDays'),
            'deliveryDate' => Mage::app()->getRequest()->getPost('delivery_date'),

Following test-deliverydate.xml

    <reference name="content">
        <block type="core/template" template="test/deliverydate/bookingdate.phtml" />

Following bookingdate.phtml

    $bookedProductDetail = Mage::getModel('core/session')->getProductToShoppingCart() ;
    $productSku = Mage::getModel('catalog/product')->load($bookedProductDetail->getData('productId'))->getSku();
    $rendDays = $bookedProductDetail->getData('rentalDays');

    $bookedDate = $bookedProductDetail->getData('deliveryDate');
    $bookedDate = strtotime($bookedDate);
    $bookedDate = date('Y-m-d', $bookedDate);

    <p> <?php echo $productSku; ?> </p>
    <p> <?php echo $rendDays; ?> </p>
    <p> <?php echo $bookedDate; ?> </p>

When I add multiple products at that time last product's detail like : $rendDays, $bookedDate showing same for all added products. Please help me how can i solve this problem.


Perhaps something like

 $cartItems = Mage::getSingleton('checkout/session')


foreach ($cartItems as $item) {
    $_product = Mage::getModel('catalog/product')->load($item->getProductId());
    $rentalDays = $_product->getData('rentalDays');
    // then do something with it
    echo $rentalDays . '<br>';
  • may be this isn't work because i want update product value before add to cart so that $cartItems may be empty. – Hardik Visa Feb 27 '16 at 8:53

We Can use below code for get all post value for perticullar product.

$quote = $observer->getQuote();
    $quote_items = $quote->getItemsCollection();
    foreach ($quote_items as $item)
        if ($item instanceof Mage_Sales_Model_Quote_Item) 
            $infoBuyRequest = $item->getOptionByCode('info_buyRequest');
            $buyRequest = new Varien_Object(unserialize($infoBuyRequest->getValue()));
        else if ($item instanceof Mage_Sales_Model_Order_Item) 
            $buyRequest = new Varien_Object($item->getProductOptions());

We can get all data of product.

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.