/** * Return address base on quote shipping address * * @return Mage_Sales_Quote_Address */ public function getAddress() { if (empty($this->_address)) { $this->_address = $this->_quote->getShippingAddress(); } return $this->_address; }
/** * @param Mage_Sales_Model_Quote $quote * @return Mage_Sales_Model_Order * @throws Exception */ public function createNewOrder($quote) { $convert = Mage::getModel('sales/convert_quote'); if ($quote->isVirtual()) { $this->setOrder($convert->addressToOrder($quote->getBillingAddress())); } else { $this->setOrder($convert->addressToOrder($quote->getShippingAddress())); } $this->getOrder()->setBillingAddress($convert->addressToOrderAddress($quote->getBillingAddress())); if ($quote->getBillingAddress()->getCustomerAddress()) { $this->getOrder()->getBillingAddress()->setCustomerAddress($quote->getBillingAddress()->getCustomerAddress()); } if (!$quote->isVirtual()) { $this->getOrder()->setShippingAddress($convert->addressToOrderAddress($quote->getShippingAddress())); if ($quote->getShippingAddress()->getCustomerAddress()) { $this->getOrder()->getShippingAddress()->setCustomerAddress($quote->getShippingAddress()->getCustomerAddress()); } } $this->getOrder()->setPayment($convert->paymentToOrderPayment($quote->getPayment())); $this->getOrder()->getPayment()->setTransactionId($quote->getPayment()->getTransactionId()); foreach ($quote->getAllItems() as $item) { /** @var Mage_Sales_Model_Order_Item $item */ $orderItem = $convert->itemToOrderItem($item); if ($item->getParentItem()) { $orderItem->setParentItem($this->getOrder()->getItemByQuoteItemId($item->getParentItem()->getId())); } $this->getOrder()->addItem($orderItem); } $this->getOrder()->setQuote($quote); $this->getOrder()->setExtOrderId($quote->getPayment()->getTransactionId()); $this->getOrder()->setCanSendNewEmailFlag(false); $this->_initTransaction($quote); return $this->getOrder(); }
/** * Make sure addresses will be saved without validation errors */ private function _ignoreAddressValidation() { $this->_quote->getBillingAddress()->setShouldIgnoreValidation(true); if (!$this->_quote->getIsVirtual()) { $this->_quote->getShippingAddress()->setShouldIgnoreValidation(true); } }
/** * @param Mage_Sales_Model_Quote $quote * * @return array[] */ public function validateQuote(Mage_Sales_Model_Quote $quote) { $errors = []; if (!$quote->isVirtual()) { // Copy data from billing address if ($quote->getShippingAddress()->getSameAsBilling()) { $quote->getShippingAddress()->importCustomerAddress($quote->getBillingAddress()->exportCustomerAddress()); $quote->getShippingAddress()->setSameAsBilling(1); } $addressErrors = $this->validateQuoteAddress($quote->getShippingAddress()); if (!empty($addressErrors)) { $errors['shipping_address'] = $addressErrors; } $method = $quote->getShippingAddress()->getShippingMethod(); $rate = $quote->getShippingAddress()->getShippingRateByCode($method); if (!$method || !$rate) { $errors['shipping_method'] = [$this->__('Please specify a valid shipping method.')]; } } $addressErrors = $this->validateQuoteAddress($quote->getBillingAddress()); if (!empty($addressErrors)) { $errors['billing_address'] = $addressErrors; } try { if (!$quote->getPayment()->getMethod() || !$quote->getPayment()->getMethodInstance()) { $errors['payment'] = [$this->__('Please select a valid payment method.')]; } } catch (Mage_Core_Exception $e) { $errors['payment'] = [$this->__('Please select a valid payment method.')]; } return $errors; }
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 getCurrentRateCode() { $postCode = $this->_quote->getShippingAddress()->getPostcode(); if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) { $sharedpageModel = Mage::getModel('ewayrapid/request_sharedpage', array('quote' => $this->_quote)); return $sharedpageModel->getShippingByCode($postCode); } elseif (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) { $transModel = Mage::getModel('ewayrapid/request_transparent'); return $transModel->getShippingByCode($this->_quote, $postCode); } return false; }
/** * Retrieve payment method and assign additional template values * * @return EbayEnterprise_Paypal_Block_Express_Review */ protected function _beforeToHtml() { $methodInstance = $this->_quote->getPayment()->getMethodInstance(); $this->setPaymentMethodTitle($methodInstance->getTitle()); $this->setShippingRateRequired(true); if ($this->_quote->getIsVirtual()) { $this->setShippingRateRequired(false); } else { // prepare shipping rates $this->_address = $this->_quote->getShippingAddress(); $groups = $this->_address->getGroupedAllShippingRates(); if ($groups && $this->_address) { $this->setShippingRateGroups($groups); // determine current selected code & name foreach ($groups as $rates) { foreach ($rates as $rate) { if ($this->_address->getShippingMethod() == $rate->getCode()) { $this->_currentShippingRate = $rate; break 2; } } } } $canEditShippingAddress = $this->_quote->getMayEditShippingAddress() && $this->_quote->getPayment()->getAdditionalInformation(EbayEnterprise_PayPal_Model_Express_Checkout::PAYMENT_INFO_BUTTON) == 1; // misc shipping parameters $this->setShippingMethodSubmitUrl($this->getUrl("{$this->_paypalActionPrefix}/checkout/saveShippingMethod"))->setCanEditShippingAddress($canEditShippingAddress)->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod()); } $this->setEditUrl($this->getUrl("{$this->_paypalActionPrefix}/checkout/edit"))->setPlaceOrderUrl($this->getUrl("{$this->_paypalActionPrefix}/checkout/placeOrder")); return parent::_beforeToHtml(); }
/** * Retrieve payment method and assign additional template values * * @return Mage_Paypal_Block_Express_Review */ protected function _beforeToHtml() { $methodInstance = $this->_quote->getPayment()->getMethodInstance(); $this->setPaymentMethodTitle($methodInstance->getTitle()); $this->setUpdateOrderSubmitUrl($this->getUrl("{$this->_paypalActionPrefix}/express/updateOrder")); $this->setUpdateShippingMethodsUrl($this->getUrl("{$this->_paypalActionPrefix}/express/updateShippingMethods")); $this->setShippingRateRequired(true); if ($this->_quote->getIsVirtual()) { $this->setShippingRateRequired(false); } else { // prepare shipping rates $this->_address = $this->_quote->getShippingAddress(); $groups = $this->_address->getGroupedAllShippingRates(); if ($groups && $this->_address) { $this->setShippingRateGroups($groups); // determine current selected code & name foreach ($groups as $code => $rates) { foreach ($rates as $rate) { if ($this->_address->getShippingMethod() == $rate->getCode()) { $this->_currentShippingRate = $rate; break 2; } } } } // misc shipping parameters $this->setShippingMethodSubmitUrl($this->getUrl("{$this->_paypalActionPrefix}/express/saveShippingMethod"))->setCanEditShippingAddress($this->_quote->getMayEditShippingAddress())->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod()); } $this->setEditUrl($this->getUrl("{$this->_paypalActionPrefix}/express/edit"))->setPlaceOrderUrl($this->getUrl("{$this->_paypalActionPrefix}/express/placeOrder")); return parent::_beforeToHtml(); }
/** * Retrieve payment method and assign additional template values * * @return Mage_Paypal_Block_Express_Review */ protected function _beforeToHtml() { $methodInstance = $this->_quote->getPayment()->getMethodInstance(); $this->setPaymentMethodTitle($methodInstance->getTitle()); $this->setShippingRateRequired(true); if ($this->_quote->getIsVirtual()) { $this->setShippingRateRequired(false); } else { // prepare shipping rates $this->_address = $this->_quote->getShippingAddress(); $groups = $this->_address->getGroupedAllShippingRates(); if ($groups && $this->_address) { $this->setShippingRateGroups($groups); // determine current selected code & name foreach ($groups as $code => $rates) { foreach ($rates as $rate) { if ($this->_address->getShippingMethod() == $rate->getCode()) { $this->_currentShippingRate = $rate; break 2; } } } } } return parent::_beforeToHtml(); }
/** * collect reward points that customer earned (per each item and address) total * * @param Mage_Sales_Model_Quote_Address $address * @param Mage_Sales_Model_Quote $quote * @return Magestore_RewardPoints_Model_Total_Quote_Point */ public function collect($address, $quote) { if (!Mage::helper('rewardpoints')->isEnable($quote->getStoreId())) { return $this; } // get points that customer can earned by Rates if ($quote->isVirtual()) { $address = $quote->getBillingAddress(); } else { $address = $quote->getShippingAddress(); } $baseGrandTotal = $quote->getBaseGrandTotal(); if (!Mage::getStoreConfigFlag(Magestore_RewardPoints_Helper_Calculation_Earning::XML_PATH_EARNING_BY_SHIPPING, $quote->getStoreId())) { $baseGrandTotal -= $address->getBaseShippingAmount(); } if (!Mage::getStoreConfigFlag(Magestore_RewardPoints_Helper_Calculation_Earning::XML_PATH_EARNING_BY_TAX, $quote->getStoreId())) { $baseGrandTotal -= $address->getBaseTaxAmount(); } $baseGrandTotal = max(0, $baseGrandTotal); $earningPoints = Mage::helper('rewardpoints/calculation_earning')->getRateEarningPoints($baseGrandTotal, $quote->getStoreId()); if ($earningPoints > 0) { $address->setRewardpointsEarn($earningPoints); } Mage::dispatchEvent('rewardpoints_collect_earning_total_points_before', array('address' => $address)); // Update earning point for each items $this->_updateEarningPoints($address); Mage::dispatchEvent('rewardpoints_collect_earning_total_points_after', array('address' => $address)); return $this; }
/** * Validates alias for in quote provided addresses * @param Mage_Sales_Model_Quote $quote * @param Varien_Object $payment * @throws Mage_Core_Exception */ protected function validateAlias($quote, $payment) { $alias = $payment->getAdditionalInformation('alias'); if (0 < strlen(trim($alias)) && is_numeric($payment->getAdditionalInformation('cvc')) && false === Mage::helper('ops/alias')->isAliasValidForAddresses($quote->getCustomerId(), $alias, $quote->getBillingAddress(), $quote->getShippingAddress(), $quote->getStoreId())) { $this->getOnepage()->getCheckout()->setGotoSection('payment'); Mage::throwException($this->getHelper()->__('Invalid payment information provided!')); } }
protected function _placeOrder($checkoutMessage, $orderStatus = 'pending', $notifyCreateOrder = false) { $this->_quote->collectTotals(); $this->_quote->reserveOrderId(); error_reporting(E_ERROR); $service = Mage::getModel('sales/service_quote', $this->_quote); // If file not exist may catch warring error_reporting(E_ALL); if ($service != false && method_exists($service, 'submitAll')) { // Magento version 1.4.1.x // $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $orderObj = $service->getOrder(); } else { // Magento version 1.4.0.x , 1.3.x $convertQuoteObj = Mage::getSingleton('sales/convert_quote'); $orderObj = $convertQuoteObj->addressToOrder($this->_quote->getShippingAddress()); $orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($this->_quote->getBillingAddress())); $orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($this->_quote->getShippingAddress())); $orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($this->_quote->getPayment())); $items = $this->_quote->getShippingAddress()->getAllItems(); foreach ($items as $item) { //@var $item Mage_Sales_Model_Quote_Item $orderItem = $convertQuoteObj->itemToOrderItem($item); if ($item->getParentItem()) { $orderItem->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId())); } $orderObj->addItem($orderItem); } $orderObj->setCanShipPartiallyItem(false); $orderObj->place(); } $orderMessages = ''; $notifyMessages = $this->_processNotifyMessage(); if ($checkoutMessage || $notifyMessages) { $orderMessages .= '<br /><b><u>' . Mage::helper('M2ePro')->__('M2E Pro Notes') . ':</u></b><br /><br />'; if ($checkoutMessage) { $orderMessages .= '<b>' . Mage::helper('M2ePro')->__('Checkout Message From Buyer') . ':</b>'; $orderMessages .= $checkoutMessage . '<br />'; } if ($notifyMessages) { $orderMessages .= $notifyMessages; } } // Adding notification to order $orderObj->addStatusToHistory($orderStatus, $orderMessages, false); $orderObj->save(); // -------------------- Mage::helper('M2ePro/Module')->getConfig()->setGroupValue('/synchronization/orders/', 'current_magento_order_id', $orderObj->getId()); $this->setFatalErrorHandler(); // -------------------- // Send Notification to customer after create order if ($notifyCreateOrder) { // Send new order E-mail only if select such mode $orderObj->sendNewOrderEmail(); } return $orderObj; }
/** * Gets the total discount from $quote * inkl. and excl. tax * Data is returned as a Varien_Object with these data-keys set: * - discount_incl_tax * - discount_excl_tax * * * @param Mage_Sales_Model_Quote $quote * * @return Varien_Object */ public function getDiscountData(Mage_Sales_Model_Quote $quote) { // if catalog-prices includes tax $CatPriceIncl = Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX); /** @var Mage_Sales_Model_Quote_Address $shippingAddress */ $shippingAddress = $quote->getShippingAddress(); $discountIncl = 0; $discountExcl = 0; // find discount on the items foreach ($quote->getItemsCollection() as $item) { /** @var Mage_Sales_Model_Quote_Item $item */ if (!$CatPriceIncl) { $discountExcl += $item->getDiscountAmount(); $discountIncl += $item->getDiscountAmount() * ($item->getTaxPercent() / 100 + 1); } else { $discountExcl += $item->getDiscountAmount() / ($item->getTaxPercent() / 100 + 1); $discountIncl += $item->getDiscountAmount(); } } // find out tax-rate for the shipping if ((double) $shippingAddress->getShippingInclTax() && (double) $shippingAddress->getShippingAmount()) { $shippingTaxRate = $shippingAddress->getShippingInclTax() / $shippingAddress->getShippingAmount(); } else { $shippingTaxRate = 1; } // how much differs between $discountExcl and total discount? // (the difference is due to discount on the shipping) if (!$CatPriceIncl) { $shippingDiscount = abs($quote->getShippingAddress()->getDiscountAmount()) - $discountExcl; } else { $shippingDiscount = abs($quote->getShippingAddress()->getDiscountAmount()) - $discountIncl; } // apply/remove tax to shipping-discount if (!$CatPriceIncl) { $discountIncl += $shippingDiscount * $shippingTaxRate; $discountExcl += $shippingDiscount; } else { $discountIncl += $shippingDiscount; $discountExcl += $shippingDiscount / $shippingTaxRate; } $return = new Varien_Object(); return $return->setDiscountInclTax($discountIncl)->setDiscountExclTax($discountExcl); }
/** * Make sure addresses will be saved without validation errors */ private function _ignoreAddressValidation() { $this->_quote->getBillingAddress()->setShouldIgnoreValidation(true); if (!$this->_quote->getIsVirtual()) { $this->_quote->getShippingAddress()->setShouldIgnoreValidation(true); if (!$this->_config->requireBillingAddress && !$this->_quote->getBillingAddress()->getEmail()) { $this->_quote->getBillingAddress()->setSameAsBilling(1); } } }
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); }
public function save() { $this->_order->setStoreId($this->_getStore()->getId()); $this->_order->createFromQuoteAddress($this->_quote->getShippingAddress()); $this->_order->validate(); $this->_order->setInitialStatus(); $this->_order->save(); $this->_order->setCreatedAt($this->_getRandomDate()); $this->_order->save(); $this->_quote->setIsActive(false); $this->_quote->save(); return $this; }
public function getShippingByCode($postalCode) { $groups = $this->_quote->getShippingAddress()->collectShippingRates()->getGroupedAllShippingRates(); // determine current selected code & name foreach ($groups as $code => $rates) { foreach ($rates as $rate) { if (strtoupper($postalCode) == strtoupper($rate->getCode())) { return $rate; } } } return false; }
/** * get some method dependend form fields * * @param Mage_Sales_Model_Quote $order * @return array */ public function getMethodDependendFormFields($order, $requestParams = null) { $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); $street = str_replace("\n", ' ', $billingAddress->getStreet(-1)); $regexp = '/^([^0-9]*)([0-9].*)$/'; if (!preg_match($regexp, $street, $splittedStreet)) { $splittedStreet[1] = $street; $splittedStreet[2] = ''; } $formFields = parent::getMethodDependendFormFields($order, $requestParams); $gender = Mage::getSingleton('eav/config')->getAttribute('customer', 'gender')->getSource()->getOptionText($order->getCustomerGender()); $formFields['CIVILITY'] = $gender == 'Male' ? 'M' : 'V'; $formFields['OWNERADDRESS'] = trim($splittedStreet[1]); $formFields['ECOM_BILLTO_POSTAL_STREET_NUMBER'] = trim($splittedStreet[2]); $formFields['OWNERZIP'] = $billingAddress->getPostcode(); $formFields['OWNERTOWN'] = $billingAddress->getCity(); $formFields['OWNERCTY'] = $billingAddress->getCountry(); $formFields['OWNERTELNO'] = $billingAddress->getTelephone(); $street = str_replace("\n", ' ', $shippingAddress->getStreet(-1)); if (!preg_match($regexp, $street, $splittedStreet)) { $splittedStreet[1] = $street; $splittedStreet[2] = ''; } $formFields['ECOM_SHIPTO_POSTAL_NAME_PREFIX'] = $shippingAddress->getPrefix(); $formFields['ECOM_SHIPTO_POSTAL_NAME_FIRST'] = $shippingAddress->getFirstname(); $formFields['ECOM_SHIPTO_POSTAL_NAME_LAST'] = $shippingAddress->getLastname(); $formFields['ECOM_SHIPTO_POSTAL_STREET_LINE1'] = trim($splittedStreet[1]); $formFields['ECOM_SHIPTO_POSTAL_STREET_NUMBER'] = trim($splittedStreet[2]); $formFields['ECOM_SHIPTO_POSTAL_POSTALCODE'] = $shippingAddress->getPostcode(); $formFields['ECOM_SHIPTO_POSTAL_CITY'] = $shippingAddress->getCity(); $formFields['ECOM_SHIPTO_POSTAL_COUNTRYCODE'] = $shippingAddress->getCountry(); // copy some already known values $formFields['ECOM_SHIPTO_ONLINE_EMAIL'] = $order->getCustomerEmail(); if (is_array($requestParams)) { if (array_key_exists('OWNERADDRESS', $requestParams)) { $formFields['OWNERADDRESS'] = $requestParams['OWNERADDRESS']; } if (array_key_exists('ECOM_BILLTO_POSTAL_STREET_NUMBER', $requestParams)) { $formFields['ECOM_BILLTO_POSTAL_STREET_NUMBER'] = $requestParams['ECOM_BILLTO_POSTAL_STREET_NUMBER']; } if (array_key_exists('ECOM_SHIPTO_POSTAL_STREET_LINE1', $requestParams)) { $formFields['ECOM_SHIPTO_POSTAL_STREET_LINE1'] = $requestParams['ECOM_SHIPTO_POSTAL_STREET_LINE1']; } if (array_key_exists('ECOM_SHIPTO_POSTAL_STREET_NUMBER', $requestParams)) { $formFields['ECOM_SHIPTO_POSTAL_STREET_NUMBER'] = $requestParams['ECOM_SHIPTO_POSTAL_STREET_NUMBER']; } } return $formFields; }
/** * Add custom methods * * @param Mage_Sales_Model_Quote $quote */ public function addCustomMethods(Mage_Sales_Model_Quote $quote) { /** @var MatheusGontijo_EasyShippingRules_Model_Custommethod $methods */ $methods = Mage::getModel('easyshippingrules/custommethod')->getCollection()->prepareAvailableMethods(); $address = $quote->getShippingAddress(); if (!$this->_isDefaultRuleValid($address)) { return; } foreach ($methods as $method) { foreach ($method->getRules() as $rule) { if ($rule->validate($address)) { $this->_rates[] = $this->createRate($method, $rule); } } } }
/** * Prepare quote customer address information and set the customer on the quote * * @return self */ protected function _prepareCustomerQuote() { $shipping = $this->_quote->isVirtual() ? null : $this->_quote->getShippingAddress(); $customer = $this->_getCustomerSession()->getCustomer(); $customerBilling = $this->_prepareCustomerBilling($customer); if ($shipping) { $customerShipping = $this->_prepareCustomerShipping($customer, $shipping); if ($customerBilling && !$customer->getDefaultShipping() && $shipping->getSameAsBilling()) { $customerBilling->setIsDefaultShipping(true); } elseif (isset($customerShipping) && !$customer->getDefaultShipping()) { $customerShipping->setIsDefaultShipping(true); } } $this->_quote->setCustomer($customer); return $this; }
private function initializeAddresses() { $billingAddress = $this->quote->getBillingAddress(); $billingAddress->addData($this->proxyOrder->getBillingAddressData()); $billingAddress->implodeStreetAddress(); $billingAddress->setLimitCarrier('m2eproshipping'); $billingAddress->setShippingMethod('m2eproshipping_m2eproshipping'); $billingAddress->setCollectShippingRates(true); $billingAddress->setShouldIgnoreValidation($this->proxyOrder->shouldIgnoreBillingAddressValidation()); // --------------------------------------- $shippingAddress = $this->quote->getShippingAddress(); $shippingAddress->setSameAsBilling(0); // maybe just set same as billing? $shippingAddress->addData($this->proxyOrder->getAddressData()); $shippingAddress->implodeStreetAddress(); $shippingAddress->setLimitCarrier('m2eproshipping'); $shippingAddress->setShippingMethod('m2eproshipping_m2eproshipping'); $shippingAddress->setCollectShippingRates(true); // --------------------------------------- }
/** * Convert the resource model collection to an array * * @param Mage_Sales_Model_Quote $quote * * @return array */ public function prepareCollection(Mage_Sales_Model_Quote $quote) { if ($quote->isVirtual()) { return []; } // Store current state $actionType = $this->getActionType(); $operation = $this->getOperation(); // Change state $this->setActionType(self::ACTION_TYPE_COLLECTION); $this->setOperation(self::OPERATION_RETRIEVE); $data = []; // Load and prep shipping address $address = $quote->getShippingAddress(); $address->setCollectShippingRates(true); $address->collectShippingRates(); $address->save(); // Load rates /** @var Mage_Sales_Model_Resource_Quote_Address_Rate_Collection $rateCollection */ $rateCollection = $address->getShippingRatesCollection(); $rates = []; foreach ($rateCollection as $rate) { /** @var Mage_Sales_Model_Quote_Address_Rate $rate */ if (!$rate->isDeleted() && $rate->getCarrierInstance()) { $rates[] = $rate; } } uasort($rates, [$this, 'sortRates']); // Get filter $filter = $this->getFilter(); // Prepare rates foreach ($rates as $rate) { /** @var Mage_Sales_Model_Quote_Address_Rate $rate */ $data[] = $this->prepareRate($rate, $filter); } // Restore old state $this->setActionType($actionType); $this->setOperation($operation); // Return prepared outbound data return $data; }
/** * Changed By Adam 06/11/2014: Fix bug hidden tax * pre collect total for quote/address and return quote total * * @param Mage_Sales_Model_Quote $quote * @param null|Mage_Sales_Model_Quote_Address $address * @return float */ public function getQuoteBaseTotal($quote, $address = null) { $cacheKey = 'quote_base_total'; if ($this->hasCache($cacheKey)) { return $this->getCache($cacheKey); } if (is_null($address)) { if ($quote->isVirtual()) { $address = $quote->getBillingAddress(); } else { $address = $quote->getShippingAddress(); } } $baseTotal = 0; foreach ($address->getAllItems() as $item) { if ($item->getParentItemId()) { continue; } if ($item->getHasChildren() && $item->isChildrenCalculated()) { foreach ($item->getChildren() as $child) { $baseTotal += $item->getQty() * ($child->getQty() * $this->_getItemBasePrice($child)) - $child->getBaseDiscountAmount() - $child->getMagestoreBaseDiscount(); } } elseif ($item->getProduct()) { $baseTotal += $item->getQty() * $this->_getItemBasePrice($item) - $item->getBaseDiscountAmount() - $item->getMagestoreBaseDiscount(); } } // if (Mage::getStoreConfig(self::XML_PATH_SPEND_FOR_SHIPPING, $quote->getStoreId())) { // $shippingAmount = $address->getShippingAmountForDiscount(); // if ($shippingAmount !== null) { // $baseShippingAmount = $address->getBaseShippingAmountForDiscount(); // } else { // $baseShippingAmount = $address->getBaseShippingAmount(); // } // $baseTotal += $baseShippingAmount - $address->getBaseShippingDiscountAmount() - $address->getMagestoreBaseDiscountForShipping(); // } $this->saveCache($cacheKey, $baseTotal); return $baseTotal; }
/** * Check whether payment method can be used * * TODO: payment method instance is not supposed to know about quote * * @param Mage_Sales_Model_Quote|null $quote * * @return bool */ public function isAvailable($quote = null) { $checkResult = new StdClass(); $isActive = (bool) (int) $this->getConfigData('active', $quote ? $quote->getStoreId() : null); $shippingMethodRaw = $quote->getShippingAddress()->getShippingMethod(); $product = $this->_getHelper()->getDPDServiceCode($shippingMethodRaw); if (!$isActive || !$quote || !$this->_getHelper()->isShippingMethodDpd($shippingMethodRaw) || !in_array($product, explode(',', $this->getConfigData('specificproducto', $quote->getStoreId()))) || is_null($this->getSurchage())) { $isActive = false; } $checkResult->isAvailable = $isActive; $checkResult->isDeniedInConfig = !$isActive; // for future use in observers Mage::dispatchEvent('payment_method_is_active', array('result' => $checkResult, 'method_instance' => $this, 'quote' => $quote)); // disable method if it cannot implement recurring profiles management and there are recurring items in quote if ($checkResult->isAvailable) { $implementsRecurring = $this->canManageRecurringProfiles(); // the $quote->hasRecurringItems() causes big performance impact, thus it has to be called last if ($quote && !$implementsRecurring && $quote->hasRecurringItems()) { $checkResult->isAvailable = false; } } return $checkResult->isAvailable; }
/** * Shipping method save action * * @return void */ public function saveShippingMethodAction() { if (!$this->getRequest()->isPost()) { $this->_message($this->__('Specified invalid data.'), self::MESSAGE_STATUS_ERROR); return; } try { $this->_initCheckout(); $data = $this->getRequest()->getPost('shipping_method', ''); $this->_quote->getShippingAddress()->setShippingMethod($data)->setCollectShippingRates(true)->save(); $result = $this->_checkout->saveShippingMethod($data); if (!isset($result['error'])) { /** @var $message Mage_XmlConnect_Model_Simplexml_Element */ $message = Mage::getModel('xmlconnect/simplexml_element', '<message></message>'); $message->addChild('status', self::MESSAGE_STATUS_SUCCESS); $message->addChild('text', $this->__('Shipping method has been set.')); if ($this->_getQuote()->isVirtual()) { $quoteAddress = $this->_getQuote()->getBillingAddress(); } else { $quoteAddress = $this->_getQuote()->getShippingAddress(); } $taxAmount = Mage::helper('core')->currency($quoteAddress->getBaseTaxAmount(), false, false); $message->addChild('tax_amount', Mage::helper('xmlconnect')->formatPriceForXml($taxAmount)); $this->getResponse()->setBody($message->asNiceXml()); } else { if (!is_array($result['message'])) { $result['message'] = array($result['message']); } $this->_message(implode('. ', $result['message']), self::MESSAGE_STATUS_ERROR); } } catch (Mage_Core_Exception $e) { $this->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR); } catch (Exception $e) { $this->_message($this->__('Unable to save shipping method.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); } }
/** * save shipping total amount to quote * send new shipping total amount to eway * * @throws Exception * @throws Mage_Core_Exception */ public function saveInfoShippingAction() { $this->_initCheckout(); $formActionURL = Mage::getSingleton('core/session')->getData('FormActionURL'); if ($formActionURL) { Mage::getSingleton('core/session')->unsetData('FormActionURL'); } $shippingMethod = $this->getRequest()->getParam('shipping_method'); if ($shippingMethod) { //Save to quote $this->_quote->getShippingAddress()->setShippingMethod($shippingMethod)->save(); //Get price $quote = $this->_getQuote(); $cRate = $this->_checkout->getShippingByCode($shippingMethod); if ($cRate) { echo json_encode(array('form_action' => $formActionURL, 'input_post' => '<input type="hidden" name="EWAY_NEWSHIPPINGTOTAL" value="' . round($cRate->getPrice() * 100) . '" />')); } else { Mage::throwException($this->__('Method not found.')); } } else { Mage::throwException($this->__('Method not support.')); } die; }
/** * Returns shiping or billing address of given quote * regarding configuration * * @param Mage_Sales_Model_Quote $quote */ public function getAddress($quote) { switch ($this->config->get('solvency/address_type')) { case Netresearch_Scoring_Model_System_Config_Source_Address_Type::BILLING: return $quote->getBillingAddress(); default: return $quote->getShippingAddress(); } }
/** * 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 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; }
public function setAliasToActiveAfterUserRegisters(Mage_Sales_Model_Order $order, Mage_Sales_Model_Quote $quote) { if (true === $quote->getPayment()->getAdditionalInformation('userIsRegistering')) { $customerId = $order->getCustomerId(); $billingAddressHash = $this->generateAddressHash($quote->getBillingAddress()); $shippingAddressHash = $this->generateAddressHash($quote->getShippingAddress()); $aliasId = $quote->getPayment()->getAdditionalInformation('opsAliasId'); if (is_numeric($aliasId) && 0 < $aliasId) { $alias = Mage::getModel('ops/alias')->getCollection()->addFieldToFilter('alias', $quote->getPayment()->getAdditionalInformation('alias'))->addFieldToFilter('billing_address_hash', $billingAddressHash)->addFieldToFilter('shipping_address_hash', $shippingAddressHash)->addFieldToFilter('store_id', array('eq' => $quote->getStoreId()))->getFirstItem(); if ($alias->getState() === Netresearch_OPS_Model_Alias_State::PENDING) { $alias->setState(Netresearch_OPS_Model_Alias_State::ACTIVE); $alias->setCustomerId($customerId); $alias->save(); } } } }