I am using onepage checkout extension, I wish to add shipping charges of products to be added in review block before login and entering customer information.
Let us take an example, product having a cost of Rs.430 and its shipping charge is Rs.80(set from backend for every product), then I just want to show 430+80 in review block, without entering any details and before login at onepage checkout page.Kindly refer to the attached screenshot for the same.
1 Answer
Yes, you can do this by using an event observer, you can use the "sales_quote_collect_totals_before"
event to add your shipping method like "flatrate"
and set the necessary values and display on review page, please find the code below and use it as per your requirement :)
Event:
<sales_quote_collect_totals_before>
<observers>
<set_shipping_cartpage>
<type>singleton</type>
<class>modulename/observer</class>
<method>yourmethodname</method>
</set_shipping_cartpage>
</observers>
</sales_quote_collect_totals_before>
Observer:
$country = 'US'; //your country code
$postcode = '';
$city = '';
$regionId = '';
$region = '';
$code = 'modulename_standard';
$quote = $observer->getEvent()->getQuote();
if (!$quote->getId()) return;
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
if ($shippingMethod) return;
$shippingAddress = $quote->getShippingAddress();
$model = Mage::getModel("modulename/carrier_method_standard");
$subTotal = $quote->getSubtotal();
$price = 0.00; // Add your shipping price
$shippingAddress
->setCountryId($country)
->setRegionId($regionId)
->setPostcode($postcode)
->setShippingMethod($code)
->setShippingAmount($price)
->setCollectShippingRates(true);
$shippingAddress->save();
$quote->save();
After that you need to override the collectotals to add you shipping like I mentioned above "carrier_method_standard"
and on checkout page override the progress block to add your functions to display your before login shipping method. Hope that will help you to integrate the same :)
Accept it if that helps.