/** * Import totals information from google request to quote address * * @param Varien_Object $qAddress */ protected function _importGoogleTotals($qAddress) { $quote = $qAddress->getQuote(); $qAddress->setTaxAmount($this->_reCalculateToStoreCurrency($this->getData('root/order-adjustment/total-tax/VALUE'), $quote)); $qAddress->setBaseTaxAmount($this->getData('root/order-adjustment/total-tax/VALUE')); $method = null; $prefix = 'root/order-adjustment/shipping/'; if (null !== ($shipping = $this->getData($prefix . 'carrier-calculated-shipping-adjustment'))) { $method = 'googlecheckout_carrier'; } else { if (null !== ($shipping = $this->getData($prefix . 'merchant-calculated-shipping-adjustment'))) { $method = $this->_getShippingMethodByName($shipping['shipping-name']['VALUE']); if ($method === false) { $method = 'googlecheckout_merchant'; } } else { if (null !== ($shipping = $this->getData($prefix . 'flat-rate-shipping-adjustment'))) { $method = 'googlecheckout_flatrate'; } else { if (null !== ($shipping = $this->getData($prefix . 'pickup-shipping-adjustment'))) { $method = 'googlecheckout_pickup'; } } } } if ($method) { Mage::getSingleton('Mage_Tax_Model_Config')->setShippingPriceIncludeTax(false); $rate = $this->_createShippingRate($method)->setMethodTitle($shipping['shipping-name']['VALUE'])->setPrice($shipping['shipping-cost']['VALUE']); $qAddress->addShippingRate($rate)->setShippingMethod($method)->setShippingDescription($shipping['shipping-name']['VALUE']); // We get from Google price with discounts applied via merchant calculations $qAddress->setShippingAmountForDiscount(0); /*if (!Mage::helper('Mage_Tax_Helper_Data')->shippingPriceIncludesTax($quote->getStore())) { $includingTax = Mage::helper('Mage_Tax_Helper_Data')->getShippingPrice( $excludingTax, true, $qAddress, $quote->getCustomerTaxClassId() ); $shippingTax = $includingTax - $excludingTax; $qAddress->setShippingTaxAmount($this->_reCalculateToStoreCurrency($shippingTax, $quote)) ->setBaseShippingTaxAmount($shippingTax) ->setShippingInclTax($includingTax) ->setBaseShippingInclTax($this->_reCalculateToStoreCurrency($includingTax, $quote)); } else { if ($method == 'googlecheckout_carrier') { $qAddress->setShippingTaxAmount(0) ->setBaseShippingTaxAmount(0); } }*/ } else { $qAddress->setShippingMethod(null); } $qAddress->setGrandTotal($this->_reCalculateToStoreCurrency($this->getData('root/order-total/VALUE'), $quote)); $qAddress->setBaseGrandTotal($this->getData('root/order-total/VALUE')); }
/** * Import totals information from google request to quote address * * @param Varien_Object $qAddress */ protected function _importGoogleTotals($qAddress) { $quote = $qAddress->getQuote(); $qAddress->setTaxAmount($this->_reCalculateToStoreCurrency($this->getData('root/order-adjustment/total-tax/VALUE'), $quote)); $qAddress->setBaseTaxAmount($this->getData('root/order-adjustment/total-tax/VALUE')); $prefix = 'root/order-adjustment/shipping/'; if ($shipping = $this->getData($prefix . 'carrier-calculated-shipping-adjustment')) { $method = 'googlecheckout_carrier'; } elseif ($shipping = $this->getData($prefix . 'merchant-calculated-shipping-adjustment')) { $method = 'googlecheckout_merchant'; } elseif ($shipping = $this->getData($prefix . 'flat-rate-shipping-adjustment')) { $method = 'googlecheckout_flatrate'; } elseif ($shipping = $this->getData($prefix . 'pickup-shipping-adjustment')) { $method = 'googlecheckout_pickup'; } if (!empty($method)) { Mage::getSingleton('tax/config')->setShippingPriceIncludeTax(false); $rate = Mage::getModel('sales/quote_address_rate')->setCode($method)->setPrice($shipping['shipping-cost']['VALUE']); $qAddress->addShippingRate($rate)->setShippingMethod($method)->setShippingDescription($shipping['shipping-name']['VALUE']); /*if (!Mage::helper('tax')->shippingPriceIncludesTax($quote->getStore())) { $includingTax = Mage::helper('tax')->getShippingPrice($excludingTax, true, $qAddress, $quote->getCustomerTaxClassId()); $shippingTax = $includingTax - $excludingTax; $qAddress->setShippingTaxAmount($this->_reCalculateToStoreCurrency($shippingTax, $quote)) ->setBaseShippingTaxAmount($shippingTax) ->setShippingInclTax($includingTax) ->setBaseShippingInclTax($this->_reCalculateToStoreCurrency($includingTax, $quote)); } else { if ($method == 'googlecheckout_carrier') { $qAddress->setShippingTaxAmount(0) ->setBaseShippingTaxAmount(0); } }*/ } else { $qAddress->setShippingMethod(null); } $qAddress->setGrandTotal($this->_reCalculateToStoreCurrency($this->getData('root/order-total/VALUE'), $quote)); $qAddress->setBaseGrandTotal($this->getData('root/order-total/VALUE')); }
/** * Validate Address Rule Condition * * @param Varien_Object|Mage_Sales_Model_Order|Mage_Sales_Model_Quote $object * @return bool */ public function validate(Varien_Object $object) { $quote = $object; if (!$object instanceof Mage_Sales_Model_Quote) { $quote = Mage::getModel('sales/quote')->load($object->getQuoteId()); } $address = $quote->getBillingAddress(); //Get infos from billing address $toValidate = new Varien_Object(); $toValidate->setBillingPostcode($address->getPostcode()); $toValidate->setBillingRegion($address->getRegion()); $toValidate->setBillingRegionId($address->getRegionId()); $toValidate->setBillingCountryId($address->getCountryId()); if (!$quote->isVirtual()) { //Get infos from shipping address $address = $quote->getShippingAddress(); } $toValidate->setBaseSubtotal($address->getBaseSubtotal()); $toValidate->setBaseGrandTotal($address->getBaseGrandTotal()); $toValidate->setWeight($address->getWeight()); $toValidate->setShippingMethod($address->getShippingMethod()); $toValidate->setTotalQty($quote->getItemsQty()); $toValidate->setBaseCurrencyCode($quote->getBaseCurrencyCode()); $toValidate->setCreatedAt($this->_getFormatCreatedAt($object)); return parent::validate($toValidate); }