27 августа 2012
Маленькая, но очень нужная заметка - как сделать так, чтобы в корзине автоматом был выбран способ доставки.
В данном примере задаем всем фиксированную стоимость отправления (flatrate):
Способ первый:
if (!Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getCountryId()) {
    $customerSession = Mage::getSingleton("customer/session");
    if ($customerSession->isLoggedIn()) {
        $customerAddress = $customerSession->getCustomer()->getDefaultShippingAddress();
        if ($customerAddress->getId()) {
            $customerCountry = $customerAddress->getCountryId();
            $shipping = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()
            ->setCountryId($customerCountry)->setShippingMethod('flatrate_flatrate')->save();
        } else {
            $shipping = Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()
            ->setCountryId('RU')->setShippingMethod('flatrate_flatrate')->save();
        }
    }
}
Способ второй:
$shippingAddress = $this->getQuote()->getShippingAddress();if (!$shippingAddress->getCountryId()) { $shippingAddress->setCountryId() == ‘RU’; }
if ($shippingAddress->getCountryId() == ‘RU’) { if ($shippingAddress->getShippingMethod() == ”) { $shippingAddress->setShippingMethod(‘flatrate_flatrate’)->save(); $this->getQuote()->save(); Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl(‘checkout/cart/’)); } } else { if ($shippingAddress->getCountryId() != ‘RU’) { if ($shippingAddress->getShippingMethod() == ”) { $shippingAddress->setShippingMethod(‘flatrate_flatrate’)->save(); $shippingAddress->save(); Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl(‘checkout/cart/’)); } } }