magento-gifts icon indicating copy to clipboard operation
magento-gifts copied to clipboard

Don't save shipping method

Open michel3vb opened this issue 11 years ago • 9 comments

For some reason the protected function _reset($address) in Validator.php removes the shipping method from the quote. I use the standard Magento OnePage checkout and after saving the shipping method the shipping method is empty. When there is no item in the quote that affects the "shopping cart gift rule" there is no problem with saving the shipping method.

Have you any idea what is causing this problem?

michel3vb avatar Oct 24 '13 15:10 michel3vb

The only operation which modifies the quote there is removeItem() but this method doesn't change the shipping method or am I wrong?

witrin avatar Oct 24 '13 15:10 witrin

I dont no of you are wrong but when i comment out $quote->removeItem($item->getId()); there is no problem with saving the shipping method. I don't understand why removeItem() also removes the shipping method?

michel3vb avatar Oct 24 '13 22:10 michel3vb

Hopefully I understand you right. When you wrote "removes the shipping method from the quote" did you mean the the selected shipping method is not saved for a later usage of a canceled checkout process or does it break a running checkout process?

witrin avatar Oct 25 '13 14:10 witrin

protected function _reset($address)
{
    $quote = $address->getQuote();
    Mage::log($quote->getShippingAddress()->getShippingMethod()); 
    //Result = freeshipping_freeshipping (based on what you select)

    if (!array_key_exists($quote->getId(), $this->_resetRules)) {
        $this->_resetRules[$quote->getId()] = array();
    }

    if (!array_key_exists($quote->getId(), $this->_appliedRules)) {
        $this->_appliedRules[$quote->getId()] = array();
    }

    foreach ( $quote->getAllItems() as $item ) {
        if ($option = $item->getOptionByCode('gift')) {
            $value = unserialize($option->getValue());
            if ($item->getId()) {
                $this->_resetRules[$quote->getId()][$value['rule_id']] = $value['rule_id'];
                $quote->removeItem($item->getId());
            } else {
                $this->_appliedRules[$quote->getId()][$value['rule_id']] = $value['rule_id'];
            }
        }
    }

    Mage::log($quote->getShippingAddress()->getShippingMethod()); 
    //Result = empty! 

    $address->setGiftRuleIds('');
    $address->getQuote()->setGiftRuleIds('');
}

See code above It brokes the running checkout process because when you try to place the order it says "No shipping method selected".

michel3vb avatar Oct 25 '13 14:10 michel3vb

I think there are two possibilities either the event sales_quote_address_collect_totals_after (see etc/config.xml and Model/Observer.php) is poorly chosen and should be changed or the shipping method should be restored. The funny thing is it works flawless on a demo system, maybe there is any configuration entry I didn't taken into account!?

Unfortunately currently I've heavy time pressure. But I'll try to fix this as soon as possible.

witrin avatar Oct 25 '13 16:10 witrin

I've tried to reproduce your bug report without success. I've used the sample data from Magento on a fresh install of CE 1.7.0.2. The only thing is that with the sample data there is only one shipment method to select but it is saved. Do you use any other extensions?

witrin avatar Nov 14 '13 13:11 witrin

No answer.

witrin avatar Dec 05 '13 12:12 witrin

I have the same problem. After an hour of investigation, this line is causing the issue: $quote->removeItem($item->getId());

When commenting out that line, the shipping method problem is solved, but the gift is added on each page load (so ending up with more than one gift).

verhaeghep avatar Mar 10 '14 20:03 verhaeghep

This was already noted (see above). But like I already wrote, I can't reproduce this issue on a fresh install. So I need to know which third party extensions you use and what the configuration of your store is. Maybe you could test a little bit by deactivating your third party extensions and change your setup e.g. allow only one shipping method.

witrin avatar Mar 10 '14 21:03 witrin