protected function _updateQuote(Mage_Sales_Model_Quote $quote) { if (!Mage::helper('recapture')->isEnabled()) { return $this; } if (!$quote->getId()) { return; } //sales_quote_save_before gets called like 5 times on some page loads, we don't want to do 5 updates per page load if (Mage::registry('recapture_has_posted')) { return; } Mage::register('recapture_has_posted', true); $mediaConfig = Mage::getModel('catalog/product_media_config'); $storeId = Mage::app()->getStore(); $transportData = array('first_name' => $quote->getCustomerFirstname(), 'last_name' => $quote->getCustomerLastname(), 'email' => $quote->getCustomerEmail(), 'external_id' => $quote->getId(), 'grand_total' => $quote->getGrandTotal(), 'products' => array(), 'totals' => array()); $cartItems = $quote->getAllVisibleItems(); foreach ($cartItems as $item) { $productModel = $item->getProduct(); $productImage = (string) Mage::helper('catalog/image')->init($productModel, 'thumbnail'); //check configurable first if ($item->getProductType() == 'configurable') { if (Mage::getStoreConfig('checkout/cart/configurable_product_image') == 'itself') { $child = $productModel->getIdBySku($item->getSku()); $image = Mage::getResourceModel('catalog/product')->getAttributeRawValue($child, 'thumbnail', $storeId); if ($image) { $productImage = $mediaConfig->getMediaUrl($image); } } } //then check grouped if (Mage::getStoreConfig('checkout/cart/grouped_product_image') == 'parent') { $options = $productModel->getTypeInstance(true)->getOrderOptions($productModel); if (isset($options['super_product_config']) && $options['super_product_config']['product_type'] == 'grouped') { $parent = $options['super_product_config']['product_id']; $image = Mage::getResourceModel('catalog/product')->getAttributeRawValue($parent, 'thumbnail', $storeId); $productImage = $mediaConfig->getMediaUrl($image); } } $optionsHelper = Mage::helper('catalog/product_configuration'); if ($item->getProductType() == 'configurable') { $visibleOptions = $optionsHelper->getConfigurableOptions($item); } else { $visibleOptions = $optionsHelper->getCustomOptions($item); } $product = array('name' => $item->getName(), 'sku' => $item->getSku(), 'price' => $item->getPrice(), 'qty' => $item->getQty(), 'image' => $productImage, 'options' => $visibleOptions); $transportData['products'][] = $product; } $totals = $quote->getTotals(); foreach ($totals as $total) { //we pass grand total on the top level if ($total->getCode() == 'grand_total') { continue; } $total = array('name' => $total->getTitle(), 'amount' => $total->getValue()); $transportData['totals'][] = $total; } Mage::helper('recapture/transport')->dispatch('cart', $transportData); return $this; }
/** * Set Quote object to Collection * * @param Mage_Sales_Model_Quote $quote * @return Mage_Sales_Model_Resource_Quote_Item_Collection */ public function setQuote($quote) { $this->_quote = $quote; $quoteId = $quote->getId(); if ($quoteId) { $this->addFieldToFilter('quote_id', $quote->getId()); } else { $this->_totalRecords = 0; $this->_setIsLoaded(true); } return $this; }
/** * Retrieve quote model object * * @return Mage_Sales_Model_Quote */ public function getQuote() { if (is_null($this->_quote)) { $this->_quote = Mage::getModel('sales/quote'); if ($this->getStoreId() && $this->getQuoteId()) { $this->_quote->setStoreId($this->getStoreId())->load($this->getQuoteId()); } elseif ($this->getStoreId() && $this->hasCustomerId()) { $this->_quote->setStoreId($this->getStoreId())->setCustomerGroupId(Mage::getStoreConfig(self::XML_PATH_DEFAULT_CREATEACCOUNT_GROUP))->assignCustomer($this->getCustomer())->setIsActive(false)->save(); $this->setQuoteId($this->_quote->getId()); } $this->_quote->setIgnoreOldQty(true); $this->_quote->setIsSuperMode(true); } return $this->_quote; }
/** * Retrieve quote model object * * @return Mage_Sales_Model_Quote */ public function getQuote() { if (is_null($this->_quote)) { $this->_quote = Mage::getModel('sales/quote'); if ($this->getStoreId() && $this->getQuoteId()) { $this->_quote->setStoreId($this->getStoreId())->load($this->getQuoteId()); } elseif ($this->getStoreId()) { $this->_quote->setStoreId($this->getStoreId())->assignCustomer($this->getCustomer())->setIsActive(false)->save(); $this->setQuoteId($this->_quote->getId()); } $this->_quote->setIgnoreOldQty(true); $this->_quote->setIsSuperMode(true); } return $this->_quote; }
protected function setUp() { parent::setUp(); $quote = new Mage_Sales_Model_Quote(); $quote->load('test01', 'reserved_order_id'); Mage::getSingleton('Mage_Checkout_Model_Session')->setQuoteId($quote->getId()); }
/** * Reserve order ID for specified quote and start checkout on PayPal * @return string */ public function start($returnUrl, $cancelUrl) { $this->_quote->collectTotals(); if (!$this->_quote->getGrandTotal() && !$this->_quote->hasNominalItems()) { Mage::throwException(Mage::helper('paypal')->__('PayPal does not support processing orders with zero amount. To complete your purchase, proceed to the standard checkout process.')); } $this->_quote->reserveOrderId()->save(); // prepare API $this->_getApi(); $this->_api->setAmount($this->_quote->getBaseGrandTotal())->setCurrencyCode($this->_quote->getBaseCurrencyCode())->setInvNum($this->_quote->getReservedOrderId())->setReturnUrl($returnUrl)->setCancelUrl($cancelUrl)->setSolutionType($this->_config->solutionType)->setPaymentAction($this->_config->paymentAction); if ($this->_giropayUrls) { list($successUrl, $cancelUrl, $pendingUrl) = $this->_giropayUrls; $this->_api->addData(array('giropay_cancel_url' => $cancelUrl, 'giropay_success_url' => $successUrl, 'giropay_bank_txn_pending_url' => $pendingUrl)); } $this->_setBillingAgreementRequest(); // supress or export shipping address if ($this->_quote->getIsVirtual()) { $this->_api->setSuppressShipping(true); } else { $address = $this->_quote->getShippingAddress(); $isOverriden = 0; if (true === $address->validate()) { $isOverriden = 1; $this->_api->setAddress($address); } $this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_OVERRIDEN, $isOverriden); $this->_quote->getPayment()->save(); } // add line items $paypalCart = Mage::getModel('paypal/cart', array($this->_quote)); $this->_api->setPaypalCart($paypalCart)->setIsLineItemsEnabled($this->_config->lineItemsEnabled); // add shipping options if needed and line items are available if ($this->_config->lineItemsEnabled && $this->_config->transferShippingOptions && $paypalCart->getItems()) { if (!$this->_quote->getIsVirtual() && !$this->_quote->hasNominalItems()) { if ($options = $this->_prepareShippingOptions($address, true)) { $this->_api->setShippingOptionsCallbackUrl(Mage::getUrl('*/*/shippingOptionsCallback', array('quote_id' => $this->_quote->getId())))->setShippingOptions($options); } } } // add recurring payment profiles information if ($profiles = $this->_quote->prepareRecurringPaymentProfiles()) { foreach ($profiles as $profile) { $profile->setMethodCode(Mage_Paypal_Model_Config::METHOD_WPP_EXPRESS); if (!$profile->isValid()) { Mage::throwException($profile->getValidationErrors(true, true)); } } $this->_api->addRecurringPaymentProfiles($profiles); } $this->_config->exportExpressCheckoutStyleSettings($this->_api); // call API and redirect with token $this->_api->callSetExpressCheckout(); $token = $this->_api->getToken(); $this->_redirectUrl = $this->_config->getExpressCheckoutStartUrl($token); $this->_quote->getPayment()->unsAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT); $this->_quote->getPayment()->save(); return $token; }
/** * Convert quote model to order model * * @param Mage_Sales_Model_Quote $quote * @return Mage_Sales_Model_Order */ public function toOrder(Mage_Sales_Model_Quote $quote, $order = null) { if (!$order instanceof Mage_Sales_Model_Order) { $order = Mage::getModel('sales/order'); } /* @var $order Mage_Sales_Model_Order */ $order->setStoreId($quote->getStoreId())->setQuoteId($quote->getId())->setRemoteIp($quote->getRemoteIp())->setCustomerId($quote->getCustomerId())->setCustomerEmail($quote->getCustomerEmail())->setCustomerFirstname($quote->getCustomerFirstname())->setCustomerLastname($quote->getCustomerLastname())->setCustomerGroupId($quote->getCustomerGroupId())->setCustomerTaxClassId($quote->getCustomerTaxClassId())->setCustomerNote($quote->getCustomerNote())->setCustomerNoteNotify($quote->getCustomerNoteNotify())->setCustomerIsGuest($quote->getCustomerIsGuest())->setBaseCurrencyCode($quote->getBaseCurrencyCode())->setStoreCurrencyCode($quote->getStoreCurrencyCode())->setOrderCurrencyCode($quote->getQuoteCurrencyCode())->setStoreToBaseRate($quote->getStoreToBaseRate())->setStoreToOrderRate($quote->getStoreToQuoteRate())->setCouponCode($quote->getCouponCode())->setGiftcertCode($quote->getGiftcertCode())->setIsVirtual($quote->getIsVirtual())->setIsMultiPayment($quote->getIsMultiPayment())->setAppliedRuleIds($quote->getAppliedRuleIds()); Mage::dispatchEvent('sales_convert_quote_to_order', array('order' => $order, 'quote' => $quote)); return $order; }
/** * Convert quote model to order model * * @param Mage_Sales_Model_Quote $quote * @return Mage_Sales_Model_Order */ public function toOrder(Mage_Sales_Model_Quote $quote, $order = null) { if (!$order instanceof Mage_Sales_Model_Order) { $order = Mage::getModel('sales/order'); } /* @var $order Mage_Sales_Model_Order */ $order->setIncrementId($quote->getReservedOrderId())->setStoreId($quote->getStoreId())->setQuoteId($quote->getId())->setCustomer($quote->getCustomer()); Mage::helper('core')->copyFieldset('sales_convert_quote', 'to_order', $quote, $order); Mage::dispatchEvent('sales_convert_quote_to_order', array('order' => $order, 'quote' => $quote)); return $order; }
/** * @magentoDataFixture Mage/Sales/_files/quote.php * @magentoDataFixture Mage/Paypal/_files/quote_payment.php */ public function testReviewAction() { $quote = new Mage_Sales_Model_Quote(); $quote->load('test01', 'reserved_order_id'); Mage::getSingleton('Mage_Checkout_Model_Session')->setQuoteId($quote->getId()); $this->dispatch('paypal/express/review'); $html = $this->getResponse()->getBody(); $this->assertContains('Simple Product', $html); $this->assertContains('Review', $html); $this->assertContains('/paypal/express/placeOrder/', $html); }
/** * @param Mage_Sales_Model_Quote $quote */ protected function reactivateQuote(Mage_Sales_Model_Quote $quote) { if ($quote->getId()) { /* @note: Reset reserved_order_id, Magento up to and including version 1.7 has a bug in Mage_Sales_Model_Resource_Quote::isOrderIncrementIdUsed() * They cast the orderIncrementId to (int), which breaks the checkout/cart for all non-numerical incrementIds * (Causes Integrity Constraint Violation, because orderIncrementId already exists */ $quote->setIsActive(1)->setReservedOrderId(null)->save(); $oSession = Mage::getSingleton('checkout/session'); $oSession->replaceQuote($quote)->unsLastRealOrderId(); } }
/** * Covers app/code/core/Mage/Checkout/Block/Multishipping/Payment/Info.php * and app/code/core/Mage/Checkout/Block/Multishipping/Overview.php * * @magentoDataFixture Mage/Sales/_files/quote.php * @magentoDataFixture Mage/Customer/_files/customer.php */ public function testOverviewAction() { $quote = new Mage_Sales_Model_Quote(); $quote->load('test01', 'reserved_order_id'); Mage::getSingleton('Mage_Checkout_Model_Session')->setQuoteId($quote->getId()); $session = new Mage_Customer_Model_Session(); $session->login('*****@*****.**', 'password'); $this->getRequest()->setPost('payment', array('method' => 'checkmo')); $this->dispatch('checkout/multishipping/overview'); $html = $this->getResponse()->getBody(); $this->assertContains('<p>' . $quote->getPayment()->getMethodInstance()->getTitle() . '</p>', $html); $this->assertContains('<span class="price">$10.00</span>', $html); }
/** * Convert quote model to order model * * @param Mage_Sales_Model_Quote $quote * @return Mage_Sales_Model_Order */ public function toOrder(Mage_Sales_Model_Quote $quote, $order = null) { if (!$order instanceof Mage_Sales_Model_Order) { $order = Mage::getModel('sales/order'); } /* @var $order Mage_Sales_Model_Order */ $order->setIncrementId($quote->getReservedOrderId())->setStoreId($quote->getStoreId())->setQuoteId($quote->getId()); Mage::helper('core')->copyFieldset('sales_convert_quote', 'to_order', $quote, $order); if (!$quote->getCustomerId()) { $order->setCustomerId(null); } // // ->setRemoteIp($quote->getRemoteIp()) // // /** // * Customer data // */ // ->setCustomerId($quote->getCustomerId()) // ->setCustomerEmail($quote->getCustomerEmail()) // ->setCustomerPrefix($quote->getCustomerPrefix()) // ->setCustomerFirstname($quote->getCustomerFirstname()) // ->setCustomerMiddlename($quote->getCustomerMiddlename()) // ->setCustomerLastname($quote->getCustomerLastname()) // ->setCustomerSuffix($quote->getCustomerSuffix()) // ->setCustomerGroupId($quote->getCustomerGroupId()) // ->setCustomerTaxClassId($quote->getCustomerTaxClassId()) // ->setCustomerNote($quote->getCustomerNote()) // ->setCustomerNoteNotify($quote->getCustomerNoteNotify()) // ->setCustomerIsGuest($quote->getCustomerIsGuest()) // ->setCustomerDob($quote->getCustomerDob()) // // /** // * Currency data // */ // ->setBaseCurrencyCode($quote->getBaseCurrencyCode()) // ->setStoreCurrencyCode($quote->getStoreCurrencyCode()) // ->setOrderCurrencyCode($quote->getQuoteCurrencyCode()) // ->setStoreToBaseRate($quote->getStoreToBaseRate()) // ->setStoreToOrderRate($quote->getStoreToQuoteRate()) // // /** // * Another data // */ // ->setCouponCode($quote->getCouponCode()) // ->setGiftcertCode($quote->getGiftcertCode()) // ->setIsVirtual($quote->getIsVirtual()) // ->setIsMultiPayment($quote->getIsMultiPayment()) // ->setAppliedRuleIds($quote->getAppliedRuleIds()); Mage::dispatchEvent('sales_convert_quote_to_order', array('order' => $order, 'quote' => $quote)); return $order; }
/** * Retrieve customer cart quote object model * * @return Mage_Sales_Model_Quote */ public function getCustomerCart() { if (!is_null($this->_cart)) { return $this->_cart; } $this->_cart = Mage::getModel('sales/quote'); if ($this->getSession()->getCustomer()->getId()) { $this->_cart->setStore($this->getSession()->getStore())->loadByCustomer($this->getSession()->getCustomer()->getId()); if (!$this->_cart->getId()) { $this->_cart->assignCustomer($this->getSession()->getCustomer()); $this->_cart->save(); } } return $this->_cart; }
/** * get alias or generate a new one * * alias has length 16 and consists of quote creation date, a separator, * and the quote id to make sure we have the full quote id we shorten * the creation date accordingly * * @param Mage_Sales_Model_Quote $quote * * @return string */ public function getAlias($quote) { $alias = $quote->getPayment()->getAdditionalInformation('alias'); if (0 == strlen($alias)) { /* turn createdAt into format MMDDHHii */ $createdAt = substr(str_replace(array(':', '-', ' '), '', $quote->getCreatedAt()), 4, -2); $quoteId = $quote->getId(); /* shorten createdAt, if we would exceed maximum length */ $maxAliasLength = 16; $separator = '99'; $maxCreatedAtLength = $maxAliasLength - strlen($quoteId) - strlen($separator); $alias = substr($createdAt, 0, $maxCreatedAtLength) . $separator . $quoteId; } if ($this->isAdminSession() && !strpos($alias, 'BE')) { $alias = $alias . 'BE'; } return $alias; }
/** * Place the order when customer returned from paypal * Until this moment all quote data must be valid * * @return array */ public function saveOrder() { $this->_ignoreAddressValidation(); $order = Mage::getModel('sales/service_quote', $this->_quote)->submit(); $this->_quote->save(); /** * Prepare session to success or cancellation page */ $quoteId = $this->_quote->getId(); $this->_getCheckoutSession()->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId)->setLastOrderId($order->getId())->setLastRealOrderId($order->getIncrementId()); if ($order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING) { try { $order->sendNewOrderEmail(); } catch (Exception $e) { Mage::logException($e); } } return array(); }
/** * Sets the customer info if available * * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object * @return $this */ protected function _addCustomer($object) { $format = Mage::getStoreConfig('tax/avatax/cust_code_format', $object->getStoreId()); $customer = Mage::getModel('customer/customer'); if ($object->getCustomerId()) { $customer->load($object->getCustomerId()); $taxClass = Mage::getModel('tax/class')->load($customer->getTaxClassId())->getOpAvataxCode(); $this->_request->setCustomerUsageType($taxClass); } switch ($format) { case OnePica_AvaTax_Model_Source_Customercodeformat::LEGACY: if ($customer->getId()) { $customerCode = $customer->getName() . ' (' . $customer->getId() . ')'; } else { $address = $object->getBillingAddress() ? $object->getBillingAddress() : $object; $customerCode = $address->getFirstname() . ' ' . $address->getLastname() . ' (Guest)'; } break; case OnePica_AvaTax_Model_Source_Customercodeformat::CUST_EMAIL: $customerCode = $object->getCustomerEmail() ? $object->getCustomerEmail() : $customer->getEmail(); break; case OnePica_AvaTax_Model_Source_Customercodeformat::CUST_ID: default: $customerCode = $object->getCustomerId() ? $object->getCustomerId() : 'guest-' . $object->getId(); break; } $this->_request->setCustomerCode($customerCode); return $this; }
/** * Given a model and id load the information from the database into this model * * @param Mage_Sales_Model_Order|Mage_Sales_Model_Quote $oObject * @param Sitewards_DeliveryDate_Model_Quote|Sitewards_DeliveryDate_Model_Order $oModel */ protected function addInformationToObject($oObject, $oModel) { $aData = $oModel->getByObject($oObject->getId()); foreach ($aData as $sKey => $sValue) { $oObject->setData($sKey, $sValue); } }
/** * @param Mage_Sales_Model_Quote $quote */ protected function reactivateQuote(Mage_Sales_Model_Quote $quote) { if ($quote->getId()) { /* @note: Reset reserved_order_id, Magento up to and including version 1.7 has a bug in Mage_Sales_Model_Resource_Quote::isOrderIncrementIdUsed() * They cast the orderIncrementId to (int), which breaks the checkout/cart for all non-numerical incrementIds * (Causes Integrity Constraint Violation, because orderIncrementId already exists */ $quote->setData('reserved_order_id', ''); $quote->setIsActive(true); $quote->save(); } }
public function updateFromQuote(Mage_Sales_Model_Quote $quote) { $id = $this->getContextId(); if (empty($id)) { throw new Exception("Before the context can be updated with a quote, the context must be stored in the database."); } $this->setQuoteId($quote->getId()); $this->setLanguageCode(Mage::app()->getLocale()->getLocaleCode()); $this->setCartUrl(Mage::getUrl('checkout/cart', array('_secure' => true))); $this->setDefaultCheckoutUrl(Mage::getUrl('checkout/onepage', array('_secure' => true))); $this->setInvoiceItems($this->collectInvoiceItems($quote)); $this->setCurrencyCode($this->collectCurrency()); $this->setCustomerId($quote->getCustomerId()); $this->setCustomerEmailAddress($quote->getCustomerEmail()); }
/** * Build XML-based Cart for Checkout by Amazon * * @param Mage_Sales_Model_Quote * @return string */ public function getXmlCart(Mage_Sales_Model_Quote $quote) { $_xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<Order xmlns="http://payments.amazon.com/checkout/2008-11-30/">' . "\n"; if (!$quote->hasItems()) { return false; } $_xml .= " <ClientRequestId>{$quote->getId()}</ClientRequestId>\n"; // Returning parametr # ."<ExpirationDate></ExpirationDate>"; $_xml .= " <Cart>\n" . " <Items>\n"; foreach ($quote->getAllVisibleItems() as $_item) { $_xml .= " <Item>\n" . " <SKU>{$_item->getSku()}/{$_item->getId()}</SKU>\n" . " <MerchantId>{$this->getMerchantId()}</MerchantId>\n" . " <Title>{$_item->getName()}</Title>\n" . " <Price>\n" . " <Amount>{$this->formatAmount($_item->getPrice())}</Amount>\n" . " <CurrencyCode>{$quote->getBaseCurrencyCode()}</CurrencyCode>\n" . " </Price>\n" . " <Quantity>{$_item->getQty()}</Quantity>\n" . " <Weight>\n" . " <Amount>{$this->formatAmount($_item->getWeight())}</Amount>\n" . " <Unit>lb</Unit>\n" . " </Weight>\n"; $_xml .= " </Item>\n"; } $_xml .= " </Items>\n" . " <CartPromotionId>cart-total-discount</CartPromotionId>\n" . " </Cart>\n"; $_xml .= " <IntegratorId>A2ZZYWSJ0WMID8MAGENTO</IntegratorId>\n" . " <IntegratorName>Varien</IntegratorName>\n"; $_xml .= " <OrderCalculationCallbacks>\n" . " <CalculateTaxRates>true</CalculateTaxRates>\n" . " <CalculatePromotions>true</CalculatePromotions>\n" . " <CalculateShippingRates>true</CalculateShippingRates>\n" . " <OrderCallbackEndpoint>" . Mage::getUrl('amazonpayments/cba/callback', array('_secure' => true)) . "</OrderCallbackEndpoint>\n" . " <ProcessOrderOnCallbackFailure>true</ProcessOrderOnCallbackFailure>\n" . " </OrderCalculationCallbacks>\n"; $_xml .= "</Order>\n"; return $_xml; }
/** * updates the additional information from payment, thats needed for backend reOrders * * @param Mage_Sales_Model_Quote $quote * @param array $params */ public function updateAdditionalInformation(Mage_Sales_Model_Quote $quote, $params) { if (!is_null($quote->getId()) && $quote->getPayment() && !is_null($quote->getPayment()->getId())) { $payment = $quote->getPayment(); if (array_key_exists('Alias', $params)) { $payment->setAdditionalInformation('alias', $params['Alias']); } if (array_key_exists('Brand', $params)) { $payment->setAdditionalInformation('CC_BRAND', $params['Brand']); } if (array_key_exists('CN', $params)) { $payment->setAdditionalInformation('CC_CN', $params['CN']); } $quote->setPayment($payment)->save(); } }
/** * recaulcuates the Shipping rates for the order * @param object $order Order object * @param string $params Parameters for shipping */ public function recalculateShippingRates($order, $params = null) { if ($order->getIsVirtual()) { return $this; } $this->_order = $order; $this->_orderWeight = $order->getWeight(); $this->_orderShippingAddress = $order->getShippingAddress(); $item = $this->getAllItems(); if (isset($params['shipping'])) { $params = Zend_Json::decode($params['shipping']); //For temporarily setting items in the order $oldStreet = $this->_orderShippingAddress->getStreet(); $oldCity = $this->_orderShippingAddress->setCity(); $oldRegion = $this->_orderShippingAddress->setRegion(); $oldPostcode = $this->_orderShippingAddress->setPostcode(); $oldCountryId = $this->_orderShippingAddress->setCountry_id(); $this->_orderShippingAddress->setStreet($params['street1']); $this->_orderShippingAddress->setCity($params['city']); $this->_orderShippingAddress->setRegion($params['region']); $this->_orderShippingAddress->setPostcode($params['postcode']); $this->_orderShippingAddress->setCountry_id($params['country_id']); } $request = Mage::getModel('shipping/rate_request'); $request->setAllItems($this->getAllItems()); $request->setDestCountryId($this->_orderShippingAddress->getCountryId()); $request->setDestRegionId($this->_orderShippingAddress->getRegionId()); $request->setDestRegionCode($this->_orderShippingAddress->getRegionCode()); /** * need to call getStreet with -1 * to get data in string instead of array */ $request->setDestStreet($this->_orderShippingAddress->getStreet(-1)); $request->setDestCity($this->_orderShippingAddress->getCity()); $request->setDestPostcode($this->_orderShippingAddress->getPostcode()); $request->setPackageValue($item ? $item[0]->getBaseRowTotal() : $this->getBaseSubtotal()); $packageValueWithDiscount = $item ? $item[0]->getBaseRowTotal() - $item[0]->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount(); $request->setPackageValueWithDiscount($packageValueWithDiscount); $request->setPackageWeight($item[0]->getWeight()); $request->setPackageQty($this->getItemQty()); $packagePhysicalValue = $item ? $item[0]->getBaseRowTotal() : $this->getBaseSubtotal() - $this->getBaseVirtualAmount(); $request->setPackagePhysicalValue($packagePhysicalValue); $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight()); $request->setStoreId(1); $request->setWebsiteId(1); $request->setFreeShipping($this->getFreeShipping()); $request->setBaseCurrency(Mage::app()->getStore()->getBaseCurrency()); $request->setPackageCurrency(Mage::app()->getStore()->getCurrentCurrency()); $request->setLimitCarrier($this->getLimitCarrier()); $request->setBaseSubtotalInclTax($this->getBaseSubtotalInclTax()); $result = Mage::getModel('shipping/shipping')->collectRates($request)->getResult(); if ($result) { /** * Remove any old rates */ $oldRates = Mage::getModel('orderedit/order_address_rate')->getCollection()->addFieldToFilter('order_id', $this->_order->getId()); foreach ($oldRates as $oldRate) { $oldRate->delete(); } /** * Add new rates */ $shippingRates = $result->getAllRates(); foreach ($shippingRates as $shippingRate) { $rate = Mage::getModel('orderedit/order_address_rate')->importShippingRate($shippingRate, $this->_order->getId(), $this->_orderShippingAddress->getId()); $this->addShippingRate($rate); } } if (isset($params['shipping'])) { /** * Set things back to the way they were to be in the order */ $this->_orderShippingAddress->setStreet($oldStreet); $this->_orderShippingAddress->setCity($oldCity); $this->_orderShippingAddress->setRegion($oldRegion); $this->_orderShippingAddress->setPostcode($oldPostcode); $this->_orderShippingAddress->setCountry_id($oldCountryId); } return $this; }
/** * register quote with connector * * @param Mage_Sales_Model_Quote $quote */ protected function _registerQuote(Mage_Sales_Model_Quote $quote) { try { $connectorQuote = Mage::getModel('ddg_automation/quote'); $connectorQuote->setQuoteId($quote->getId())->setCustomerId($quote->getCustomerId())->setStoreId($quote->getStoreId())->save(); } catch (Exception $e) { Mage::logException($e); } }
/** * Create duplicate of quote preserving all data (items, addresses, payment etc.) * * @param Mage_Sales_Model_Quote $quote Original Quote * @param bool $active Create active quote or not * @return Mage_Sales_Model_Quote New created quote */ public function copyQuote(Mage_Sales_Model_Quote $quote, $active = false) { if (!$quote->getId()) { return $quote; } $newQuote = clone $quote; $newQuote->setId(null); $newQuote->setIsActive($active ? 1 : 0); $newQuote->save(); // copy items with their options $newParentItemIds = array(); foreach ($quote->getItemsCollection() as $item) { // save child items later if ($item->getParentItem()) { continue; } $oldItemId = $item->getId(); $newItem = clone $item; $newItem->setQuote($newQuote); $newItem->save(); $newParentItemIds[$oldItemId] = $newItem->getId(); } // save childs with new parent id foreach ($quote->getItemsCollection() as $item) { if (!$item->getParentItem() || !isset($newParentItemIds[$item->getParentItemId()])) { continue; } $newItem = clone $item; $newItem->setQuote($newQuote); $newItem->setParentItemId($newParentItemIds[$item->getParentItemId()]); $newItem->save(); } // copy billing and shipping addresses foreach ($quote->getAddressesCollection() as $address) { $address->setQuote($newQuote); $address->setId(null); $address->save(); } // copy payment info foreach ($quote->getPaymentsCollection() as $payment) { $payment->setQuote($newQuote); $payment->setId(null); $payment->save(); } return $newQuote; }
public function updateActive(Mage_Sales_Model_Quote $quote) { $this->getResource()->updateActive($quote->getId(), $quote->getIsActive()); return $this; }
/** * add shipping to the quote. * * @var $shippingObj Mage_Sales_Model_Quote_Address * @param \Vbw\Procurement\Punchout\Request\Body\Shipping $shipping * @param Mage_Sales_Model_Quote $quoteObj */ public function addQuoteShipping($shipping, $quoteObj) { /** @var $dataHelper Vbw_Punchout_Helper_Data */ $dataHelper = Mage::helper('vbw_punchout'); if ($shipping instanceof \Vbw\Procurement\Punchout\Request\Body\Shipping) { $data = array("country_id" => $shipping->getData('country_id'), "to" => $shipping->getData('shipping_to'), "company" => $shipping->getData('shipping_business'), "street" => $shipping->getData('shipping_street'), "city" => $shipping->getData('shipping_city'), "state" => $shipping->getData('shipping_state'), "postcode" => $shipping->getData('shipping_zip')); $dataHelper->debug('Built : ' . json_encode($data)); if (false == $this->testAddressData($data)) { $dataHelper->debug('incomplete address'); return false; } } elseif (is_array($shipping)) { $data = $shipping; $dataHelper->debug('Sent : ' . json_encode($data)); } else { $dataHelper->debug('Invalid address data'); return false; } $shippingObj = $quoteObj->getShippingAddress(); $shippingObj->setSameAsBilling(0); $shippingObj->setCountryId(isset($data['country_id']) ? $data['country_id'] : 'US'); if (isset($data['to']) && !empty($data['to'])) { $split = explode(" ", $data['to']); if (count($split) >= 2) { $last = array_pop($split); $shippingObj->setLastname($last); } $shippingObj->setFirstname(implode(" ", $split)); } if (isset($data['first_name']) && !empty($data['first_name'])) { $shippingObj->setFirstname($data['first_name']); } if (isset($data['last_name']) && !empty($data['last_name'])) { $shippingObj->setLastname($data['last_name']); } if (isset($data['company']) && !empty($data['company'])) { $shippingObj->setCompany($data['company']); } if (isset($data['street']) && !empty($data['street'])) { $shippingObj->setStreet($data['street']); } if (isset($data['city']) && !empty($data['city'])) { $shippingObj->setCity($data['city']); } // $shippingObj->setRegionId($regionId); if (isset($data['state']) && !empty($data['state'])) { $directory = Mage::helper('vbw_punchout')->getDirectoryRegionByData($data['state'], $shippingObj->getCountryId()); if (!empty($directory)) { $shippingObj->setRegionId($directory->getId()); } } if (isset($data['postcode']) && !empty($data['postcode'])) { $shippingObj->setPostcode($data['postcode']); } $shippingObj->setCollectShippingRates(false); if (is_numeric($quoteObj->getId())) { $shippingObj->setQuoteId($quoteObj->getId()); $shippingObj->save(); $dataHelper->debug('Saving address data : ' . $quoteObj->getId() . " <- " . $shippingObj->getId()); } // $quoteObj->setShippingAddress($shippingObj); return true; /** [address_name] => BigBuyer Headquarters [shipping_business] => [shipping_to] => Jean Picard [shipping_street] => 1565 Pine, MS A.2 [shipping_city] => New York [shipping_state] => NY [shipping_zip] => 01043 [shipping_country] => United States */ }
/** * @param Mage_Sales_Model_Quote $quote * * @return Bronto_Common_Model_Email_Template_Filter */ protected function _filterQuote(Mage_Sales_Model_Quote $quote) { if (!in_array('quote', $this->_filteredObjects)) { $this->setStoreId($quote->getStoreId()); $currencyCode = $quote->getQuoteCurrencyCode(); if (Mage::helper('bronto_common')->displayPriceIncTax($quote->getStoreId())) { $totals = $quote->getTotals(); $this->setField('subtotal', $this->formatPrice($totals['subtotal']->getValue(), $currencyCode)); $this->setField('grandTotal', $this->formatPrice($totals['grand_total']->getValue(), $currencyCode)); } else { $this->setField('subtotal', $this->formatPrice($quote->getSubtotal(), $currencyCode)); $this->setField('grandTotal', $this->formatPrice($quote->getGrandTotal(), $currencyCode)); } $index = 1; foreach ($quote->getAllItems() as $item) { if (!$item->getParentItem()) { $this->_filterQuoteItem($item, $index); $index++; } } // Add Related Content $this->_items = $quote->getAllItems(); $queryParams = $this->getQueryParams(); $queryParams['id'] = urlencode(base64_encode(Mage::helper('core')->encrypt($quote->getId()))); if ($store = $this->getStore()) { $this->setField('quoteURL', $store->getUrl('reminder/load/index', $queryParams)); } else { $this->setField('quoteURL', Mage::getUrl('reminder/load/index', $queryParams)); } // Setup quote items as a template if (class_exists('Bronto_Reminder_Block_Cart_Items', false)) { $layout = Mage::getSingleton('core/layout'); /* @var $items Mage_Sales_Block_Items_Abstract */ $items = $layout->createBlock('bronto/bronto_reminder_cart_items', 'items'); $items->setTemplate('bronto/reminder/items.phtml'); $items->setQuote($item->getQuote()); $this->_respectDesignTheme(); $this->setField("cartItems", $items->toHtml()); } $this->_filteredObjects[] = 'quote'; } return $this; }
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; } }
/** * Declare quote model instance * * @param Mage_Sales_Model_Quote $quote * @return Mage_Sales_Model_Quote_Payment */ public function setQuote(Mage_Sales_Model_Quote $quote) { $this->_quote = $quote; $this->setQuoteId($quote->getId()); return $this; }
/** * @param Mage_Sales_Model_Quote $quote * @return Adyen_Payment_Model_Billing_Agreement */ public function getBillingAgreement(Mage_Sales_Model_Quote $quote) { $billingAgreement = $quote->getPayment()->getMethodInstance()->getBillingAgreement(); if (!$billingAgreement) { Adyen_Subscription_Exception::throwException('Could not find billing agreement for quote ' . $quote->getId()); } Mage::dispatchEvent('adyen_subscription_quote_getbillingagreement', array('billingAgreement' => $billingAgreement, 'quote' => $quote)); return $billingAgreement; }