Skip to content

Commit

Permalink
Get correct price other shipping method than MyParcel
Browse files Browse the repository at this point in the history
  • Loading branch information
reindertvetter committed Nov 14, 2016
1 parent e24deaa commit 107f277
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
38 changes: 20 additions & 18 deletions app/code/community/TIG/MyParcel2014/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,25 +1110,27 @@ public function updateRatePrice(Mage_Sales_Model_Quote $quote = null)
* @var $rate Mage_Sales_Model_Quote_Address_Rate
*/
$shipAddress = $quote->getShippingAddress();
foreach ($shipAddress->getShippingRatesCollection() as $rate) {
if ($rate->getCarrier() == 'myparcel') {
$price = $this->calculatePrice();
$rate->setPrice($price);
$rate->save();

if(strpos($shipAddress->getShippingMethod(), 'myparcel') !== false) {
foreach ($shipAddress->getShippingRatesCollection() as $rate) {
if ($rate->getCarrier() == 'myparcel') {
$price = $this->calculatePrice();
$rate->setPrice($price);
$rate->save();
}
}
}
/**
* @var $rate Mage_Sales_Model_Quote_Address_Rate
*/
if ($quote->getMyparcelData() !== null && $price != null) {
$store = Mage::app()->getStore($quote->getStoreId());
$carriers = Mage::getStoreConfig('carriers', $store);

foreach ($carriers as $carrierCode => $carrierConfig) {
if ($carrierCode == 'myparcel') {
$fee = $price;
$store->setConfig("carriers/{$carrierCode}/handling_type", 'F'); #F - Fixed, P - Percentage
$store->setConfig("carriers/{$carrierCode}/price", $fee);
/**
* @var $rate Mage_Sales_Model_Quote_Address_Rate
*/
if ($quote->getMyparcelData() !== null && $price != null) {
$store = Mage::app()->getStore($quote->getStoreId());
$carriers = Mage::getStoreConfig('carriers', $store);

foreach ($carriers as $carrierCode => $carrierConfig) {
if ($carrierCode == 'myparcel') {
$store->setConfig("carriers/{$carrierCode}/handling_type", 'F'); #F - Fixed, P - Percentage
$store->setConfig("carriers/{$carrierCode}/price", $price);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function salesQuoteCollectTotalsBefore(Varien_Event_Observer $observer)

$price = Mage::getSingleton('core/session')->getMyParcelBasePrice();

$shipAddress = $quote->getShippingAddress();
if ($price === null) {
$shipAddress = $quote->getShippingAddress();
foreach ($shipAddress->getShippingRatesCollection() as $rate) {
if ($rate->getCarrier() == 'myparcel') {
$price = $rate->getPrice();
Expand All @@ -45,6 +45,8 @@ public function salesQuoteCollectTotalsBefore(Varien_Event_Observer $observer)
}
}

$helper->calculatePrice($price);
if(strpos($shipAddress->getShippingMethod(), 'myparcel') !== false) {
$helper->calculatePrice($price);
}
}
}

0 comments on commit 107f277

Please sign in to comment.