/** * Collect gift wrapping totals * * @param Mage_Sales_Model_Quote_Address $address * @return Enterprise_GiftWrapping_Model_Total_Quote_Giftwrapping */ public function collect(Mage_Sales_Model_Quote_Address $address) { parent::collect($address); if ($address->getAddressType() != Mage_Sales_Model_Quote_Address::TYPE_SHIPPING) { return $this; } $this->_quote = $address->getQuote(); $this->_store = $this->_quote->getStore(); $quote = $this->_quote; if ($quote->getIsMultiShipping()) { $this->_quoteEntity = $address; } else { $this->_quoteEntity = $quote; } $this->_collectWrappingForItems($address)->_collectWrappingForQuote($address)->_collectPrintedCard($address); $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getGwItemsBasePrice() + $address->getGwBasePrice() + $address->getGwCardBasePrice()); $address->setGrandTotal($address->getGrandTotal() + $address->getGwItemsPrice() + $address->getGwPrice() + $address->getGwCardPrice()); if ($quote->getIsNewGiftWrappingCollecting()) { $quote->setGwItemsBasePrice(0); $quote->setGwItemsPrice(0); $quote->setGwBasePrice(0); $quote->setGwPrice(0); $quote->setGwCardBasePrice(0); $quote->setGwCardPrice(0); $quote->setIsNewGiftWrappingCollecting(false); } $quote->setGwItemsBasePrice($address->getGwItemsBasePrice() + $quote->getGwItemsBasePrice()); $quote->setGwItemsPrice($address->getGwItemsPrice() + $quote->getGwItemsPrice()); $quote->setGwBasePrice($address->getGwBasePrice() + $quote->getGwBasePrice()); $quote->setGwPrice($address->getGwPrice() + $quote->getGwPrice()); $quote->setGwCardBasePrice($address->getGwCardBasePrice() + $quote->getGwCardBasePrice()); $quote->setGwCardPrice($address->getGwCardPrice() + $quote->getGwCardPrice()); return $this; }
private function getProductTaxRate() { /** @var $taxCalculator Mage_Tax_Model_Calculation */ $taxCalculator = Mage::getSingleton('tax/calculation'); $request = $taxCalculator->getRateRequest($this->quote->getShippingAddress(), $this->quote->getBillingAddress(), $this->quote->getCustomerTaxClassId(), $this->quote->getStore()); $request->setProductClassId($this->getProduct()->getTaxClassId()); return $taxCalculator->getRate($request); }
public function callGetTaxForQuote(Mage_Sales_Model_Quote $quote) { $request = $this->createTaxRequestFromQuoteAddress($quote->getShippingAddress()); $request = $this->prepareGetTaxRequest($request); $errors = $this->validateTaxRequest($request); if (count($errors)) { return $errors; } return $this->call($quote->getStore(), '1.0/tax/get', $request); }
private function initializeCurrency() { /** @var $currencyHelper Ess_M2ePro_Model_Currency */ $currencyHelper = Mage::getSingleton('M2ePro/Currency'); if ($currencyHelper->isConvertible($this->proxyOrder->getCurrency(), $this->quote->getStore())) { $currentCurrency = Mage::getModel('directory/currency')->load($this->proxyOrder->getCurrency()); } else { $currentCurrency = $this->quote->getStore()->getBaseCurrency(); } $this->quote->getStore()->setData('current_currency', $currentCurrency); }
private function needToSubtractShippingTax() { if (!$this->proxyOrder->isTaxModeChannel() && !$this->proxyOrder->isTaxModeMixed()) { return false; } if (!$this->proxyOrder->isShippingPriceIncludesTax()) { return false; } /** @var $storeConfigurator Ess_M2ePro_Model_Magento_Quote_Store_Configurator */ $storeConfigurator = Mage::getModel('M2ePro/Magento_Quote_Store_Configurator', $this); $storeShippingTaxRate = $storeConfigurator->getStoreShippingTaxRate($this->quote->getStore()); return $this->proxyOrder->getTaxRate() != $storeShippingTaxRate; }
/** * Check max amount on cart * * @param Mage_Sales_Model_Quote $quote */ public function checkCartMaxAmount($quote) { $quoteStore = $quote->getStore(); if ($this->isCartEnable($quoteStore)) { $maxAmount = $this->getCartMaxAmount($quoteStore); $grandTotal = $quote->getGrandTotal(); if ($grandTotal > $maxAmount) { $formater = new Varien_Filter_Template(); $formater->setVariables(array('amount' => Mage::helper('core')->currency($maxAmount, true, false))); $format = $this->getCartMessage($quoteStore); // hold checkout $quote->setHasError(true)->addMessage($formater->filter($format)); } } }
/** * Return the correct rule set * * @param Mage_Sales_Model_Quote $quote * @param bool $forceReload * * @return Mage_SalesRule_Model_Rule[] */ public function getRules(Mage_Sales_Model_Quote $quote, $forceReload = false) { $websiteId = intval($quote->getStore()->getWebsiteId()); $customerGroupId = intval($quote->getCustomerGroupId()); $couponCode = trim($quote->getCouponCode()); $key = $websiteId . '_' . $customerGroupId . '_' . $couponCode; if ($forceReload) { unset($this->rules[$key]); } if (!isset($this->rules[$key])) { /** @var Mage_SalesRule_Model_Resource_Rule_Collection $rules */ $rules = Mage::getResourceModel('salesrule/rule_collection'); $rules->setValidationFilter($websiteId, $customerGroupId, $couponCode); $this->rules[$key] = $rules->getItems(); } return $this->rules[$key]; }
/** * Add product block to cart * * @param Mage_XmlConnect_Model_Simplexml_Element $xmlObject * @param Mage_Sales_Model_Quote $quote * @return null */ public function addCartProductsToXmlObj($xmlObject, $quote) { $productSmallImageSize = Mage::getModel('xmlconnect/images')->getImageLimitParam('content/product_small'); $products = $xmlObject->addCustomChild('products'); /* @var $item Mage_Sales_Model_Quote_Item */ foreach ($this->getItems() as $item) { $type = $item->getProductType(); $renderer = $this->getItemRenderer($type)->setItem($item); /** * General information */ $itemXml = $products->addCustomChild('item', null, array('entity_id' => $item->getProduct()->getId())); $itemXml->addCustomChild('entity_type', $type); $itemXml->addCustomChild('item_id', $item->getId()); $itemXml->addCustomChild('name', $xmlObject->escapeXml($renderer->getProductName())); $itemXml->addCustomChild('code', 'cart[' . $item->getId() . '][qty]'); $itemXml->addCustomChild('qty', $renderer->getQty()); $icon = $renderer->getProductThumbnail()->resize($productSmallImageSize); $iconXml = $itemXml->addChild('icon', $icon); $iconXml->addAttribute('modification_time', filemtime($icon->getNewFile())); /** * Price */ $pricesXmlObj = $itemXml->addCustomChild('price_list'); $exclPrice = $inclPrice = 0; if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') && $item->getWeeeTaxAppliedAmount()) { $exclPrice = $item->getCalculationPrice() + $item->getWeeeTaxAppliedAmount() + $item->getWeeeTaxDisposition(); } else { $exclPrice = $item->getCalculationPrice(); } } if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) { $incl = $this->helper('checkout')->getPriceInclTax($item); if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') && $item->getWeeeTaxAppliedAmount()) { $inclPrice = $incl + $item->getWeeeTaxAppliedAmount(); } else { $inclPrice = $incl - $item->getWeeeTaxDisposition(); } } $exclPrice = Mage::helper('xmlconnect')->formatPriceForXml($exclPrice); $paypalPrice = Mage::helper('xmlconnect')->formatPriceForXml($item->getCalculationPrice()); $formattedExclPrice = $quote->getStore()->formatPrice($exclPrice, false); $inclPrice = Mage::helper('xmlconnect')->formatPriceForXml($inclPrice); $formattedInclPrice = $quote->getStore()->formatPrice($inclPrice, false); $priceXmlObj = $pricesXmlObj->addCustomChild('prices', null, array('id' => 'price')); if ($this->helper('tax')->displayCartBothPrices()) { $priceXmlObj->addCustomChild('price', $exclPrice, array('id' => 'excluding_tax', 'label' => $this->__('Excl. Tax'), 'formatted_value' => $formattedExclPrice)); $priceXmlObj->addCustomChild('price', $inclPrice, array('id' => 'including_tax', 'label' => $this->__('Incl. Tax'), 'formatted_value' => $formattedInclPrice)); } else { if ($this->helper('tax')->displayCartPriceExclTax()) { $priceXmlObj->addCustomChild('price', $exclPrice, array('id' => 'regular', 'label' => $this->__('Unit Price'), 'formatted_value' => $formattedExclPrice)); } if ($this->helper('tax')->displayCartPriceInclTax()) { $priceXmlObj->addCustomChild('price', $inclPrice, array('id' => 'regular', 'label' => $this->__('Unit Price'), 'formatted_value' => $formattedInclPrice)); } } /** * Info for paypal MEP if it's enabled */ $appConfig = Mage::helper('xmlconnect')->getApplication()->loadConfiguration()->getRenderConf(); $isMepActive = $appConfig['paypal']['isActive']; $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null); if ($paypalMepIsAvailable && $isMepActive) { $paypalPriceXmlObj = $pricesXmlObj->addCustomChild('prices', null, array('id' => 'paypal')); $paypalPriceXmlObj->addCustomChild('price', $paypalPrice, array('id' => 'regular', 'label' => $this->__('Unit Price'), 'formatted_value' => $quote->getStore()->formatPrice($paypalPrice, false))); $paypalSubtotalPrice = Mage::helper('xmlconnect')->formatPriceForXml($item->getRowTotal()); $paypalPriceXmlObj->addCustomChild('price', $paypalSubtotalPrice, array('id' => 'subtotal', 'label' => $this->__('Subtotal'), 'formatted_value' => $quote->getStore()->formatPrice($paypalSubtotalPrice, false))); } /** * Subtotal */ $subtotalExclTax = $subtotalInclTax = 0; if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()) { if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') && $item->getWeeeTaxAppliedAmount()) { $subtotalExclTax = $item->getRowTotal() + $item->getWeeeTaxAppliedRowAmount() + $item->getWeeeTaxRowDisposition(); } else { $subtotalExclTax = $item->getRowTotal(); } } if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()) { $incl = $this->helper('checkout')->getSubtotalInclTax($item); if (Mage::helper('weee')->typeOfDisplay($item, array(0, 1, 4), 'sales') && $item->getWeeeTaxAppliedAmount()) { $subtotalInclTax = $incl + $item->getWeeeTaxAppliedRowAmount(); } else { $subtotalInclTax = $incl - $item->getWeeeTaxRowDisposition(); } } $subtotalExclTax = Mage::helper('xmlconnect')->formatPriceForXml($subtotalExclTax); $formattedSubtotalExcl = $quote->getStore()->formatPrice($subtotalExclTax, false); $subtotalInclTax = Mage::helper('xmlconnect')->formatPriceForXml($subtotalInclTax); $formattedSubtotalIncl = $quote->getStore()->formatPrice($subtotalInclTax, false); $priceXmlObj = $pricesXmlObj->addCustomChild('prices', null, array('id' => 'subtotal')); if ($this->helper('tax')->displayCartBothPrices()) { $priceXmlObj->addCustomChild('price', $subtotalExclTax, array('id' => 'excluding_tax', 'label' => $this->__('Subtotal Excl. Tax'), 'formatted_value' => $formattedSubtotalExcl)); $priceXmlObj->addCustomChild('price', $subtotalInclTax, array('id' => 'including_tax', 'label' => $this->__('Subtotal Incl. Tax'), 'formatted_value' => $formattedSubtotalIncl)); } else { if ($this->helper('tax')->displayCartPriceExclTax()) { $priceXmlObj->addCustomChild('price', $subtotalExclTax, array('id' => 'regular', 'label' => $this->__('Subtotal'), 'formatted_value' => $formattedSubtotalExcl)); } if ($this->helper('tax')->displayCartPriceInclTax()) { $priceXmlObj->addCustomChild('price', $subtotalInclTax, array('id' => 'regular', 'label' => $this->__('Subtotal'), 'formatted_value' => $formattedSubtotalIncl)); } } /** * Options list */ $options = $renderer->getOptionList(); if ($options) { $itemOptionsXml = $itemXml->addCustomChild('options'); foreach ($options as $_option) { $formattedOptionValue = $renderer->getFormatedOptionValue($_option); $itemOptionsXml->addCustomChild('option', null, array('label' => $xmlObject->xmlAttribute($_option['label']), 'text' => $xmlObject->xmlAttribute($formattedOptionValue['value']))); } } /** * Downloadable products */ $links = $renderer->getLinks(); if ($links) { $itemOptionsXml = $itemXml->addCustomChild('options', null, array('label' => $renderer->getLinksTitle())); foreach ($links as $link) { $itemOptionsXml->addCustomChild('option', null, array('label' => $link->getTitle())); } } /** * Item messages */ $messages = $renderer->getMessages(); if ($messages) { $itemMessagesXml = $itemXml->addCustomChild('messages'); foreach ($messages as $message) { $messageXml = $itemMessagesXml->addCustomChild('option'); $messageXml->addCustomChild('type', $message['type']); $messageXml->addCustomChild('text', $xmlObject->escapeXml($message['text'])); } } } }
/** * Get GeoIp data by user ip address * @param Mage_Sales_Model_Quote $quote * @return array */ public function getAddressGeoIP(Mage_Sales_Model_Quote $quote) { $data = array(); $ipaddress = $_SERVER['REMOTE_ADDR']; $geoip = false; $enabled = Mage::getStoreConfig('onestepcheckout/general/enable_geoip', $quote->getStore()); $database = Mage::getBaseDir('base') . DS . Mage::getStoreConfig('onestepcheckout/general/geoip_database', $quote->getStore()); if (!$enabled || !file_exists($database) || !$ipaddress) { return $data; } try { if (!@(include_once 'Net/GeoIP.php')) { Mage::throwException(Mage::helper('onestepcheckout')->__('Net/GeoIP pear package is not installed or inaccessible')); } else { require_once 'Net/GeoIP.php'; $geoip = Net_GeoIP::getInstance($database); } } catch (Exception $e) { Mage::logException($e); } try { // city database if (is_object($geoip) && method_exists($geoip, 'lookupLocation')) { $location = $geoip->lookupLocation($ipaddress); $data['country_id'] = $location->countryCode; $data['region_id'] = Mage::getModel('directory/region')->loadByCode($location->region, $location->countryCode)->getRegionId(); $data['city'] = $location->city ? utf8_encode($location->city) : ''; $data['postcode'] = $location->postalCode ? $location->postalCode : ''; // country database } else { if (is_object($geoip) && method_exists($geoip, 'lookupCountryCode')) { $data['country_id'] = $geoip->lookupCountryCode($ipaddress); //no database } else { Mage::throwException(Mage::helper('onestepcheckout')->__('Net/GeoIP database %s is not installed properly or is inaccessible', $database)); } } } catch (Exception $e) { Mage::logException($e); } return $data; }
/** * Check whether payment method is applicable to quote * Purposed to allow use in controllers some logic that was implemented in blocks only before * * @param Mage_Sales_Model_Quote $quote * @param int|null $checksBitMask * @return bool */ public function isApplicableToQuote($quote, $checksBitMask) { if ($checksBitMask & self::CHECK_USE_FOR_COUNTRY) { if (!$this->canUseForCountry($quote->getBillingAddress()->getCountry())) { return false; } } if ($checksBitMask & self::CHECK_USE_FOR_CURRENCY) { if (!$this->canUseForCurrency($quote->getStore()->getBaseCurrencyCode())) { return false; } } if ($checksBitMask & self::CHECK_USE_CHECKOUT) { if (!$this->canUseCheckout()) { return false; } } if ($checksBitMask & self::CHECK_USE_FOR_MULTISHIPPING) { if (!$this->canUseForMultishipping()) { return false; } } if ($checksBitMask & self::CHECK_USE_INTERNAL) { if (!$this->canUseInternal()) { return false; } } if ($checksBitMask & self::CHECK_ORDER_TOTAL_MIN_MAX) { $total = $quote->getBaseGrandTotal(); $minTotal = $this->getConfigData('min_order_total'); $maxTotal = $this->getConfigData('max_order_total'); if (!empty($minTotal) && $total < $minTotal || !empty($maxTotal) && $total > $maxTotal) { return false; } } if ($checksBitMask & self::CHECK_RECURRING_PROFILES) { if (!$this->canManageRecurringProfiles() && $quote->hasRecurringItems()) { return false; } } if ($checksBitMask & self::CHECK_ZERO_TOTAL) { $total = $quote->getBaseSubtotal() + $quote->getShippingAddress()->getBaseShippingAmount(); if ($total < 0.0001 && $this->getCode() != 'free' && !($this->canManageRecurringProfiles() && $quote->hasRecurringItems())) { return false; } } return true; }
public function callGetTaxForQuote(Mage_Sales_Model_Quote $quote) { /** @var Aoe_AvaTax_Helper_Soap $helper */ $helper = Mage::helper('Aoe_AvaTax/Soap'); $address = $quote->getShippingAddress(); if ($address->validate() !== true) { $resultArray = array('ResultCode' => 'Skip', 'Messages' => array(), 'TaxLines' => array()); return $resultArray; } $store = $quote->getStore(); $hideDiscountAmount = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $store); $timestamp = $quote->getCreatedAt() ? Varien_Date::toTimestamp($quote->getCreatedAt()) : now(); $date = new Zend_Date($timestamp); $request = new AvaTax\GetTaxRequest(); $request->setCompanyCode($this->limit($helper->getConfig('company_code', $store), 25)); $request->setDocType(AvaTax\DocumentType::$SalesOrder); $request->setCommit(false); $request->setDetailLevel(AvaTax\DetailLevel::$Tax); $request->setDocDate($date->toString('yyyy-MM-dd')); $request->setCustomerCode($helper->getCustomerDocCode($quote->getCustomer()) ?: $helper->getQuoteDocCode($quote)); $request->setCurrencyCode($this->limit($quote->getBaseCurrencyCode(), 3)); $request->setDiscount($hideDiscountAmount ? 0.0 : $store->roundPrice($address->getBaseDiscountAmount())); if ($quote->getCustomerTaxvat()) { $request->setBusinessIdentificationNo($this->limit($quote->getCustomerTaxvat(), 25)); } $request->setOriginAddress($this->getOriginAddress($store)); $request->setDestinationAddress($this->getAddress($address)); $taxLines = array(); $itemPriceIncludesTax = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, $store); foreach ($this->getHelper()->getActionableQuoteAddressItems($address) as $k => $item) { /** @var Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Quote_Address_Item $item */ $itemAmount = $store->roundPrice($itemPriceIncludesTax ? $item->getBaseRowTotalInclTax() : $item->getBaseRowTotal()); //$itemAmount = $store->roundPrice($item->getBaseRowTotal()); $itemAmount -= $store->roundPrice($item->getBaseDiscountAmount()); $taxLine = new AvaTax\Line(); $taxLine->setNo($this->limit($k, 50)); $taxLine->setItemCode($this->limit($item->getSku(), 50)); $taxLine->setQty(round($item->getQty(), 4)); $taxLine->setAmount($itemAmount); $taxLine->setDescription($this->limit($item->getName(), 255)); $taxLine->setTaxCode($this->limit($helper->getProductTaxCode($item->getProduct()), 25)); $taxLine->setDiscounted($item->getBaseDiscountAmount() > 0.0); $taxLine->setTaxIncluded($itemPriceIncludesTax); $taxLine->setRef1($this->limit($helper->getQuoteItemRef1($item, $store), 250)); $taxLine->setRef2($this->limit($helper->getQuoteItemRef2($item, $store), 250)); $taxLines[] = $taxLine; } $shippingPriceIncludesTax = Mage::getStoreConfigFlag(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX, $store); $shippingAmount = $store->roundPrice($shippingPriceIncludesTax ? $address->getBaseShippingInclTax() : $address->getBaseShippingAmount()); //$shippingAmount = $store->roundPrice($address->getBaseShippingAmount()); $shippingAmount -= $store->roundPrice($address->getBaseShippingDiscountAmount()); $taxLine = new AvaTax\Line(); $taxLine->setNo('SHIPPING'); $taxLine->setItemCode('SHIPPING'); $taxLine->setQty(1); $taxLine->setAmount($shippingAmount); $taxLine->setDescription($this->limit("Shipping: " . $address->getShippingMethod(), 255)); $taxLine->setTaxCode($this->limit($helper->getShippingTaxCode($store), 25)); $taxLine->setDiscounted($address->getBaseShippingDiscountAmount() > 0.0); $taxLine->setTaxIncluded($shippingPriceIncludesTax); $taxLine->setRef1($this->limit($address->getShippingMethod(), 25)); $taxLines[] = $taxLine; $request->setLines($taxLines); Mage::dispatchEvent('aoe_avatax_soapapi_get_tax_for_quote_before', array('request' => $request, 'quote' => $quote)); // TODO: Handle giftwrapping return $this->callGetTax($store, $request); }
/** * Fetches the current store's currency or the one from the quote model. * @param Mage_Sales_Model_Quote $quote [also accepts order model] */ public function getCurrencyRate($quote = null) { if ($quote->getStoreToQuoteRate() && $quote) { $c = round($quote->getStoreToQuoteRate(), 4); } else { if ($quote) { $store = $quote->getStore() ? $quote->getStore() : Mage::app()->getStore(); } else { $store = Mage::app()->getStore(); } $baseCurrency = $store->getBaseCurrency(); if ($quote) { $quoteCurrency = $quote->hasForcedCurrency() ? $quote->getForcedCurrency() : $store->getCurrentCurrency(); } else { $quoteCurrency = $store->getCurrentCurrency(); } $c = $baseCurrency->getRate($quoteCurrency); } return $c; }
/** * set the quote information * @param Mage_Sales_Model_Quote $quoteData */ public function __construct(Mage_Sales_Model_Quote $quoteData) { $customerModel = Mage::getModel('customer/customer'); $customerModel->load($quoteData->getCustomerId()); $this->id = $quoteData->getId(); $this->email = $quoteData->getCustomerEmail(); $this->store_name = $quoteData->getStore()->getName(); $created_at = new Zend_Date($quoteData->getCreatedAt(), Zend_Date::ISO_8601); $this->created_date = $created_at->toString(Zend_Date::ISO_8601); if ($quoteData->getShippingAddress()) { $this->delivery_method = $quoteData->getShippingAddress()->getShippingDescription(); $this->delivery_total = $quoteData->getShippingAddress()->getShippingAmount(); } $this->currency = $quoteData->getStoreCurrencyCode(); if ($payment = $quoteData->getPayment()) { $this->payment = $payment->getMethod(); } $this->couponCode = $quoteData->getCouponCode(); /** * custom quote attributes */ $helper = Mage::helper('ddg'); $website = Mage::app()->getStore($quoteData->getStore())->getWebsite(); $customAttributes = $helper->getConfigSelectedCustomQuoteAttributes($website); if ($customAttributes) { $fields = Mage::getResourceModel('ddg_automation/quote')->getQuoteTableDescription(); foreach ($customAttributes as $customAttribute) { if (isset($fields[$customAttribute])) { $field = $fields[$customAttribute]; $value = $this->_getCustomAttributeValue($field, $quoteData); if ($value) { $this->_assignCustom($field, $value); } } } } /** * Billing address. */ if ($quoteData->getBillingAddress()) { $billingData = $quoteData->getBillingAddress()->getData(); $this->billing_address = array('billing_address_1' => $this->_getStreet($billingData['street'], 1), 'billing_address_2' => $this->_getStreet($billingData['street'], 2), 'billing_city' => $billingData['city'], 'billing_region' => $billingData['region'], 'billing_country' => $billingData['country_id'], 'billing_postcode' => $billingData['postcode']); } /** * Shipping address. */ if ($quoteData->getShippingAddress()) { $shippingData = $quoteData->getShippingAddress()->getData(); $this->delivery_address = array('delivery_address_1' => $this->_getStreet($shippingData['street'], 1), 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2), 'delivery_city' => $shippingData['city'], 'delivery_region' => $shippingData['region'], 'delivery_country' => $shippingData['country_id'], 'delivery_postcode' => $shippingData['postcode']); } /** * Quote items. * @var Mage_Sales_Model_Quote_Item $productItem */ foreach ($quoteData->getAllItems() as $productItem) { $product = $productItem->getProduct(); if ($product) { // category names $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name'); foreach ($categoryCollection as $cat) { $categories = array(); $categories[] = $cat->getName(); $this->categories[]['Name'] = substr(implode(', ', $categories), 0, 244); } //get attribute set name $attributeSetName = $this->_getAttributeSetName($product); $this->products[] = array('name' => $productItem->getName(), 'sku' => $productItem->getSku(), 'qty' => (int) number_format($productItem->getData('qty'), 2), 'price' => (double) number_format($productItem->getPrice(), 2, '.', ''), 'attribute-set' => $attributeSetName); } else { // when no product information is available limit to this data $this->products[] = array('name' => $productItem->getName(), 'sku' => $productItem->getSku(), 'qty' => (int) number_format($productItem->getData('qty'), 2), 'price' => (double) number_format($productItem->getPrice(), 2, '.', '')); } } $this->quote_subtotal = (double) number_format($quoteData->getData('subtotal'), 2, '.', ''); $discountAmount = $quoteData->getData('subtotal') - $quoteData->getData('subtotal_with_discount'); $this->discount_amount = (double) number_format($discountAmount, 2, '.', ''); $this->quote_total = (double) number_format($quoteData->getData('grand_total'), 2, '.', ''); return true; }
/** * Format price base on store convert price method * * @param $price float * @return string */ public function formatPrice($price) { return $this->_quote->getStore()->convertPrice($price, true); }
/** * Format price base on store convert price method * * @param float $price * @return string */ protected function _formatPrice($price) { return $this->_quote->getStore()->convertPrice($price, true); }
/** * Get the tax request object for the current quote. * * @param Mage_Sales_Model_Quote $quote * * @return bool|Varien_Object */ protected function _getBuckarooFeeTaxRequest(Mage_Sales_Model_Quote $quote) { $store = $quote->getStore(); $codTaxClass = Mage::getStoreConfig(self::XPATH_BUCKAROO_TAX_CLASS, $store); /** * If no tax class is configured for the Buckaroo fee, there is no tax to be calculated. */ if (!$codTaxClass) { return false; } $taxCalculation = $this->getTaxCalculation(); $customerTaxClass = $quote->getCustomerTaxClassId(); $shippingAddress = $quote->getShippingAddress(); $billingAddress = $quote->getBillingAddress(); $request = $taxCalculation->getRateRequest($shippingAddress, $billingAddress, $customerTaxClass, $store); $request->setProductClassId($codTaxClass); return $request; }
protected function _addTaxAndCurrencyToQuoteItem(Mage_Sales_Model_Quote $quoteToBuild, $reverbOrderObject) { if (property_exists($reverbOrderObject, 'amount_tax')) { $amountTaxObject = $reverbOrderObject->amount_tax; if (is_object($amountTaxObject)) { $tax_amount = $amountTaxObject->amount; if (empty($tax_amount)) { $tax_amount = "0.00"; } } else { $tax_amount = "0.00"; } } else { $tax_amount = "0.00"; } $totalBaseTax = floatval($tax_amount); $quoteItem = $quoteToBuild->getItemsCollection()->getFirstItem(); $quoteItem->setBaseTaxAmount($totalBaseTax); $totalTax = $quoteToBuild->getStore()->convertPrice($totalBaseTax); $quoteItem->setTaxAmount($totalTax); // The check to ensure this field is set has already been made at this point $amountProductObject = $reverbOrderObject->amount_product; $currency_code = $amountProductObject->currency; $currencyHelper = Mage::helper('ReverbSync/orders_creation_currency'); if (!empty($currency_code)) { if (!$currencyHelper->isValidCurrencyCode($currency_code)) { $error_message = $this->__(self::INVALID_CURRENCY_CODE, $currency_code); throw new Exception($error_message); } } else { $currency_code = $currencyHelper->getDefaultCurrencyCode(); } $currencyToForce = Mage::getModel('directory/currency')->load($currency_code); $quoteToBuild->setForcedCurrency($currencyToForce); }
public function getQuoteDocCode(Mage_Sales_Model_Quote $quote) { $prefix = trim($this->getConfig('quote_prefix', $quote->getStore()), self::DOC_CODE_SEPARATOR); $prefix = (empty($prefix) ? 'Q' : $prefix) . self::DOC_CODE_SEPARATOR; if ($quote->getId()) { return $prefix . $quote->getId(); } else { return null; } }
/** * Prepare and set to quote reward balance instance, * set zero subtotal checkout payment if need * * @param Mage_Sales_Model_Quote $quote * @param Varien_Object $payment * @param boolean $useRewardPoints * @return Enterprise_Reward_Model_Observer */ protected function _paymentDataImport($quote, $payment, $useRewardPoints) { if (!$quote || !$quote->getCustomerId()) { return $this; } $quote->setUseRewardPoints((bool) $useRewardPoints); if ($quote->getUseRewardPoints()) { /* @var $reward Enterprise_Reward_Model_Reward */ $reward = Mage::getModel('enterprise_reward/reward')->setCustomer($quote->getCustomer())->setWebsiteId($quote->getStore()->getWebsiteId())->loadByCustomer(); if ($reward->getId()) { $quote->setRewardInstance($reward); if (!$payment->getMethod()) { $payment->setMethod('free'); } } else { $quote->setUseRewardPoints(false); } } return $this; }
/** * * @param Mage_Sales_Model_Quote $quote * * @return float */ public function getBaseValueOfShippableGoods(Mage_Sales_Model_Quote $quote) { $baseTotalPrice = 0.0; $taxConfig = Mage::getSingleton('tax/config'); /* @var $taxConfig Mage_Tax_Model_Config */ if ($quote->getAllItems()) { foreach ($quote->getAllItems() as $item) { /* @var $item Mage_Sales_Model_Quote_Item */ if ($item->getProduct()->isVirtual() || $item->getParentItemId()) { continue; } $baseTotalPrice += $taxConfig->shippingPriceIncludesTax($quote->getStore()) ? $item->getBaseRowTotalInclTax() : $item->getBaseRowTotal(); } } return $baseTotalPrice; }
protected function isShippingIncludesTax() { return Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX, $this->_quote->getStore()) === '1'; }
/** * Prepare and set to quote reward balance instance, * set zero subtotal checkout payment if need * * @param Mage_Sales_Model_Quote $quote * @param Varien_Object $payment * @param boolean $useRewardPoints * @return Enterprise_Reward_Model_Observer */ protected function _paymentDataImport($quote, $payment, $useRewardPoints) { if (!$quote || !$quote->getCustomerId() || $quote->getBaseGrandTotal() + $quote->getBaseRewardCurrencyAmount() <= 0) { return $this; } $quote->setUseRewardPoints((bool) $useRewardPoints); if ($quote->getUseRewardPoints()) { /* @var $reward Enterprise_Reward_Model_Reward */ $reward = Mage::getModel('enterprise_reward/reward')->setCustomer($quote->getCustomer())->setWebsiteId($quote->getStore()->getWebsiteId())->loadByCustomer(); $minPointsBalance = (int) Mage::getStoreConfig(Enterprise_Reward_Model_Reward::XML_PATH_MIN_POINTS_BALANCE, $quote->getStoreId()); if ($reward->getId() && $reward->getPointsBalance() >= $minPointsBalance) { $quote->setRewardInstance($reward); if (!$payment->getMethod()) { $payment->setMethod('free'); } } else { $quote->setUseRewardPoints(false); } } return $this; }
/** * Determines if the object (quote, invoice, or credit memo) should use AvaTax services * * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object * @param Mage_Sales_Model_Quote_Address $shippingAddress * @return bool */ public function isObjectActionable($object, $shippingAddress = null) { $storeId = $object->getStore()->getId(); //is action enabled? $action = $object->getOrder() ? OnePica_AvaTax_Model_Config::ACTION_CALC_SUBMIT : OnePica_AvaTax_Model_Config::ACTION_CALC; if (Mage::getStoreConfig('tax/avatax/action', $storeId) < $action) { return false; } if (!$shippingAddress) { $shippingAddress = $object->getShippingAddress(); } if (!$shippingAddress) { $shippingAddress = $object->getBillingAddress(); } //is the region filtered? if (!$this->isAddressActionable($shippingAddress, $storeId, OnePica_AvaTax_Model_Config::REGIONFILTER_TAX)) { return false; } return true; }
/** * get payment fee before the paymentmethod is selected, based on tax settings * * @param Mage_Sales_Model_Quote $quote * @param string $paymentMethod * @return float|string */ public function getPaymentFeeBeforeSelect(Mage_Sales_Model_Quote $quote, $paymentMethod = '') { $store = $quote->getStore(); $storeId = $store->getId(); $configuredFee = Mage::getStoreConfig(sprintf(self::XPATH_BUCKAROO_FEE, $quote->getPayment()->getMethod()), $storeId); if (strpos($configuredFee, '%') !== false) { return $configuredFee; } $baseFee = $this->_getPaymentFee($quote, $paymentMethod); $fee = $store->convertPrice($baseFee); $includeTax = false; if (!$this->getFeeIsInclTax($storeId)) { $includeTax = true; } $paymentFee = Mage::helper('tax')->getShippingPrice($fee, $includeTax, $quote->getShippingAddress()); return $paymentFee; }
/** * * @param Mage_Sales_Model_Quote $quote * @param Mage_Sales_Model_Quote_Address $address * @param Mage_Sales_Model_Quote_Item $item * @param int $rule_id */ public function getNewDiscounts($quote, $address, $item, $rule_id) { $rule = $this->getRule($rule_id); $store = $item->getQuote()->getStore(); //@nelkaake 17/03/2010 5:01:35 AM if (!$this->_getDiscountValidator()->isValidAppliedRedemption($rule, $item)) { return $this->_emptyDiscount(); } //@nelkaake -a 16/11/10: No rule ID? if (!$rule->getId()) { throw new Exception("No rule ID was detected in Salesrule_Discount_Calculator::getNewDiscounts, which means that there may be some unexpected behaviour that may cause problems."); } //@nelkaake -a 11/03/11: if this item is valid for the rule if (!$rule->getActions()->validate($item)) { return $this->_emptyDiscount(); } $qty = $item->getQty(); //@nelkaake -a 11/03/11: If we have a bundle of 2, and two bundles it's 2x2=4 products total. if ($item->getParentItem()) { $qty *= $item->getParentItem()->getQty(); } //@nelkaake -a 11/03/11: Is there a maximum quantity to discount? If so, use that. TODO check if this is required. $qty = $rule->getDiscountQty() ? min($qty, $rule->getDiscountQty()) : $qty; //@nelkaake -a 11/03/11: Make sure there discount percent is 100% max. $rulePercent = min(100, $rule->getDiscountAmount()); //@nelkaake -a 11/03/11: Initialize the discount amounts $discountAmount = 0; $baseDiscountAmount = 0; //@nelkaake 17/03/2010 5:09:27 AM :Get all items. $all_items = $item->getQuote()->getAllItems(); //@nelkaake -a 11/03/11: How much was the total shipping amount so far? $shipping_amount = $address->getShippingAmount(); $base_shipping_amount = $address->getBaseShippingAmount(); //@nelkaake -a 11/03/11: Initialize the per-item price. $itemPrice = $item->getDiscountCalculationPrice(); if ($itemPrice !== null) { $baseItemPrice = $item->getBaseDiscountCalculationPrice(); } else { $itemPrice = $item->getCalculationPrice(); $baseItemPrice = $item->getBaseCalculationPrice(); } $cartRules = $address->getRewardsCartRules(); $cartRules = empty($cartRules) ? array() : $cartRules; // WDCA CODE BEGIN //@nelkaake -a 11/03/11: Before we begin, refactor all the catalog redemptions so we have the latest row totals. // TODO Is this still needed? switch ($rule->getSimpleAction()) { case 'by_percent': $by_percent_discounter = Mage::getSingleton('rewards/salesrule_discount_action_bypercent'); list($discountAmount, $baseDiscountAmount) = $by_percent_discounter->applyDiscounts($cartRules, $address, $item, $rule, $qty); break; case 'cart_fixed': $cart_fixed_discounter = Mage::getSingleton('rewards/salesrule_discount_action_cartfixed'); list($discountAmount, $baseDiscountAmount) = $cart_fixed_discounter->applyDiscounts($cartRules, $address, $item, $rule, $qty); // WDCA CODE END break; default: throw new Exception("Reached unsupported discount action. This may be due to corrupt data. Unexpected rule action was: " . $rule->getSimpleAction()); break; } //@nelkaake -a 11/03/11: Save cart rule entries. $address->setRewardsCartRules($cartRules); $discountAmount = $quote->getStore()->roundPrice($discountAmount); $baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount); return new Varien_Object(array('discount_amount' => $discountAmount, 'base_discount_amount' => $baseDiscountAmount)); }