コード例 #1
0
ファイル: AbstractPayol.php プロジェクト: buttasg/cowgirlk
 /**
  * @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();
 }
コード例 #2
0
ファイル: Product.php プロジェクト: manojiksula/magento
 /**
  * Get QuoteItem that matches Product.
  * 
  * @param Mage_Sales_Model_Quote $quote
  * @param Mage_Catalog_Model_Product $product
  * @return Mage_Sales_Model_Quote_Item | NULL
  */
 protected function _getItemByProduct(Mage_Sales_Model_Quote $quote, Mage_Catalog_Model_Product $product)
 {
     foreach ($quote->getAllItems() as $item) {
         if ($item->getProduct()->getId() == $product->getId()) {
             return $item;
         }
     }
     return Mage::getModel("sales/quote_item")->setProduct($product)->setQuote($quote);
 }
コード例 #3
0
 protected function getInitAmount(Mage_Sales_Model_Quote $quote)
 {
     $initAmount = 0;
     if ($quote->getSubscriptionPlan() != null) {
         $initAmount = (double) $quote->getSubscriptionPlan()->getInitAmount();
     } else {
         foreach ($quote->getAllItems() as $item) {
             $product = $item->getProduct();
             $product->load($product->getId());
             if ($item->isSubscription() && $product->getInitAmount()) {
                 $initAmount += $product->getInitAmount() * $item->getQty();
             }
         }
     }
     return $initAmount;
 }
コード例 #4
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return mixed|Varien_Object
  */
 public function isQuoteAdyenSubscription(Mage_Sales_Model_Quote $quote)
 {
     if (!$quote->hasData('_is_adyen_subscription')) {
         foreach ($quote->getAllItems() as $quoteItem) {
             /** @var Mage_Sales_Model_Quote_Item $quoteItem */
             $additionalOptions = $quoteItem->getOptionByCode('additional_options');
             if (!$additionalOptions) {
                 continue;
             }
             $options = unserialize($additionalOptions->getValue());
             foreach ($options as $option) {
                 if ($option['code'] == 'adyen_subscription' && $option['option_value'] != 'none') {
                     $quote->setData('_is_adyen_subscription', true);
                     $quoteItem->setData('_adyen_subscription', $option['option_value']);
                     return $quote->getData('_is_adyen_subscription');
                 }
             }
         }
         $quote->setData('_is_adyen_subscription', false);
     }
     return $quote->getData('_is_adyen_subscription');
 }
コード例 #5
0
 /**
  * Gets Mage_Sales_Model_Quote_Item from Mage_Sales_Model_Quote by product id
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param $productId
  * @return Mage_Sales_Model_Quote_Item|null
  */
 private function _getQuoteItemIdByProductId($quote, $productId)
 {
     /** @var $quoteItems Mage_Sales_Model_Quote_Item[] */
     $quoteItems = $quote->getAllItems();
     foreach ($quoteItems as $quoteItem) {
         if ($productId == $quoteItem->getProductId()) {
             return $quoteItem;
         }
     }
     return null;
 }
コード例 #6
0
 /**
  * Check the inventory status of each item in the quote. Will add errors
  * to the quote and items if any are not currently available at the
  * requested quantity. Will throw an exception if any item not yet added
  * to the quote should be prevented from being added.
  *
  * @param Mage_Sales_Model_Quote
  * @return self
  * @throws EbayEnterprise_Inventory_Exception_Quantity_Unavailable_Exception If any items should not be added to the quote.
  */
 public function checkQuoteInventory(Mage_Sales_Model_Quote $quote)
 {
     $inventoryItems = $this->_inventoryItemSelection->selectFrom($quote->getAllItems());
     if (empty($inventoryItems)) {
         $this->_logger->debug('no items to check, clearing collected quantities', $this->_logContext->getMetaData(__CLASS__));
         $this->_quantityCollector->clearResults();
     }
     foreach ($inventoryItems as $item) {
         if (!$this->isItemAvailable($item)) {
             $this->_handleUnavailableItem($item);
         } else {
             $this->_notifyCustomerIfItemBackorderable($item);
         }
     }
     return $this;
 }
コード例 #7
0
 /**
  * recursively process line items into payloads
  *
  * @param  Mage_Sales_Model_Quote
  * @param  ILineItemIterable
  * @param  string
  * @return self
  */
 protected function processLineItems(Mage_Sales_Model_Quote $quote, ILineItemIterable $lineItems)
 {
     $items = $this->selectionHelper->selectFrom($quote->getAllItems());
     foreach ($items as $item) {
         $this->createLineItem($item, $lineItems, $quote->getQuoteCurrencyCode());
     }
     return $this;
 }
コード例 #8
0
ファイル: Quote.php プロジェクト: rajarshc/Rooja
 /**
  * Updates this quotes' item catalog points.
  * @param TBT_Rewards_Model_Sales_Quote|Mage_Sales_Model_Quote $quote = null
  * @return TBT_Rewards_Model_Sales_Quote
  *
  */
 public function updateItemCatalogPoints($quote = null)
 {
     if ($quote == null) {
         $quote =& $this;
     }
     $quote_items = $quote->getAllItems();
     foreach ($quote_items as &$item) {
         if (!$item->getId()) {
             continue;
         }
         if ($item->getParentItem()) {
             continue;
         }
         $earned_point_totals = $this->_calculateItemCatalogEarnings($item, $quote);
         $item->setEarnedPointsHash(Mage::helper('rewards')->hashIt($earned_point_totals));
     }
     return $quote;
 }
コード例 #9
0
 /**
  * Initialize permissions for quote items
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return Enterprise_CatalogPermissions_Model_Observer
  */
 protected function _initPermissionsOnQuoteItems($quote)
 {
     $productIds = array();
     foreach ($quote->getAllItems() as $item) {
         if (!isset($this->_permissionsQuoteCache[$item->getProductId()]) && $item->getProductId()) {
             $productIds[] = $item->getProductId();
         }
     }
     if (!empty($productIds)) {
         $this->_permissionsQuoteCache += $this->_getIndexModel()->getIndexForProduct($productIds, $this->_getCustomerGroupId(), $quote->getStoreId());
         foreach ($productIds as $productId) {
             if (!isset($this->_permissionsQuoteCache[$productId])) {
                 $this->_permissionsQuoteCache[$productId] = false;
             }
         }
     }
     $defaultGrants = array('grant_catalog_category_view' => $this->_helper->isAllowedCategoryView(), 'grant_catalog_product_price' => $this->_helper->isAllowedProductPrice(), 'grant_checkout_items' => $this->_helper->isAllowedCheckoutItems());
     foreach ($quote->getAllItems() as $item) {
         if ($item->getProductId()) {
             $permission = $this->_permissionsQuoteCache[$item->getProductId()];
             if (!$permission && in_array(false, $defaultGrants)) {
                 // If no permission found, and no one of default grant is disallowed
                 $item->setDisableAddToCart(true);
                 continue;
             }
             foreach ($defaultGrants as $grant => $defaultPermission) {
                 if ($permission[$grant] == -2 || $permission[$grant] != -1 && !$defaultPermission) {
                     $item->setDisableAddToCart(true);
                     break;
                 }
             }
         }
     }
     return $this;
 }
コード例 #10
0
 /**
  * Check the inventory status of each item in the quote. Will add errors
  * to the quote and items if any are not currently available at the
  * requested quantity. Will throw an exception if any item not yet added
  * to the quote should be prevented from being added.
  *
  * @param Mage_Sales_Model_Quote
  * @return self
  * @throws EbayEnterprise_Inventory_Exception_Quantity_Unavailable_Exception If any items should not be added to the quote.
  */
 public function checkQuoteInventory(Mage_Sales_Model_Quote $quote)
 {
     $inventoryItems = $this->_inventoryItemSelection->selectFrom($quote->getAllItems());
     if (empty($inventoryItems)) {
         $this->_quantityCollector->clearResults();
     }
     foreach ($inventoryItems as $item) {
         if (!$this->isItemAvailable($item)) {
             $this->_handleUnavailableItem($item);
         } else {
             $this->_notifyCustomerIfItemBackorderable($item);
         }
     }
     return $this;
 }
コード例 #11
0
 /**
  * calculate earning point for order quote
  * 
  * @param Mage_Sales_Model_Quote $quote
  * @param int $customerGroupId
  * @param int $websiteId
  * @param string $date
  * @return int
  */
 public function getShoppingCartPoints($quote, $customerGroupId = null, $websiteId = null, $date = null)
 {
     if ($quote->isVirtual()) {
         $address = $quote->getBillingAddress();
     } else {
         $address = $quote->getShippingAddress();
     }
     //webpos
     $customerId = Mage::getSingleton('checkout/session')->getData('webpos_customerid');
     if ($customerId) {
         $customerGroupId = Mage::getModel('customer/customer')->load($customerId)->getGroupId();
     } else {
         $customerGroupId = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
     }
     if (is_null($websiteId)) {
         $websiteId = Mage::app()->getStore($quote->getStoreId())->getWebsiteId();
     }
     if (is_null($date)) {
         $date = date('Y-m-d', strtotime($quote->getCreatedAt()));
     }
     $points = 0;
     $rules = Mage::getResourceModel('rewardpointsrule/earning_sales_collection')->setAvailableFilter($customerGroupId, $websiteId, $date);
     $items = $quote->getAllItems();
     $this->setStoreId($quote->getStoreId());
     foreach ($rules as $rule) {
         $rule->afterLoad();
         if (!$rule->validate($address)) {
             continue;
         }
         $rowTotal = 0;
         $qtyTotal = 0;
         foreach ($items as $item) {
             if ($item->getParentItemId()) {
                 continue;
             }
             if ($rule->getActions()->validate($item)) {
                 $rowTotal += max(0, $item->getBaseRowTotal() - $item->getBaseDiscountAmount() - $item->getRewardpointsBaseDiscount());
                 $qtyTotal += $item->getQty();
             }
         }
         if (!$qtyTotal) {
             continue;
         }
         if (Mage::getStoreConfigFlag(self::XML_PATH_EARNING_BY_SHIPPING, $quote->getStoreId())) {
             $rowTotal += $address->getBaseShippingAmount();
         }
         $points += $this->calcSalesPoints($rule->getSimpleAction(), $rule->getPointsEarned(), $rule->getMoneyStep(), $rowTotal, $rule->getQtyStep(), $qtyTotal, $rule->getMaxPointsEarned());
         if ($points && $rule->getStopRulesProcessing()) {
             break;
         }
     }
     return $points;
 }
コード例 #12
0
ファイル: Crosssell.php プロジェクト: aoepeople/aoe_cartapi
 /**
  * @param Mage_Sales_Model_Quote $quote
  * @param bool                   $applyCollectionModifiers
  *
  * @return Mage_Catalog_Model_Product[]
  */
 protected function getCrosssellProducts(Mage_Sales_Model_Quote $quote, $applyCollectionModifiers = true)
 {
     $cartProductIds = [];
     foreach ($quote->getAllItems() as $item) {
         /** @var Mage_Sales_Model_Quote_Item $item */
         if ($product = $item->getProduct()) {
             $cartProductIds[] = intval($product->getId());
         }
     }
     if ($cartProductIds) {
         /** @var Mage_Catalog_Model_Resource_Product_Link_Product_Collection $collection */
         $collection = Mage::getModel('catalog/product_link')->useCrossSellLinks()->getProductCollection();
         $collection->setStoreId($quote->getStoreId());
         $collection->addStoreFilter();
         //$collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
         $collection->addAttributeToSelect('*');
         $collection->addUrlRewrite();
         $collection->addAttributeToFilter('status', ['eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED]);
         Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($collection);
         Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
         $collection->applyFrontendPriceLimitations();
         $collection->addProductFilter($cartProductIds);
         $collection->addExcludeProductFilter($cartProductIds);
         $collection->setGroupBy();
         $collection->setPositionOrder();
         if ($applyCollectionModifiers) {
             $this->_applyCollectionModifiers($collection);
         }
         /** @var Mage_CatalogInventory_Model_Stock $stock */
         $stock = Mage::getModel('cataloginventory/stock');
         $stock->addItemsToProducts($collection);
         return $collection->getItems();
     } else {
         return [];
     }
 }
コード例 #13
0
ファイル: Mapping.php プロジェクト: ratepay/magento-module
 /**
  * Article preparations for PAYMENT_REQUEST, PAYMENT_CHANGE, CONFIRMATION_DELIVER
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
  * @return array
  */
 public function getArticles($object)
 {
     $articles = array();
     $articleDiscountAmount = 0;
     $objectItems = $object->getAllItems();
     foreach ($objectItems as $item) {
         if ($item instanceof Mage_Sales_Model_Order_Item || $item instanceof Mage_Sales_Model_Quote_Item) {
             $orderItem = $item;
         } else {
             $orderItem = Mage::getModel('sales/order_item')->load($item->getOrderItemId());
         }
         $shopProduct = Mage::getModel('catalog/product')->load($orderItem->getProductId());
         if (($orderItem->getProductType() !== 'bundle' || $orderItem->getProductType() === 'bundle' && $shopProduct->getPrice() > 0) && $orderItem->getRowTotal() > 0) {
             $article = array();
             $article['articleNumber'] = $item->getSku();
             $article['articleName'] = $item->getName();
             $article['quantity'] = $object instanceof Mage_Sales_Model_Order ? $item->getQtyOrdered() : $item->getQty();
             $article['unitPriceGross'] = $item->getPriceInclTax();
             $article['taxPercent'] = $orderItem->getTaxPercent();
             $article['discountId'] = '';
             if ($item->getDiscountAmount() > 0) {
                 $discount = array();
                 $discount['articleNumber'] = 'DISCOUNT-' . $item->getSku();
                 $discount['articleName'] = 'DISCOUNT - ' . $item->getName();
                 $discount['quantity'] = $article['quantity'];
                 $discount['unitPriceGross'] = -1 * $item->getDiscountAmount() / $article['quantity'];
                 $discount['discountId'] = $item->getSku();
                 $articleDiscountAmount = $articleDiscountAmount + $item->getDiscountAmount();
             }
             $articles[] = $article;
             if ($item->getDiscountAmount() > 0) {
                 // only for sort reason
                 $articles[] = $discount;
             }
         }
     }
     if ($object->getGwPrice() > 0) {
         $article = array();
         $article['articleNumber'] = 'orderwrapping';
         $article['articleName'] = 'Wrapping Cost Order';
         $article['quantity'] = '1';
         $article['unitPriceGross'] = $object->getGwPrice();
         $article['taxPercent'] = 100 / $object->getGwPrice() * $object->getGwTaxAmount();
         $article['discountId'] = '';
         $articles[] = $article;
     }
     if ($object->getGwItemsPrice() > 0) {
         $article = array();
         $article['articleNumber'] = 'itemswrapping';
         $article['articleName'] = 'Wrapping Cost Items';
         $article['quantity'] = '1';
         $article['unitPriceGross'] = $object->getGwItemsPrice();
         $article['taxPercent'] = 100 / $object->getGwItemsPrice() * $object->getGwItemsTaxAmount();
         $article['discountId'] = '';
         $articles[] = $article;
     }
     if ($object->getGwAddCard() > 0) {
         $article = array();
         $article['articleNumber'] = 'printed_card';
         $article['articleName'] = 'Printed Card';
         $article['quantity'] = '1';
         $article['unitPriceGross'] = $object->getGwCardPrice();
         $article['taxPercent'] = 100 / $object->getGwCardPrice() * $object->getGwCardTaxAmount();
         $article['discountId'] = '';
         $articles[] = $article;
     }
     if (Mage::getEdition() == 'Enterprise') {
         $_cards = Mage::getBlockSingleton('enterprise_giftcardaccount/checkout_cart_total')->getQuoteGiftCards();
         if ($_cards) {
             foreach ($_cards as $card) {
                 $article = array();
                 $article['articleNumber'] = 'gift_card';
                 $article['articleName'] = $card['c'];
                 $article['quantity'] = '1';
                 $article['unitPriceGross'] = -round($card['ba'], 2);
                 $article['taxPercent'] = 0;
                 $article['discountId'] = '';
                 $articles[] = $article;
             }
         }
     }
     if ($object instanceof Mage_Sales_Model_Order || $object instanceof Mage_Sales_Model_Order_Invoice || $object instanceof Mage_Sales_Model_Order_Creditmemo) {
         $shippingObject = $object;
         if ($object instanceof Mage_Sales_Model_Order_Creditmemo) {
             $articles = $this->addAdjustments($object, $articles);
         }
     } else {
         $shippingObject = $object->getShippingAddress();
     }
     if ($shippingObject->getShippingAmount() > 0) {
         if ($object instanceof Mage_Sales_Model_Order_Invoice || $object instanceof Mage_Sales_Model_Order_Shipment || $object instanceof Mage_Sales_Model_Order_Creditmemo) {
             $shippingDiscountAmount = $shippingObject->getDiscountAmount() - $articleDiscountAmount;
             $shippingDescription = $object->getOrder()->getShippingDescription();
         } else {
             $shippingDiscountAmount = $shippingObject->getShippingDiscountAmount();
             $shippingDescription = $shippingObject->getShippingDescription();
         }
         $article = array();
         $article['articleNumber'] = 'SHIPPING';
         $article['articleName'] = $shippingDescription;
         $article['quantity'] = '1';
         $article['unitPriceGross'] = $shippingObject->getShippingInclTax();
         $shippingTaxPercent = 0;
         if ($shippingObject->getShippingInclTax() - $shippingObject->getShippingAmount() > 0) {
             $shippingTaxPercent = ($shippingObject->getShippingInclTax() - $shippingObject->getShippingAmount()) * 100 / $shippingObject->getShippingAmount();
         }
         $article['taxPercent'] = $shippingTaxPercent;
         $article['discountId'] = '';
         if ($shippingDiscountAmount > 0) {
             $discount = array();
             $discount['articleNumber'] = 'SHIPPINGDISCOUNT';
             $discount['articleName'] = 'Shipping - Discount';
             $discount['quantity'] = 1;
             $discount['unitPriceGross'] = -1 * $shippingObject->getShippingDiscountAmount();
             $discount['taxPercent'] = 0;
             $discount['discountId'] = 'SHIPPING';
         }
         $articles[] = $article;
         if ($shippingDiscountAmount > 0) {
             // only for sort reason
             $articles[] = $discount;
         }
     }
     if ($object->getRewardCurrencyAmount() > 0) {
         $article = array();
         $article['articleNumber'] = 'REWARDPOINTS';
         $article['articleName'] = 'Reward points';
         $article['quantity'] = '1';
         $article['unitPriceGross'] = -1 * $object->getRewardCurrencyAmount();
         $article['taxPercent'] = 0;
         $article['discountId'] = '';
         $articles[] = $article;
     }
     return $articles;
 }
コード例 #14
0
 /**
  * Place the order
  *
  * @return bool
  */
 protected function _processOrder()
 {
     if (!$this->_auth()) {
         return false;
     }
     if (!$this->_validateQuote()) {
         return false;
     }
     // Push address to the quote, set totals,
     // Convert quote to the order,
     // Set rakuten_order attribute to "1"
     try {
         // To avoid duplicates look for order with the same Rakuten order no
         $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('ext_order_id', (string) $this->_request->order_no);
         if (count($orders)) {
             $this->_debugData['reason'] = 'The same order already placed';
             return false;
         }
         // Import addresses and other data to quote
         $this->_quote->setIsActive(true)->reserveOrderId();
         $storeId = $this->_quote->getStoreId();
         Mage::app()->setCurrentStore(Mage::app()->getStore($storeId));
         if ($this->_quote->getQuoteCurrencyCode() != $this->_quote->getBaseCurrencyCode()) {
             Mage::app()->getStore()->setCurrentCurrencyCode($this->_quote->getQuoteCurrencyCode());
         }
         $billing = $this->_convertAddress('client');
         $this->_quote->setBillingAddress($billing);
         $shipping = $this->_convertAddress('delivery_address');
         $this->_quote->setShippingAddress($shipping);
         $this->_convertTotals($this->_quote->getShippingAddress());
         $this->_quote->getPayment()->importData(array('method' => 'rakuten'));
         /**
          * Convert quote to order
          *
          * @var $convertQuote Mage_Sales_Model_Convert_Quote
          */
         $convertQuote = Mage::getSingleton('sales/convert_quote');
         /* @var $order Mage_Sales_Model_Order */
         $order = $convertQuote->toOrder($this->_quote);
         if ($this->_quote->isVirtual()) {
             $convertQuote->addressToOrder($this->_quote->getBillingAddress(), $order);
         } else {
             $convertQuote->addressToOrder($this->_quote->getShippingAddress(), $order);
         }
         $order->setExtOrderId((string) $this->_request->order_no);
         $order->setExtCustomerId((string) $this->_request->client->client_id);
         if (!$order->getCustomerEmail()) {
             $order->setCustomerEmail($billing->getEmail())->setCustomerPrefix($billing->getPrefix())->setCustomerFirstname($billing->getFirstname())->setCustomerMiddlename($billing->getMiddlename())->setCustomerLastname($billing->getLastname())->setCustomerSuffix($billing->getSuffix())->setCustomerIsGuest(1);
         }
         $order->setBillingAddress($convertQuote->addressToOrderAddress($this->_quote->getBillingAddress()));
         if (!$this->_quote->isVirtual()) {
             $order->setShippingAddress($convertQuote->addressToOrderAddress($this->_quote->getShippingAddress()));
         }
         /** @var $item Mage_Sales_Model_Quote_Item */
         foreach ($this->_quote->getAllItems() as $item) {
             $orderItem = $convertQuote->itemToOrderItem($item);
             if ($item->getParentItem()) {
                 $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
             }
             $order->addItem($orderItem);
         }
         /**
          * Adding transaction for correct transaction information displaying on the order view in the admin.
          * It has no influence on the API interaction logic.
          *
          * @var $payment Mage_Sales_Model_Order_Payment
          */
         $payment = Mage::getModel('sales/order_payment');
         $payment->setMethod('rakuten')->setTransactionId((string) $this->_request->order_no)->setIsTransactionClosed(false);
         $order->setPayment($payment);
         $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
         $order->setCanShipPartiallyItem(false);
         $message = '';
         if (trim((string) $this->_request->comment_client) != '') {
             $message .= $this->__('Customer\'s Comment: %s', '<strong>' . trim((string) $this->_request->comment_client) . '</strong><br />');
         }
         $message .= $this->__('Rakuten Order No: %s', '<strong>' . (string) $this->_request->order_no . '</strong><br />') . $this->__('Rakuten Client ID: %s', '<strong>' . (string) $this->_request->client->client_id . '</strong><br />');
         $order->addStatusHistoryComment($message);
         $order->setRakutenOrder(1);
         // Custom attribute for fast filtering of orders placed via Rakuten Checkout
         $order->place();
         $order->save();
         //            $order->sendNewOrderEmail();
         $this->_quote->setIsActive(false)->save();
         Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote));
     } catch (Exception $e) {
         $this->_debugData['exception'] = $e->getMessage();
         Mage::logException($e);
         return false;
     }
     return true;
 }
コード例 #15
0
 /**
  * @param Mage_Sales_Model_Quote     $quote
  * @param Adyen_Subscription_Model_Subscription $subscription
  *
  * @return Mage_Sales_Model_Order
  * @throws Adyen_Subscription_Exception|Exception
  */
 public function createOrder(Mage_Sales_Model_Quote $quote, Adyen_Subscription_Model_Subscription $subscription)
 {
     Mage::dispatchEvent('adyen_subscription_quote_createorder_before', array('subscription' => $subscription, 'quote' => $quote));
     try {
         if (!$subscription->canCreateOrder()) {
             Mage::helper('adyen_subscription')->logOrderCron("Not allowed to create order from quote");
             Adyen_Subscription_Exception::throwException(Mage::helper('adyen_subscription')->__('Not allowed to create order from quote'));
         }
         foreach ($quote->getAllItems() as $item) {
             /** @var Mage_Sales_Model_Quote_Item $item */
             $item->getProduct()->setData('is_created_from_subscription_item', $item->getData('subscription_item_id'));
         }
         $quote->collectTotals();
         $service = Mage::getModel('sales/service_quote', $quote);
         $service->submitAll();
         $order = $service->getOrder();
         // Save order addresses at subscription when they're currently quote addresses
         $subscriptionBillingAddress = Mage::getModel('adyen_subscription/subscription_address')->getSubscriptionAddress($subscription, self::ADDRESS_TYPE_BILLING);
         if ($subscriptionBillingAddress->getSource() == self::ADDRESS_SOURCE_QUOTE) {
             $subscriptionBillingAddress->initAddress($subscription, $order->getBillingAddress())->save();
         }
         $subscriptionShippingAddress = Mage::getModel('adyen_subscription/subscription_address')->getSubscriptionAddress($subscription, self::ADDRESS_TYPE_SHIPPING);
         if ($subscriptionShippingAddress->getSource() == self::ADDRESS_SOURCE_QUOTE) {
             $subscriptionShippingAddress->initAddress($subscription, $order->getShippingAddress())->save();
         }
         $orderAdditional = $subscription->getOrderAdditional($order, true)->save();
         $quoteAdditional = $subscription->getActiveQuoteAdditional()->setOrder($order)->save();
         $subscription->setErrorMessage(null);
         $subscriptionHistory = null;
         //Save history
         if ($subscription->getStatus() == $subscription::STATUS_ORDER_ERROR || $subscription->getStatus() == $subscription::STATUS_PAYMENT_ERROR) {
             $subscription->setStatus($subscription::STATUS_ACTIVE);
             $subscriptionHistory = Mage::getModel('adyen_subscription/subscription_history');
             $subscriptionHistory->createHistoryFromSubscription($subscription);
         }
         $subscription->setScheduledAt($subscription->calculateNextScheduleDate());
         $transaction = Mage::getModel('core/resource_transaction');
         $transaction->addObject($subscription)->addObject($orderAdditional)->addObject($quoteAdditional)->addObject($order);
         if ($subscriptionHistory) {
             $transaction->addObject($subscriptionHistory);
         }
         $transaction->save();
         Mage::helper('adyen_subscription')->logOrderCron(sprintf("Successful created order (#%s) for subscription (#%s)", $order->getId(), $subscription->getId()));
         $order = $service->getOrder();
         Mage::dispatchEvent('adyen_subscription_quote_createorder_after', array('subscription' => $subscription, 'quote' => $quote, 'order' => $order));
         return $order;
     } catch (Mage_Payment_Exception $e) {
         Mage::helper('adyen_subscription')->logOrderCron(sprintf("Error in subscription (#%s) creating order from quote (#%s) error is: %s", $subscription->getId(), $quote->getId(), $e->getMessage()));
         if (isset($order)) {
             $order->delete();
         }
         $subscription->setStatus($subscription::STATUS_PAYMENT_ERROR);
         $subscription->setErrorMessage($e->getMessage());
         $subscription->save();
         Mage::dispatchEvent('adyen_subscription_quote_createorder_fail', array('subscription' => $subscription, 'status' => $subscription::STATUS_PAYMENT_ERROR, 'error' => $e->getMessage()));
         throw $e;
     } catch (Exception $e) {
         Mage::helper('adyen_subscription')->logOrderCron(sprintf("Error in subscription (#%s) creating order from quote (#%s) error is: %s", $subscription->getId(), $quote->getId(), $e->getMessage()));
         if (isset($order)) {
             $order->delete();
         }
         $subscription->setStatus($subscription::STATUS_ORDER_ERROR);
         $subscription->setErrorMessage($e->getMessage());
         $subscription->save();
         Mage::dispatchEvent('adyen_subscription_quote_createorder_fail', array('subscription' => $subscription, 'status' => $subscription->getStatus(), 'error' => $e->getMessage()));
         throw $e;
     }
 }
コード例 #16
0
ファイル: Filter.php プロジェクト: bevello/bevello
 /**
  * @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;
 }
コード例 #17
0
ファイル: Edit.php プロジェクト: AleksNesh/pandora
 /**
  * Add new products to order
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param Mage_Sales_Model_Order $order
  * @param                        $changes
  * @return $this
  */
 public function saveNewOrderItems(Mage_Sales_Model_Quote $quote, Mage_Sales_Model_Order $order, $changes)
 {
     foreach ($quote->getAllItems() as $quoteItem) {
         $orderItem = $order->getItemByQuoteItemId($quoteItem->getItemId());
         if ($orderItem && $orderItem->getItemId()) {
             continue;
         }
         $quoteItem->save();
         $orderItem = $this->getConvertor()->itemToOrderItem($quoteItem, $orderItem);
         $order->addItem($orderItem);
         $orderItem->save();
         /*** Add new items to log ***/
         $changedItem = $quoteItem;
         $itemChange = array('name' => $changedItem->getName(), 'qty_before' => 0, 'qty_after' => $changedItem->getQty());
         $this->getLogModel()->addItemChange($changedItem->getId(), $itemChange);
         $this->_savedOrderItems[] = $orderItem->getItemId();
     }
     foreach ($quote->getAllItems() as $childQuoteItem) {
         $parentOrderItem = false;
         $childOrderItem = $order->getItemByQuoteItemId($childQuoteItem->getItemId());
         /*** Add items relations for configurable and bundle products ***/
         if ($childQuoteItem->getParentItemId()) {
             $parentOrderItem = $order->getItemByQuoteItemId($childQuoteItem->getParentItemId());
             $childOrderItem->setParentItemId($parentOrderItem->getItemId());
             $childOrderItem->save();
         }
         //            /*** Add new items to log ***/
         //            $changedItem = $parentOrderItem ? $parentOrderItem : $childOrderItem;
         //            $itemChange = array(
         //                'name' => $changedItem->getName(),
         //                'qty_before' => 0,
         //                'qty_after' => $changedItem->getQtyToRefund() + $changedItem->getQtyToCancel()
         //            );
         //            $this->getLogModel()->addItemChange($changedItem->getId(), $itemChange);
     }
     return $this;
 }
コード例 #18
0
 protected function handleUnavailableItems(Mage_Sales_Model_Quote $quote)
 {
     foreach ($quote->getAllItems() as $item) {
         if ($item->getHasChildren()) {
             continue;
         }
         $detail = $this->getDetailsForItem($item);
         if ($detail && !$detail->isAvailable() && !$this->hasQuantityError($item)) {
             // an item came back unavailable for an item that
             // succeeded in the last quantity request.
             $this->handleDesynchedFromQuantity();
         }
     }
 }
コード例 #19
0
 /**
  * Get quantity results for a quote.
  *
  * @param Mage_Sales_Model_Quote
  * @return EbayEnterprise_Inventory_Model_Quantity_Results
  */
 public function getQuantityResultsForQuote(Mage_Sales_Model_Quote $quote)
 {
     $items = $this->_itemSelection->selectFrom($quote->getAllItems());
     return $this->_getSessionResults($items) ?: $this->_requestNewResults($items);
 }
コード例 #20
0
ファイル: Data.php プロジェクト: GabrielCC/zitec-dpd-master
 /**
  *
  * @param Mage_Sales_Model_Quote $quote
  *
  * @return float
  */
 public function getBaseValueOfShippableGoods(Mage_Sales_Model_Quote $quote)
 {
     $baseTotalPrice = 0.0;
     $taxConfig = Mage::getSingleton('tax/config');
     /* @var $taxConfig Mage_Tax_Model_Config */
     if ($quote->getAllItems()) {
         foreach ($quote->getAllItems() as $item) {
             /* @var $item Mage_Sales_Model_Quote_Item */
             if ($item->getProduct()->isVirtual() || $item->getParentItemId()) {
                 continue;
             }
             $baseTotalPrice += $taxConfig->shippingPriceIncludesTax($quote->getStore()) ? $item->getBaseRowTotalInclTax() : $item->getBaseRowTotal();
         }
     }
     return $baseTotalPrice;
 }
コード例 #21
0
 /**
  * recursively process line items into payloads
  * @param  Mage_Sales_Model_Quote
  * @param  ILineItemIterable
  * @return self
  */
 protected function processLineItems(Mage_Sales_Model_Quote $quote, ILineItemIterable $lineItems)
 {
     $items = $quote->getAllItems();
     $currencyCode = $quote->getQuoteCurrencyCode();
     foreach ($items as $item) {
         $this->processItem($item, $lineItems, $currencyCode);
     }
     return $this;
 }
コード例 #22
0
 /**
  * @param Mage_Sales_Model_Quote $quote
  * @return bool
  */
 private function _hasEcodeItems(Mage_Sales_Model_Quote $quote)
 {
     foreach ($quote->getAllItems() as $quoteItem) {
         if ($this->_isEcodeItem($quoteItem)) {
             return true;
         }
     }
     return false;
 }
コード例 #23
0
ファイル: Observer.php プロジェクト: ThomasNegeli/freeproduct
 /**
  * Delete all free items from the cart.
  *
  * @param Mage_Sales_Model_Quote $quote
  */
 protected static function _resetFreeItems(Mage_Sales_Model_Quote $quote)
 {
     foreach ($quote->getAllItems() as $item) {
         if ($item->getIsFreeProduct()) {
             $quote->removeItem($item->getId());
         }
     }
 }
コード例 #24
0
ファイル: Quote.php プロジェクト: AleksNesh/pandora
 protected function clearQuote(Mage_Sales_Model_Quote $quote)
 {
     $items = $quote->getAllItems();
     /** @var Mage_Sales_Model_Quote_Item $item */
     foreach ($items as $item) {
         if ($this->clearQuoteItems($item, false)) {
             $quote->removeItem($item->getId());
         }
     }
 }
コード例 #25
0
ファイル: Observer.php プロジェクト: rajarshc/Rooja
 /**
  * This function will attempt to update the quote catalog redemptions
  * data.  This should be triggered when the cart changes.
  * @param Mage_Sales_Model_Quote $quote
  * @param array $data[=null]
  * @param unknown_type $date[=null]
  * @param int $wId[=null]
  */
 public function updateQuoteCatalogRedemptions($quote, $data = null, $date = null, $wId = null)
 {
     try {
         if (!$quote) {
             return $this;
         }
         if ($data) {
             //@nelkaake -a 17/02/11: A save-on-quote event
             $is_on_quote_save = false;
             $items = $data;
         } else {
             $is_on_quote_save = true;
             $items = $quote->getAllItems();
         }
         if (!is_array($items)) {
             $items = array($items);
         }
         $refactorItems = array();
         foreach ($items as $key => $itemInfo) {
             if ($is_on_quote_save) {
                 $itemId = $itemInfo->getId();
                 $item = $itemInfo;
             } else {
                 $itemId = $key;
                 $item = $quote->getItemById($itemId);
             }
             if (!$itemId || !$item) {
                 continue;
             }
             if (!$is_on_quote_save) {
                 if (!empty($itemInfo['remove']) || isset($itemInfo['qty']) && $itemInfo['qty'] == '0') {
                     continue;
                 }
             }
             $product = $item->getProduct();
             $pId = $product->getId();
             $storeId = $product->getStoreId();
             if (!$date) {
                 $date = Mage::helper('rewards')->now();
             }
             if ($wId) {
                 $wId = Mage::app()->getStore($storeId)->getWebsiteId();
             }
             $gId = Mage::getSingleton('customer/session')->getCustomerGroupId();
             if ($gId !== 0 && empty($gId)) {
                 $gId = Mage_Customer_Model_Group::NOT_LOGGED_IN_ID;
             }
             if ($is_on_quote_save) {
                 $qty = $item->getQty();
             } else {
                 $qty = isset($itemInfo['qty']) ? (double) $itemInfo['qty'] : false;
             }
             // Since the cart has changed, reset our before-redemptions value and let Sweet Tooth recalculate the discount amount.
             Mage::getSingleton('rewards/redeem')->resetBeforeDiscount($item);
             $refactorItems[] = $item;
         }
         Mage::getSingleton('rewards/redeem')->refactorRedemptions($refactorItems);
     } catch (Exception $e) {
         Mage::logException($e);
         Mage::helper('rewards')->log($e->getMessage());
         Mage::helper('rewards')->log($e);
         die($e->getMessage());
     }
 }
コード例 #26
0
ファイル: Mapping.php プロジェクト: nschoen/magento-module
 /**
  * Article preparations for PAYMENT_REQUEST, PAYMENT_CHANGE, CONFIRMATION_DELIVER
  *
  * @param Mage_Sales_Model_Quote|Mage_Sales_Model_Order|Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
  * @return array
  */
 public function getArticles($object)
 {
     $articles = array();
     $articleDiscountAmount = 0;
     $objectItems = $object->getAllItems();
     foreach ($objectItems as $item) {
         if ($item instanceof Mage_Sales_Model_Order_Item || $item instanceof Mage_Sales_Model_Quote_Item) {
             $orderItem = $item;
         } else {
             $orderItem = Mage::getModel('sales/order_item')->load($item->getOrderItemId());
         }
         $shopProduct = Mage::getModel('catalog/product')->load($orderItem->getProductId());
         if (($orderItem->getProductType() !== 'bundle' || $orderItem->getProductType() === 'bundle' && $shopProduct->getPrice() > 0) && $orderItem->getRowTotal() > 0) {
             $article = array();
             $article['articleNumber'] = $item->getSku();
             $article['articleName'] = $item->getName();
             $article['quantity'] = $object instanceof Mage_Sales_Model_Order ? $item->getQtyOrdered() : $item->getQty();
             $article['unitPriceGross'] = $item->getPriceInclTax();
             $article['tax'] = $item->getTaxAmount();
             $article['taxPercent'] = $orderItem->getTaxPercent();
             if ($object instanceof Mage_Sales_Model_Quote) {
                 $article['unitPriceNett'] = $item->getCalculationPrice();
             } else {
                 $article['unitPriceNett'] = $item->getPrice();
                 // netto
             }
             $article['discountId'] = '';
             if ($item->getDiscountAmount() > 0) {
                 $discount = array();
                 $discount['articleNumber'] = 'DISCOUNT-' . $item->getSku();
                 $discount['articleName'] = 'DISCOUNT - ' . $item->getName();
                 $discount['quantity'] = $article['quantity'];
                 $article['tax'] = $item->getRowTotalInclTax() - $item->getRowTotal();
                 $discount['tax'] = -1 * ($article['tax'] - $item->getTaxAmount());
                 $tax = 0;
                 $taxConfig = Mage::getSingleton('tax/config');
                 if ($taxConfig->priceIncludesTax($object->getStoreId())) {
                     $tax = $discount['tax'];
                 }
                 if (round($discount['tax'], 2) < 0) {
                     $discount['taxPercent'] = $article['taxPercent'];
                 }
                 $discount['unitPriceGross'] = -1 * $item->getDiscountAmount() / $article['quantity'];
                 $discount['discountId'] = $item->getSku();
                 $articleDiscountAmount = $articleDiscountAmount + $item->getDiscountAmount();
             }
             $articles[] = $article;
             if ($item->getDiscountAmount() > 0) {
                 // only for sort reason
                 $articles[] = $discount;
             }
         }
     }
     if ($object instanceof Mage_Sales_Model_Order || $object instanceof Mage_Sales_Model_Order_Invoice || $object instanceof Mage_Sales_Model_Order_Creditmemo) {
         $shippingObject = $object;
         if ($object instanceof Mage_Sales_Model_Order_Creditmemo) {
             $articles = $this->addAdjustments($object, $articles);
         }
     } else {
         $shippingObject = $object->getShippingAddress();
     }
     if ($shippingObject->getShippingAmount() > 0) {
         if ($object instanceof Mage_Sales_Model_Order_Invoice || $object instanceof Mage_Sales_Model_Order_Shipment || $object instanceof Mage_Sales_Model_Order_Creditmemo) {
             $shippingDiscountAmount = $shippingObject->getDiscountAmount() - $articleDiscountAmount;
             $shippingDescription = $object->getOrder()->getShippingDescription();
         } else {
             $shippingDiscountAmount = $shippingObject->getShippingDiscountAmount();
             $shippingDescription = $shippingObject->getShippingDescription();
         }
         $article = array();
         $article['articleNumber'] = 'SHIPPING';
         $article['articleName'] = $shippingDescription;
         $article['quantity'] = '1';
         $article['unitPriceGross'] = $shippingObject->getShippingInclTax();
         $article['tax'] = $shippingObject->getShippingTaxAmount();
         $shippingTaxPercent = 0;
         if ($shippingObject->getShippingInclTax() - $shippingObject->getShippingAmount() > 0) {
             $shippingTaxPercent = ($shippingObject->getShippingInclTax() - $shippingObject->getShippingAmount()) * 100 / $shippingObject->getShippingAmount();
         }
         $article['taxPercent'] = $shippingTaxPercent;
         $article['discountId'] = '';
         if ($shippingDiscountAmount > 0) {
             $discount = array();
             $discount['articleNumber'] = 'SHIPPINGDISCOUNT';
             $discount['articleName'] = 'Shipping - Discount';
             $discount['quantity'] = 1;
             $discount['unitPriceGross'] = -1 * $shippingObject->getShippingDiscountAmount();
             $article['tax'] = $shippingObject->getShippingInclTax() - $shippingObject->getShippingAmount();
             $discount['tax'] = -1 * ($article['tax'] - $shippingObject->getShippingTaxAmount());
             $tax = 0;
             if (Mage::getSingleton('tax/config')->shippingPriceIncludesTax($object->getStoreId())) {
                 $tax = $discount['tax'];
             }
             $discount['unitPrice'] = -1 * $shippingObject->getShippingDiscountAmount() - $tax;
             $discount['totalPrice'] = -1 * $shippingObject->getShippingDiscountAmount() - $tax;
             $discount['taxPercent'] = 0;
             if (round($discount['tax'], 2) < 0) {
                 $discount['taxPercent'] = $article['taxPercent'];
             }
             $discount['discountId'] = 'SHIPPING';
         }
         $articles[] = $article;
         if ($shippingDiscountAmount > 0) {
             // only for sort reason
             $articles[] = $discount;
         }
     }
     return $articles;
 }