/** * Add svea data to additional_information * * @param Varien_Event_Observer $observer */ public function addSveaData(Varien_Event_Observer $observer) { $payment = $observer->getEvent()->getPayment(); $data = $observer->getEvent()->getInput(); $payment = $this->_addAdditionalInfoToPayment($data, $payment); if ($data['method'] == 'svea_invoice') { // Get fee and tax class $paymentFee = Mage::getStoreConfig('payment/svea_invoice/handling_fee'); $paymentFeeTaxId = Mage::getStoreConfig('payment/svea_invoice/handling_fee_tax_class'); if ($paymentFee > 0) { $quote = Mage::getSingleton('checkout/session')->getQuote(); // Get tax rate for select tax $taxRequest = new Varien_Object(); $taxRequest->setProductClassId($paymentFeeTaxId); $taxRequest->setCustomerClassId($quote->getCustomerTaxClassId()); $taxRequest->setCountryId($quote->getShippingAddress()->getCountry()); $taxHelper = Mage::getSingleton('tax/calculation'); $percent = (100 + $taxHelper->getRate($taxRequest)) / 100; $paymentFeeTaxAmount = $paymentFee - $paymentFee / $percent; $payment->setAdditionalInformation('svea_payment_fee', $paymentFee); $payment->setAdditionalInformation('svea_payment_fee_tax_amount', $paymentFeeTaxAmount); $payment->setAdditionalInformation('svea_payment_fee_refunded', 0); $payment->setAdditionalInformation('svea_payment_fee_invoiced', 0); } } }
public function getRateRequest($shippingAddress = null, $billingAddress = null, $customerTaxClass = null, $store = null) { if ($shippingAddress === false && $billingAddress === false && $customerTaxClass === false) { return $this->getRateOriginRequest($store); } $address = new Varien_Object(); $customer = $this->getCustomer(); $basedOn = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $store); if ($shippingAddress === false && $basedOn == 'shipping' || $billingAddress === false && $basedOn == 'billing') { $basedOn = 'default'; } else { if (($billingAddress === false || is_null($billingAddress) || !$billingAddress->getCountryId()) && $basedOn == 'billing' || ($shippingAddress === false || is_null($shippingAddress) || !$shippingAddress->getCountryId()) && $basedOn == 'shipping') { if ($customer) { $defBilling = $customer->getDefaultBillingAddress(); $defShipping = $customer->getDefaultShippingAddress(); if ($basedOn == 'billing' && $defBilling && $defBilling->getCountryId()) { $billingAddress = $defBilling; } else { if ($basedOn == 'shipping' && $defShipping && $defShipping->getCountryId()) { $shippingAddress = $defShipping; } else { $basedOn = 'default'; } } } else { $basedOn = 'default'; } } } if ($billingAddress && $billingAddress && ($billingAddress->getRegion() == 'California' || $shippingAddress->getRegion() == 'California')) { $customerTaxClass = 5; } switch ($basedOn) { case 'billing': $address = $billingAddress; break; case 'shipping': $address = $shippingAddress; break; case 'origin': $address = $this->getRateOriginRequest($store); break; case 'default': $address->setCountryId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, $store))->setRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION, $store))->setPostcode(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, $store)); break; } if (is_null($customerTaxClass) && $customer) { $customerTaxClass = $customer->getTaxClassId(); } elseif ($customerTaxClass === false || !$customer) { $customerTaxClass = $this->getDefaultCustomerTaxClass($store); } $request = new Varien_Object(); $request->setCountryId($address->getCountryId())->setRegionId($address->getRegionId())->setPostcode($address->getPostcode())->setStore($store)->setCustomerClassId($customerTaxClass); return $request; }
/** * Get request object with information necessary for getting tax rate * Request object contain: * country_id (->getCountryId()) * region_id (->getRegionId()) * postcode (->getPostcode()) * customer_class_id (->getCustomerClassId()) * store (->getStore()) * * @param null|false|Varien_Object $shippingAddress * @param null|false|Varien_Object $billingAddress * @param null|int $customerTaxClass * @param null|int $store * @return Varien_Object */ public function getRateRequest($shippingAddress = null, $billingAddress = null, $customerTaxClass = null, $store = null) { if ($shippingAddress === false && $billingAddress === false && $customerTaxClass === false) { return $this->getRateOriginRequest($store); } $address = new Varien_Object(); $customer = $this->getCustomer(); $basedOn = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $store); if ($shippingAddress === false && $basedOn == 'shipping' || $billingAddress === false && $basedOn == 'billing') { $basedOn = 'default'; } else { if (($billingAddress === false || is_null($billingAddress) || !$billingAddress->getCountryId()) && $basedOn == 'billing' || ($shippingAddress === false || is_null($shippingAddress) || !$shippingAddress->getCountryId()) && $basedOn == 'shipping') { if ($customer) { $defBilling = $customer->getDefaultBillingAddress(); $defShipping = $customer->getDefaultShippingAddress(); if ($basedOn == 'billing' && $defBilling && $defBilling->getCountryId()) { $billingAddress = $defBilling; } else { if ($basedOn == 'shipping' && $defShipping && $defShipping->getCountryId()) { $shippingAddress = $defShipping; } else { $basedOn = 'default'; } } } else { $basedOn = 'default'; } } } switch ($basedOn) { case 'billing': $address = $billingAddress; break; case 'shipping': $address = $shippingAddress; break; case 'origin': $address = $this->getRateOriginRequest($store); break; case 'default': $address->setCountryId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, $store))->setRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION, $store))->setPostcode(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, $store)); break; } if (is_null($customerTaxClass) && $customer) { $customerTaxClass = $customer->getTaxClassId(); } elseif ($customerTaxClass === false || !$customer) { $customerTaxClass = $this->getDefaultCustomerTaxClass($store); } $request = new Varien_Object(); if ($address->getBuyWithoutVat() > 0) { $mode = null; $country_code = $address->getCountry(); if ($country_code == "GR") { $country_code = "EL"; } if ($address->getCountry() == Mage::helper('gomage_checkout')->getConfigData('vat/country')) { $mode = Mage::helper('gomage_checkout')->getVatBaseCountryMode(); } elseif (in_array($country_code, array("AT", "BE", "BG", "CY", "CZ", "DE", "DK", "EE", "EL", "ES", "FI", "FR", "GB", "HU", "IE", "IT", "LT", "LU", "LV", "MT", "NL", "PL", "PT", "RO", "SE", "SI", "SK"))) { $mode = Mage::helper('gomage_checkout')->getVatWithinCountryMode(); } if ($mode) { $rule_ids = Mage::helper('gomage_checkout')->getConfigData('vat/rule'); if ($rule_ids) { switch ($mode) { case 1: if ($address->getIsValidVat() > 0) { $request->setDisableByRule($rule_ids); } break; case 2: $request->setDisableByRule($rule_ids); break; } } } } $request->setCountryId($address->getCountryId())->setRegionId($address->getRegionId())->setPostcode($address->getPostcode())->setStore($store)->setCustomerClassId($customerTaxClass); return $request; }
protected function _initProductTaxClassId(Mage_Catalog_Model_Product $product) { if (!is_null($this->_productTaxClassId)) { $product->setTaxClassId($this->_productTaxClassId); return; } if ($this->_taxPercent > 0) { // Getting tax percent for magento product // ------------------------- $requestTax = new Varien_Object(); $requestTax->setCountryId($this->_quote->getShippingAddress()->getCountryId())->setRegionId($this->_quote->getShippingAddress()->getRegionId())->setPostcode($this->_quote->getShippingAddress()->getPostcode())->setStore($this->_quote->getStore())->setCustomerClassId($this->_quote->getCustomerTaxClassId())->setProductClassId($product->getTaxClassId()); $productTaxPercent = Mage::getSingleton('tax/calculation')->getRate($requestTax); // ------------------------- // If magento product tax class has other tax percent // set temp tax class with ebay order tax percent // ------------------------- if ($this->_taxPercent != (double) $productTaxPercent) { $product->setTaxClassId($this->_getProductTaxClassId()); } else { $this->_productTaxClassId = $product->getTaxClassId(); } // ------------------------- } else { // If order has no tax - disable magento product tax class // ------------------------- $product->setTaxClassId(0); // ------------------------- } }
/** * Retrieve rates by customer tax class * * @param int $customerTaxClassId * @param int $productTaxClassId * @return array */ public function getRatesByCustomerTaxClass($customerTaxClass, $productTaxClass = null) { $adapter = $this->_getReadAdapter(); $customerTaxClassId = (int) $customerTaxClass; $calcJoinConditions = array('calc_table.tax_calculation_rate_id = main_table.tax_calculation_rate_id', $adapter->quoteInto('calc_table.customer_tax_class_id = ?', $customerTaxClassId)); if ($productTaxClass) { $productTaxClassId = (int) $productTaxClass; $calcJoinConditions[] = $adapter->quoteInto('calc_table.product_tax_class_id = ?', $productTaxClassId); } $selectCSP = $adapter->select(); $selectCSP->from(array('main_table' => $this->getTable('tax/tax_calculation_rate')), array('country' => 'tax_country_id', 'region_id' => 'tax_region_id', 'postcode' => 'tax_postcode'))->joinInner(array('calc_table' => $this->getTable('tax/tax_calculation')), implode(' AND ', $calcJoinConditions), array('product_class' => 'calc_table.product_tax_class_id'))->joinLeft(array('state_table' => $this->getTable('directory/country_region')), 'state_table.region_id = main_table.tax_region_id', array('region_code' => 'state_table.code'))->distinct(true); $CSP = $adapter->fetchAll($selectCSP); $result = array(); foreach ($CSP as $one) { $request = new Varien_Object(); $request->setCountryId($one['country'])->setRegionId($one['region_id'])->setPostcode($one['postcode'])->setCustomerClassId($customerTaxClassId)->setProductClassId($one['product_class']); $rate = $this->getRate($request); if ($rate) { $row = array('value' => $rate / 100, 'country' => $one['country'], 'state' => $one['region_code'], 'postcode' => $one['postcode'], 'product_class' => $one['product_class']); $result[] = $row; } } return $result; }
public function getRateRequest($shippingAddress = null, $billingAddress = null, $customerTaxClass = null, $store = null) { $address = new Varien_Object(); $session = Mage::getSingleton('customer/session'); $basedOn = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_BASED_ON, $store); if ($shippingAddress === false && $basedOn == 'shipping' || $billingAddress === false && $basedOn == 'billing') { $basedOn = 'default'; } else { if (($billingAddress === false || is_null($billingAddress) || !$billingAddress->getCountryId()) && $basedOn == 'billing' || ($shippingAddress === false || is_null($shippingAddress) || !$shippingAddress->getCountryId()) && $basedOn == 'shipping') { if (!$session->isLoggedIn()) { $basedOn = 'default'; } else { $defBilling = $session->getCustomer()->getDefaultBillingAddress(); $defShipping = $session->getCustomer()->getDefaultShippingAddress(); if ($basedOn == 'billing' && $defBilling && $defBilling->getCountryId()) { $billingAddress = $defBilling; } else { if ($basedOn == 'shipping' && $defShipping && $defShipping->getCountryId()) { $shippingAddress = $defShipping; } else { $basedOn = 'default'; } } } } } switch ($basedOn) { case 'billing': $address = $billingAddress; break; case 'shipping': $address = $shippingAddress; break; case 'origin': $address->setCountryId(Mage::getStoreConfig('shipping/origin/country_id', $store))->setRegionId(Mage::getStoreConfig('shipping/origin/region_id', $store))->setPostcode(Mage::getStoreConfig('shipping/origin/postcode', $store)); break; case 'default': $address->setCountryId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, $store))->setRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION, $store))->setPostcode(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, $store)); break; } if (is_null($customerTaxClass) && $session->isLoggedIn()) { $customerTaxClass = $session->getCustomer()->getTaxClassId(); } elseif ($customerTaxClass === false || !$session->isLoggedIn()) { $defaultCustomerGroup = Mage::getStoreConfig('customer/create_account/default_group', $store); $customerTaxClass = Mage::getModel('customer/group')->getTaxClassId($defaultCustomerGroup); } $request = new Varien_Object(); $request->setCountryId($address->getCountryId())->setRegionId($address->getRegionId())->setPostcode($address->getPostcode())->setStore($store)->setCustomerClassId($customerTaxClass); return $request; }
private function getDefaultDestination($store = null) { $this->log('default dest'); $address = new Varien_Object(); $request = new Varien_Object(); $address->setCountryId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, $store))->setRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION, $store))->setPostcode(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, $store)); $customerTaxClass = null; $customer = $this->getCustomer(); if (is_null($customerTaxClass) && $customer) { $customerTaxClass = $customer->getTaxClassId(); } elseif ($customerTaxClass === false || !$customer) { $customerTaxClass = $this->getDefaultCustomerTaxClass($store); } $request->setCountryId($address->getCountryId())->setRegionId($address->getRegionId())->setPostcode($address->getPostcode())->setStore($store)->setCustomerClassId($customerTaxClass); return $request; }
/** * Copy address * * @param Varien_Object $srcAddress * @param Varien_Object $dstAddress * @return Innoexts_Warehouse_Helper_Data */ public function copy($srcAddress, $dstAddress) { $dstAddress->setCountryId($srcAddress->getCountryId()); $dstAddress->setRegionId($srcAddress->getRegionId()); $dstAddress->setRegion($srcAddress->getRegion()); $dstAddress->setCity($srcAddress->getCity()); $dstAddress->setPostcode($srcAddress->getPostcode()); $dstAddress->setStreet($srcAddress->getStreet()); return $this; }