0

I'm trying to set a custom information for the product on the Catalog (product detail page) and retrieve this information at the checkout. Note: I need to associate with the specific product so I can get the information for every product at the cart.

At the product page I'm using this logic:

$_product  =  Mage::Registry('current_product');
$customInfo =  "teste 123";
$_product   -> setData('seller', $customInfo );

And to retrieve the information at the cart page, I'm using this logic:

$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
     $customInfo = $item->getProduct()->getData('seller');
}

The logic is not working.

What is the best way to associate specific values for specific products during the user session and retrieve this information?

Thx

1 Answer 1

0

Your solution does not work because "current_product" in registry does not have any connection with items in quote. To save something to quote you need to change DB structure, which is odd in your case.

You can pass this information via session. Here is what you do.

At the product page save the data to session:

$customInfo = Mage::getSingleton('checkout/session')->getData('product_custom_info');
if (!is_array($customInfo)) {
    $customInfo = array();
}
$_product = Mage::registry('current_product');
$customInfo[$_product->getId()] = "teste 123";
Mage::getSingleton('checkout/session')->setData('product_custom_info', $customInfo);

And then you can get this information at checkout:

$customInfo = Mage::getSingleton('checkout/session')->getData('product_custom_info');

foreach ($customInfo as $id => $data) {
    echo "Custom info for product $id = $data <br/>";
}

Your Answer

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

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