Answer the question
In order to leave comments, you need to log in
Shipping (Shipping) by default in Magento?
There was a problem setting up delivery charges in Magento. The bottom line is that the system calculates the cost of delivery after the checkout, and before that it simply does not display the corresponding field in the Summary of the basket.
What is? The shipping cost is fixed, always the same, and for the entire basket (regardless of the quantity or cost of the goods in it).
What do you need? As soon as I entered the cart, I should see the corresponding field without waiting for the checkout. Kind of like a default delivery.
For those who know, perhaps the task is trifling, but it already spoils my nerves. I would be grateful for help.
Answer the question
In order to leave comments, you need to log in
If I understand correctly, then default shipping can be implemented by editing the file app/design/frontend/default/default/template/checkout/onepage/shipping_method/available.phtml
Find:
<?php foreach ($_rates as $_rate): ?>
Add this code (in this case, check if there is a free delivery):
<?php if ($_rate->getCode()=='freeshipping_freeshipping' && !$this->getAddress()->getShippingMethod()) {
$this->getAddress()->setShippingMethod($_rate->getCode());
} ?>
In order for the shipping cost to be displayed in the cart, you need this method to be activated for this cart. To do this, just add an observer to the checkout_cart_save_after event and implement the addition in the code:
$_shippingMethod = 'freeshipping_freeshipping';
$_session = Mage::getSingleton('checkout/session');
$_quote = $_session->getQuote();
$_address = $_quote->getShippingAddress();
$_sessionCost = $_session->getQuoteShippingCost();
$_sessionCountry = $_session->getQuoteShippingCountry();
if ((!$_sessionCost || $_sessionCost == 0)) {
$_country = null;
$_customerSession = Mage::getSingleton('customer/session');
if ($_customerSession->isLoggedIn()) {
$_customerAddress = $_customerSession->getCustomer()->getDefaultShippingAddress();
if ($_customerAddress != null) {
if ($_customerAddress->getId()) $_country = $_customerAddress->getCountryId();
}
}
if ($_country == null) $_country = 'US';
$_address->setCountryId($_country);
if ($this->_getRequest()->getParam('zip_code')) {
$_address->setPostcode($this->_getRequest()->getParam('zip_code'));
}
$_address->setCollectShippingRates(true)->collectShippingRates();
$_quote->setShippingMethod($_shippingMethod)->save();
$_method = $_quote->getShippingMethod();
if ($_method) {
foreach ($_address->getAllShippingRates() as $_rate) {
if ($_rate->getCode() == $_method) {
$_session->setQuoteShippingCost($_address->getQuote()->getStore()->convertPrice($_rate->getPrice(), false));
Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->setCountryId($_country)->setShippingMethod($_method)->save();
break;
}
}
}
$_session->getQuote()->save();
$_session->resetCheckout();
} else {
//log
}
The code may vary slightly, but the principle is this
There is a ready-made solution based on the Mage_Autoquote module . I checked its work on the basis of Magento 1.8.1.0
This is how the page with settings in the backend looks like:
Front screen immediately after adding the product to the cart with the extension enabled:
And here you can find answers to a similar question in English.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question