1

I have custom attributes for products (defined via module) with different options/values and price increases. I have managed to track down most of the events that I need in order to transfer these attributes (on add to cart, on front end reorder, on checkout).

I am unable to get these attributes to stay associated with the item when checking the box and adding the item to the cart from the sidebar under "Last Ordered Items". I suspect this has something to do with the ajax add to cart and the data that gets passed through.

The bigger and more important issue is that if a customer adds a product with attributes to their cart, then logs in, none of the attributes transfer over. Is there a specific event I can hook into for this? If I can just use the logic I already have for when I add an item to the cart, and maybe just make it get all items instead of the one item, that would be helpful.

I've tried controller_action_predispatch, customer_login, sales_quote_merge_before and checkout_cart_product_add_after, and neither work, though I'm not sure if it's because of the code I'm using or because the event isn't correct.

Problem is, I don't need to call this on add to cart, I need to call it only when they're logging in.

Here's the function I'm calling:

public function modifyAllItems()
{
    $cart = Mage::getModel('checkout/cart')->getQuote();
    foreach ($cart->getAllItems() as $item) {
        $item_id = $item->getProduct()->getId();
        $product_price = $item->getPrice();
        $exclude_protein = $item->getData('exclude_protein');
        $sub_protein = $item->getData('sub_protein');
        $exclude_sides = $item->getData('exclude_sides');
        $sub_sides = $item->getData('sub_sides');

        $item->setData('exclude_protein', $exclude_protein);
        $item->setData('sub_protein', $sub_protein);
        $item->setData('exclude_sides', $exclude_sides);
        $item->setData('sub_sides', $sub_sides);

        // Set the custom price
        $item->setCustomPrice($product_price);
        $item->setOriginalCustomPrice($product_price);
        // Enable super mode on the product.
        $item->getProduct()->setIsSuperMode(true);
    }
}

Your Answer

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

Browse other questions tagged or ask your own question.