/**
  * Call Transaction API (Authorized & Capture at the same time)
  *
  * @param Eway_Rapid31_Model_Response $response
  * @return Eway_Rapid31_Model_Response
  */
 public function doTransaction(Eway_Rapid31_Model_Response $response)
 {
     $this->unsetData();
     $this->_buildRequest();
     $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
     $items = $this->_quote->getAllVisibleItems();
     $lineItems = array();
     foreach ($items as $item) {
         /* @var Mage_Sales_Model_Order_Item $item */
         $lineItem = Mage::getModel('ewayrapid/field_lineItem');
         $lineItem->setSKU($item->getSku());
         $lineItem->setDescription(substr($item->getName(), 0, 26));
         $lineItem->setQuantity($item->getQty());
         $lineItem->setUnitCost(round($item->getBasePrice() * 100));
         $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
         $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
         $lineItems[] = $lineItem;
     }
     $this->setItems($lineItems);
     $this->setItems(false);
     // add Payment
     $amount = round($this->_quote->getBaseGrandTotal() * 100);
     $paymentParam = Mage::getModel('ewayrapid/field_payment');
     $paymentParam->setTotalAmount($amount);
     $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
     $this->setPayment($paymentParam);
     $customerParam = $this->getCustomer();
     $customerParam->setTokenCustomerID($response->getTokenCustomerID());
     $this->setCustomer($customerParam);
     $response = $this->_doRapidAPI('Transaction');
     return $response;
 }
 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;
 }
Beispiel #3
0
 /**
  * Get rid of all nominal items
  */
 protected function _deleteNominalItems()
 {
     foreach ($this->_quote->getAllVisibleItems() as $item) {
         if ($item->isNominal()) {
             $item->isDeleted(true);
         }
     }
 }
 /**
  * Get sku and qty data for a given quote
  * @param  Mage_Sales_Model_Quote $quote Quote object to extract data from
  * @return array                         Array of 'sku' => qty
  */
 protected function _extractQuoteSkuData(Mage_Sales_Model_Quote $quote)
 {
     $skuData = [];
     // use getAllVisibleItems to prevent dupes due to parent config + child used both being included
     foreach ($quote->getAllVisibleItems() as $item) {
         // before item's have been saved, getAllVisible items won't properly
         // filter child items...this extra check fixes it
         if ($item->getParentItem()) {
             continue;
         }
         $skuData[$item->getSku()] = ['item_id' => $item->getId(), 'managed' => Mage::helper('eb2ccore/quote_item')->isItemInventoried($item), 'virtual' => $item->getIsVirtual(), 'qty' => $item->getQty()];
     }
     return $skuData;
 }
 /**
  * Compare Magento quote and shopping cart details from the request
  *
  * @return bool
  */
 protected function _validateQuote()
 {
     $quoteItems = $this->_quote->getAllVisibleItems();
     $quoteItemsArray = array();
     $quoteItemsSku = array();
     /** @var $xmlItems SimpleXMLElement */
     $xmlItems = $this->_request->{$this->_orderNode}->items;
     $xmlItemsArray = array();
     $xmlItemsSku = array();
     foreach ($quoteItems as $item) {
         /** @var $item Mage_Sales_Model_Quote_Item */
         $quoteItemsArray[(string) $item->getSku()] = $item;
         $quoteItemsSku[] = (string) $item->getSku();
     }
     foreach ($xmlItems->children() as $item) {
         /** @var $item SimpleXMLElement */
         $xmlItemsArray[(string) $item->sku] = $item;
         $xmlItemsSku[] = (string) $item->sku;
     }
     $this->_debugData['quoteItemsSku'] = implode(', ', $quoteItemsSku);
     $this->_debugData['xmlItemsSku'] = implode(', ', $xmlItemsSku);
     // Validation of the shopping cart
     if (count($quoteItemsArray) != count($xmlItemsArray)) {
         $this->_debugData['reason'] = 'Quote validation failed: Qty of items';
         return false;
     }
     foreach ($quoteItemsArray as $sku => $item) {
         if (!isset($xmlItemsArray[$sku])) {
             $this->_debugData['reason'] = 'Quote validation failed: SKU doesn\'t exist';
             return false;
         }
         $xmlItem = $xmlItemsArray[$sku];
         $checkoutHelper = Mage::helper('checkout');
         if ($item->getQty() != (int) $xmlItem->qty || $checkoutHelper->getPriceInclTax($item) != Mage::app()->getStore()->roundPrice((double) $xmlItem->price)) {
             $this->_debugData['reason'] = 'Quote validation failed: Items don\'t match';
             return false;
         }
     }
     return true;
 }
 /**
  * Get Shopping Cart XML
  * @param Mage_Sales_Model_Quote $quote
  * @return string
  */
 public function getShoppingCartXML($quote)
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     $ShoppingCart = $dom->createElement('ShoppingCart');
     $dom->appendChild($ShoppingCart);
     $ShoppingCart->appendChild($dom->createElement('CurrencyCode', $quote->getQuoteCurrencyCode()));
     $ShoppingCart->appendChild($dom->createElement('Subtotal', (int) (100 * $quote->getGrandTotal())));
     // Add Order Lines
     $items = $quote->getAllVisibleItems();
     /** @var $item Mage_Sales_Model_Quote_Item */
     foreach ($items as $item) {
         $product = $item->getProduct();
         $ShoppingCartItem = $dom->createElement('ShoppingCartItem');
         $ShoppingCartItem->appendChild($dom->createElement('Description', $item->getName()));
         $ShoppingCartItem->appendChild($dom->createElement('Quantity', (int) $item->getQty()));
         $ShoppingCartItem->appendChild($dom->createElement('Value', (int) bcmul($product->getFinalPrice(), 100)));
         $ShoppingCartItem->appendChild($dom->createElement('ImageURL', $product->getThumbnailUrl()));
         // NOTE: getThumbnailUrl is DEPRECATED!
         $ShoppingCart->appendChild($ShoppingCartItem);
     }
     return str_replace("\n", '', $dom->saveXML());
 }
 /**
  * @param array $data
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order $object
  */
 private function _fillCartInformation(&$data, $object)
 {
     $productIids = array();
     $productQtys = array();
     $productStyleIds = array();
     /** @var Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Item $item */
     foreach ($object->getAllVisibleItems() as $item) {
         $productIids[] = $item->getProduct()->getIid();
         $productQtys[] = is_null($item->getQtyOrdered()) ? (int) $item->getQty() : (int) $item->getQtyOrdered();
         $productStyleIds[] = $item->getProduct()->getNumber() . '-' . $item->getProduct()->getColorCode();
     }
     $data['productStyleId'] = implode(',', $productStyleIds);
     $data['cartProductIds'] = implode(',', $productIids);
     $data['cartProductQtys'] = implode(',', $productQtys);
     $data['cartTotalNetto'] = round($object->getBaseSubtotal(), 2);
     $data['cartTotalBrutto'] = round($object->getBaseGrandTotal(), 2);
     $data['customerId'] = (int) $object->getCustomerId();
     // For zanox tracking
     if (array_key_exists('zanpid', $_COOKIE) && $_COOKIE['zanpid'] != '') {
         $data['zanpid'] = $_COOKIE['zanpid'];
     }
 }
 /**
  * Return false if we have an item that's not backorderable or not out of stock
  * otherwise return true that all items are backorderable and out of stock.
  *
  * @param  Mage_Sales_Model_Quote
  * @return bool
  */
 protected function isAllItemBackorderableAndOutOfStock(Mage_Sales_Model_Quote $quote)
 {
     /** @var Mage_Sales_Model_Quote_Item[] $items */
     $items = $quote->getAllVisibleItems();
     foreach ($items as $item) {
         if ($this->quantityService->canSendInventoryAllocation($item)) {
             return false;
         }
     }
     return true;
 }
Beispiel #9
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return bool
  */
 protected function isSingleQuote($quote)
 {
     foreach ($quote->getAllVisibleItems() as $item) {
         if (($product = $item->getProduct()) && $product->getTypeId() === 'subscription') {
             return false;
         }
     }
     return true;
 }
Beispiel #10
0
 /**
  * Convert the resource model collection to an array
  *
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return array
  */
 public function prepareCollection(Mage_Sales_Model_Quote $quote)
 {
     // Store current state
     $actionType = $this->getActionType();
     $operation = $this->getOperation();
     // Change state
     $this->setActionType(self::ACTION_TYPE_COLLECTION);
     $this->setOperation(self::OPERATION_RETRIEVE);
     $data = [];
     $filter = $this->getFilter();
     foreach ($quote->getAllVisibleItems() as $item) {
         /** @var Mage_Sales_Model_Quote_Item $item */
         // Add data to result
         $data[$item->getId()] = $this->prepareItem($item, $filter);
     }
     // Restore old state
     $this->setActionType($actionType);
     $this->setOperation($operation);
     // This collection should always be a key/value hash and never a simple array
     $data = new ArrayObject($data);
     // Return prepared outbound data
     return $data;
 }
 /**
  * Handle admin out of stock Exception thrown from ROM Inventory Service.
  *
  * @param  EbayEnterprise_Inventory_Exception_Quantity_Unavailable_Exception
  * @param  Mage_Sales_Model_Quote
  * @return self
  */
 protected function handleAdminOrderException(EbayEnterprise_Inventory_Exception_Quantity_Unavailable_Exception $e, Mage_Sales_Model_Quote $quote)
 {
     $this->getAdminQuoteSession()->addError($e->getMessage());
     foreach ($quote->getAllVisibleItems() as $quoteItem) {
         if (!$this->quantityService->isItemAvailable($quoteItem)) {
             $quote->deleteItem($quoteItem);
         }
     }
     return $this;
 }
 public function updateQuoteTotalQty(Mage_Sales_Model_Quote $quote)
 {
     $quote->setItemsCount(0);
     $quote->setItemsQty(0);
     $quote->setVirtualItemsQty(0);
     foreach ($quote->getAllVisibleItems() as $item) {
         if ($item->getParentItem()) {
             continue;
         }
         $children = $item->getChildren();
         if ($children && $item->isShipSeparately()) {
             foreach ($children as $child) {
                 if ($child->getProduct()->getIsVirtual()) {
                     $quote->setVirtualItemsQty($quote->getVirtualItemsQty() + $child->getQty() * $item->getQty());
                 }
             }
         }
         if ($item->getProduct()->getIsVirtual()) {
             $quote->setVirtualItemsQty($quote->getVirtualItemsQty() + $item->getQty());
         }
         $quote->setItemsCount($quote->getItemsCount() + 1);
         $quote->setItemsQty((double) $quote->getItemsQty() + $item->getQty());
     }
 }
 /**
  * Return false if we have an item that's not backorderable or not out of stock
  * otherwise return true that all items are backorderable and out of stock.
  *
  * @param  Mage_Sales_Model_Quote
  * @return bool
  */
 protected function isAllItemBackorderableAndOutOfStock(Mage_Sales_Model_Quote $quote)
 {
     /** @var Mage_Sales_Model_Quote_Item[] $items */
     $items = $quote->getAllVisibleItems();
     foreach ($items as $item) {
         /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */
         $stockItem = $item->getProduct()->getStockItem();
         if ($this->isAllocatable($stockItem)) {
             return false;
         }
     }
     return true;
 }
Beispiel #14
0
 /**
  * add all visible items from a quote as tracked ecommerce items
  * 
  * @param Fooman_Jirafe_Model_JirafeTracker $piwikTracker
  * @param Mage_Sales_Model_Quote $quote 
  */
 protected function _addEcommerceItems($piwikTracker, $quote)
 {
     foreach ($quote->getAllVisibleItems() as $item) {
         if ($item->getName()) {
             //we only want to track the main configurable item
             //but not the subitem
             if ($item->getParentItem()) {
                 if ($item->getParentItem()->getProductType() == 'configurable') {
                     continue;
                 }
             }
             $itemPrice = $item->getBasePrice();
             // This is inconsistent behaviour from Magento
             // base_price should be item price in base currency
             // TODO: add test so we don't get caught out when this is fixed in a future release
             if (!$itemPrice || $itemPrice < 1.0E-5) {
                 $itemPrice = $item->getPrice();
             }
             $piwikTracker->addEcommerceItem($item->getProduct()->getData('sku'), $item->getName(), Mage::helper('foomanjirafe')->getCategory($item->getProduct()), $itemPrice, $item->getQty());
         }
     }
 }
Beispiel #15
0
 /**
  * Returns all items from quote and validates
  * them by quantity and addresses.
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param ShopgateCart           $cart
  *
  * @return array
  */
 public function getItems($quote, ShopgateCart $cart)
 {
     $validator = Mage::getModel('shopgate/shopgate_cart_validation_stock');
     $items = array();
     $quote->collectTotals();
     /** @var Mage_Sales_Model_Quote_Item $_item */
     foreach ($quote->getAllVisibleItems() as $_item) {
         /** @var Mage_Catalog_Model_Product $_item */
         $items[] = $validator->validateStock($_item, $_item->getPriceInclTax(), $_item->getPrice());
     }
     foreach (Mage::helper('shopgate')->fetchMissingQuoteItems($cart, $quote) as $_item) {
         $item = Mage::helper('shopgate')->generateShopgateCartItem($_item->getProduct());
         $catchedErrors = $quote->getShopgateError();
         $sgError = ShopgateLibraryException::CART_ITEM_OUT_OF_STOCK;
         if ($catchedErrors) {
             if (array_key_exists($item->getItemNumber(), $catchedErrors)) {
                 foreach ($catchedErrors[$item->getItemNumber()] as $error) {
                     if ($error == Mage::helper('catalog')->__('The text is too long')) {
                         $sgError = ShopgateLibraryException::CART_ITEM_INPUT_VALIDATION_FAILED;
                     }
                 }
             }
         }
         $item->setError($sgError);
         $item->setErrorText(ShopgateLibraryException::getMessageFor($sgError));
         $items[] = $item;
     }
     return $items;
 }
Beispiel #16
0
 /**
  * Merge quotes
  *
  * @param   Mage_Sales_Model_Quote $quote
  * @return  Mage_Sales_Model_Quote
  */
 public function merge(Mage_Sales_Model_Quote $quote)
 {
     foreach ($quote->getAllVisibleItems() as $item) {
         $found = false;
         foreach ($this->getAllItems() as $quoteItem) {
             if ($quoteItem->compare($item)) {
                 $quoteItem->setQty($quoteItem->getQty() + $item->getQty());
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $newItem = clone $item;
             $this->addItem($newItem);
             if ($item->getHasChildren()) {
                 foreach ($item->getChildren() as $child) {
                     $newChild = clone $child;
                     $newChild->setParentItem($newItem);
                     $this->addItem($newChild);
                 }
             }
         }
     }
     if ($quote->getCouponCode()) {
         $this->setCouponCode($quote->getCouponCode());
     }
     return $this;
 }
Beispiel #17
0
 /**
  * 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;
 }
Beispiel #18
0
 /**
  * Save temp items in quote with "is_temporary" flag
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param int                    $flag
  * @param bool                   $checkItemId
  */
 public function saveTemporaryItems(Mage_Sales_Model_Quote $quote, $flag = 0, $checkItemId = false)
 {
     foreach ($quote->getAllVisibleItems() as $item) {
         if ($item->getId() && $checkItemId) {
             continue;
         }
         $item->setData('orderspro_is_temporary', $flag)->save();
     }
 }
Beispiel #19
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return int
  */
 private function countSubscriptions($quote)
 {
     $count = 0;
     foreach ($quote->getAllVisibleItems() as $item) {
         if (($product = $item->getProduct()) && $this->isSubscription($product)) {
             $count++;
         }
     }
     return $count;
 }
Beispiel #20
0
 /**
  * Send email id payment was failed
  *
  * @param Mage_Sales_Model_Quote $checkout
  * @param string $message
  * @param string $checkoutType
  * @return Mage_Checkout_Helper_Data
  */
 public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage')
 {
     $translate = Mage::getSingleton('Mage_Core_Model_Translate');
     /* @var $translate Mage_Core_Model_Translate */
     $translate->setTranslateInline(false);
     $mailTemplate = Mage::getModel('Mage_Core_Model_Email_Template');
     /* @var $mailTemplate Mage_Core_Model_Email_Template */
     $template = Mage::getStoreConfig('checkout/payment_failed/template', $checkout->getStoreId());
     $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId());
     $copyMethod = Mage::getStoreConfig('checkout/payment_failed/copy_method', $checkout->getStoreId());
     if ($copyTo && $copyMethod == 'bcc') {
         $mailTemplate->addBcc($copyTo);
     }
     $_reciever = Mage::getStoreConfig('checkout/payment_failed/reciever', $checkout->getStoreId());
     $sendTo = array(array('email' => Mage::getStoreConfig('trans_email/ident_' . $_reciever . '/email', $checkout->getStoreId()), 'name' => Mage::getStoreConfig('trans_email/ident_' . $_reciever . '/name', $checkout->getStoreId())));
     if ($copyTo && $copyMethod == 'copy') {
         foreach ($copyTo as $email) {
             $sendTo[] = array('email' => $email, 'name' => null);
         }
     }
     $shippingMethod = '';
     if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) {
         $data = explode('_', $shippingInfo);
         $shippingMethod = $data[0];
     }
     $paymentMethod = '';
     if ($paymentInfo = $checkout->getPayment()) {
         $paymentMethod = $paymentInfo->getMethod();
     }
     $items = '';
     foreach ($checkout->getAllVisibleItems() as $_item) {
         /* @var $_item Mage_Sales_Model_Quote_Item */
         $items .= $_item->getProduct()->getName() . '  x ' . $_item->getQty() . '  ' . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
     }
     $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal();
     foreach ($sendTo as $recipient) {
         $mailTemplate->setDesignConfig(array('area' => Mage_Core_Model_App_Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()))->sendTransactional($template, Mage::getStoreConfig('checkout/payment_failed/identity', $checkout->getStoreId()), $recipient['email'], $recipient['name'], array('reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => Mage::app()->getLocale()->date(), 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(), 'customerEmail' => $checkout->getCustomerEmail(), 'billingAddress' => $checkout->getBillingAddress(), 'shippingAddress' => $checkout->getShippingAddress(), 'shippingMethod' => Mage::getStoreConfig('carriers/' . $shippingMethod . '/title'), 'paymentMethod' => Mage::getStoreConfig('payment/' . $paymentMethod . '/title'), 'items' => nl2br($items), 'total' => $total));
     }
     $translate->setTranslateInline(true);
     return $this;
 }
 /**
  * Build the request with necessary parameters for doAuthorisation() and doTransaction()
  *
  * @param Mage_Sales_Model_Order_Payment $payment
  * @param $amount
  * @return Eway_Rapid31_Model_Request_Direct
  */
 protected function _buildRequest(Mage_Sales_Model_Quote $quote, $amount)
 {
     // Empty Varien_Object's data
     $this->unsetData();
     $billing = $quote->getBillingAddress();
     $shipping = $quote->getShippingAddress();
     $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
     if (Mage::helper('ewayrapid')->isBackendOrder()) {
         $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
     } else {
         $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
     }
     $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion());
     $this->setShippingMethod('Other');
     $paymentParam = Mage::getModel('ewayrapid/field_payment');
     $paymentParam->setTotalAmount($amount);
     $paymentParam->setCurrencyCode($quote->getBaseCurrencyCode());
     $this->setPayment($paymentParam);
     $customerParam = Mage::getModel('ewayrapid/field_customer');
     $customerParam->setTitle($billing->getPrefix())->setFirstName($billing->getFirstname())->setLastName($billing->getLastname())->setCompanyName($billing->getCompany())->setJobDescription('')->setStreet1($billing->getStreet1())->setStreet2($billing->getStreet2())->setCity($billing->getCity())->setState($billing->getRegion())->setPostalCode($billing->getPostcode())->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))->setEmail($billing->getEmail())->setPhone($billing->getTelephone())->setMobile('')->setComments('')->setFax($billing->getFax())->setUrl('');
     $infoCard = Mage::getSingleton('core/session')->getInfoCard();
     if ($infoCard && $infoCard->getCard() && $infoCard->getOwner() && !$this->getTokenInfo()) {
         $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
         $cardDetails->setName($infoCard->getOwner())->setNumber($infoCard->getCard())->setExpiryMonth($infoCard->getExpMonth())->setExpiryYear($infoCard->getExpYear())->setCVN($infoCard->getCid());
         $customerParam->setCardDetails($cardDetails);
     }
     if ($quote->getTokenCustomerID()) {
         $customerParam->setTokenCustomerID($quote->getTokenCustomerID());
     } elseif ($token = $this->getTokenInfo()) {
         $customerParam->setTokenCustomerID($token->getToken() ? $token->getToken() : $token->getTokenCustomerID());
     }
     $this->setCustomer($customerParam);
     $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
     $shippingParam->setFirstName($shipping->getFirstname())->setLastName($shipping->getLastname())->setStreet1($shipping->getStreet1())->setStreet2($shipping->getStreet2())->setCity($shipping->getCity())->setState($shipping->getRegion())->setPostalCode($shipping->getPostcode())->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))->setEmail($shipping->getEmail())->setPhone($shipping->getTelephone())->setFax($shipping->getFax());
     $this->setShippingAddress($shippingParam);
     $orderItems = $quote->getAllVisibleItems();
     $lineItems = array();
     foreach ($orderItems as $orderItem) {
         /* @var Mage_Sales_Model_Order_Item $orderItem */
         $lineItem = Mage::getModel('ewayrapid/field_lineItem');
         $lineItem->setSKU($orderItem->getSku());
         $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
         $lineItem->setQuantity($orderItem->getQtyOrdered());
         $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
         $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
         $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
         $lineItems[] = $lineItem;
     }
     $this->setItems($lineItems);
     if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
         $this->setItems(false);
     }
     return $this;
 }
Beispiel #22
0
 /**
  * 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/2009-05-15/">' . "\n";
     if (!$quote->hasItems()) {
         // Log if the checkout is done with an empty cart
         Mage::log("No Items found in the quote");
         return false;
     }
     $_xml .= " <ClientRequestId>{$quote->getId()}</ClientRequestId>\n";
     // Returning parameter
     $_xml .= " <Cart>\n" . "   <Items>\n";
     foreach ($quote->getAllVisibleItems() as $_item) {
         $product = $_item->getProduct();
         $configurabledata = Mage::getModel('Mage_Catalog_Model_Product_Type_Configurable');
         $configurablearray = $configurabledata->getOrderOptions($product);
         if ($_item->getProductType() == "configurable") {
             $sku = $configurablearray['simple_sku'];
             $product = $_item->getProduct($product->getIdBySku($sku));
             $name = $configurablearray['simple_name'];
         } else {
             $sku = $_item->getSku();
             $name = $_item->getName();
         }
         // VAT inclusive prices only for UK and DE. Taxes are ignored in EU callbacks
         if ($this->getCountry == "US") {
             $amount = $this->formatAmount($_item->getPrice());
         } else {
             $amount = $this->formatAmount($_item['price_incl_tax']);
         }
         $_xml .= "   <Item>\n" . "    <SKU>{$sku}/{$_item->getId()}</SKU>\n" . "    <MerchantId>{$this->getMerchantId()}</MerchantId>\n" . "    <Title>{$name}</Title>\n" . "    <Price>\n" . "     <Amount>{$amount}</Amount>\n" . "     <CurrencyCode>{$this->getCurrencyFormat()}</CurrencyCode>\n" . "    </Price>\n" . "    <Quantity>{$_item->getQty()}</Quantity>\n" . "    <Weight>\n" . "      <Amount>{$this->formatAmount($_item->getWeight())}</Amount>\n" . "       <Unit>{$this->getWeightUnit()}</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 .= " <DisablePromotionCode>true</DisablePromotionCode>\n";
     $_xml .= "</Order>\n";
     return $_xml;
 }
 /**
  * Create Abandoned Cart Email
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param string $email
  * @return boolean
  */
 public function createAbandonedCartEmail($quote, $email)
 {
     try {
         $this->_eventType = 'abandonedCart';
         $storeId = $quote->getStoreId();
         $reminderTemplate = Mage::getStoreConfig('sailthru/email/abandoned_cart_template', $storeId);
         $newTemplate = array('template' => $reminderTemplate, 'content_html' => $this->_getContent(), 'subject' => Mage::getStoreConfig('sailthru/email/abandoned_subject', $storeId), 'from_name' => Mage::getStoreConfig('sailthru/email/abandoned_cart_sender_name', $storeId), 'from_email' => Mage::getStoreConfig('sailthru/email/abandoned_cart_sender_email', $storeId), 'is_link_tracking' => 1, 'is_google_analytics' => 1);
         $templateResponse = $this->apiPost('template', $newTemplate);
         //Send Purchase Data
         $data = array('email' => $email, 'incomplete' => 1, 'items' => $this->_getItems($quote->getAllVisibleItems()), 'reminder_template' => $reminderTemplate);
         $response = $this->apiPost("purchase", $data);
         return true;
     } catch (Exception $e) {
         Mage::logException($e);
         return false;
     }
 }
Beispiel #24
0
 /**
  * Merge quotes
  *
  * @param   Mage_Sales_Model_Quote $quote
  * @return  Mage_Sales_Model_Quote
  */
 public function merge(Mage_Sales_Model_Quote $quote)
 {
     Mage::dispatchEvent($this->_eventPrefix . '_merge_before', array($this->_eventObject => $this, 'source' => $quote));
     foreach ($quote->getAllVisibleItems() as $item) {
         $found = false;
         foreach ($this->getAllItems() as $quoteItem) {
             if ($quoteItem->compare($item)) {
                 $quoteItem->setQty($quoteItem->getQty() + $item->getQty());
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $newItem = clone $item;
             $this->addItem($newItem);
             if ($item->getHasChildren()) {
                 foreach ($item->getChildren() as $child) {
                     $newChild = clone $child;
                     $newChild->setParentItem($newItem);
                     $this->addItem($newChild);
                 }
             }
         }
     }
     /**
      * Init shipping and billing address if quote is new
      */
     if (!$this->getId()) {
         $this->getShippingAddress();
         $this->getBillingAddress();
     }
     if ($quote->getCouponCode()) {
         $this->setCouponCode($quote->getCouponCode());
     }
     Mage::dispatchEvent($this->_eventPrefix . '_merge_after', array($this->_eventObject => $this, 'source' => $quote));
     return $this;
 }
 /**
  * Build ItemList
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return ItemList
  */
 protected function buildItemList($quote, $taxFailure)
 {
     $itemArray = array();
     $itemList = new ItemList();
     $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
     if (!$taxFailure) {
         foreach ($quote->getAllVisibleItems() as $quoteItem) {
             $item = new Item();
             if ($quoteItem->getQty() > 1) {
                 $item->setName($quoteItem->getName() . ' x' . $quoteItem->getQty());
             } else {
                 $item->setName($quoteItem->getName());
             }
             $item->setSku($quoteItem->getSku())->setCurrency($currencyCode)->setQuantity(1)->setPrice($quoteItem->getRowTotal());
             $itemArray[] = $item;
         }
         $itemList->setItems($itemArray);
     }
     return $itemList;
 }