Esempio n. 1
1
 private function initializeQuoteItems()
 {
     foreach ($this->proxyOrder->getItems() as $item) {
         $this->clearQuoteItemsCache();
         /** @var $quoteItemBuilder Ess_M2ePro_Model_Magento_Quote_Item */
         $quoteItemBuilder = Mage::getModel('M2ePro/Magento_Quote_Item');
         $quoteItemBuilder->init($this->quote, $item);
         $product = $quoteItemBuilder->getProduct();
         $request = $quoteItemBuilder->getRequest();
         // ----------------------------
         $productOriginalPrice = (double) $product->getPrice();
         $price = $item->getBasePrice();
         $product->setPrice($price);
         $product->setSpecialPrice($price);
         // ----------------------------
         // see Mage_Sales_Model_Observer::substractQtyFromQuotes
         $this->quote->setItemsCount($this->quote->getItemsCount() + 1);
         $this->quote->setItemsQty((double) $this->quote->getItemsQty() + $request->getQty());
         $result = $this->quote->addProduct($product, $request);
         if (is_string($result)) {
             throw new Exception($result);
         }
         $quoteItem = $this->quote->getItemByProduct($product);
         if ($quoteItem !== false) {
             $weight = $product->getTypeInstance()->getWeight();
             if ($product->isConfigurable()) {
                 // hack: for child product weight was not load
                 $simpleProductId = $product->getCustomOption('simple_product')->getProductId();
                 $weight = Mage::getResourceModel('catalog/product')->getAttributeRawValue($simpleProductId, 'weight', 0);
             }
             $quoteItem->setStoreId($this->quote->getStoreId());
             $quoteItem->setOriginalCustomPrice($item->getPrice());
             $quoteItem->setOriginalPrice($productOriginalPrice);
             $quoteItem->setBaseOriginalPrice($productOriginalPrice);
             $quoteItem->setWeight($weight);
             $quoteItem->setNoDiscount(1);
             $giftMessageId = $quoteItemBuilder->getGiftMessageId();
             if (!empty($giftMessageId)) {
                 $quoteItem->setGiftMessageId($giftMessageId);
             }
             $quoteItem->setAdditionalData($quoteItemBuilder->getAdditionalData($quoteItem));
         }
     }
 }
Esempio n. 2
0
 /**
  * Check if quote meets the minimun quantity
  * of total items for a specific customer
  *
  * @todo   Change to more meaningful name
  *
  * @param  Mage_Sales_Model_Quote       $quote
  * @param  Mage_Customer_Model_Customer $customer
  * @return int|false
  */
 public function minimunOrderQty(Mage_Sales_Model_Quote $quote, Mage_Customer_Model_Customer $customer)
 {
     $minQtyForCustomer = $this->getConfigValue($customer->getGroupId());
     if ($quote->getItemsQty() < $minQtyForCustomer && $quote->getItemsQty() !== 0) {
         return $minQtyForCustomer;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Initialize quote items objects
  *
  * @throws Exception
  */
 private function initializeQuoteItems()
 {
     foreach ($this->proxyOrder->getItems() as $item) {
         $this->clearQuoteItemsCache();
         /** @var $quoteItemBuilder Ess_M2ePro_Model_Magento_Quote_Item */
         $quoteItemBuilder = Mage::getModel('M2ePro/Magento_Quote_Item');
         $quoteItemBuilder->init($this->quote, $item);
         $product = $quoteItemBuilder->getProduct();
         $request = $quoteItemBuilder->getRequest();
         // see Mage_Sales_Model_Observer::substractQtyFromQuotes
         $this->quote->setItemsCount($this->quote->getItemsCount() + 1);
         $this->quote->setItemsQty((double) $this->quote->getItemsQty() + $request->getQty());
         $result = $this->quote->addProduct($product, $request);
         if (is_string($result)) {
             throw new Exception($result);
         }
         $quoteItem = $this->quote->getItemByProduct($product);
         if ($quoteItem !== false) {
             $quoteItem->setOriginalCustomPrice($item->getPrice());
             $quoteItem->setNoDiscount(1);
             $quoteItem->setGiftMessageId($quoteItemBuilder->getGiftMessageId());
             $quoteItem->setAdditionalData($quoteItemBuilder->getAdditionalData($quoteItem));
         }
     }
 }
Esempio n. 4
0
 /**
  * @magentoDataFixture Mage/Catalog/_files/product_virtual.php
  * @magentoDataFixture Mage/Sales/_files/quote.php
  */
 public function testCollectTotalsWithVirtual()
 {
     $quote = new Mage_Sales_Model_Quote();
     $quote->load('test01', 'reserved_order_id');
     $product = new Mage_Catalog_Model_Product();
     $product->load(21);
     $quote->addProduct($product);
     $quote->collectTotals();
     $this->assertEquals(2, $quote->getItemsQty());
     $this->assertEquals(1, $quote->getVirtualItemsQty());
     $this->assertEquals(20, $quote->getGrandTotal());
     $this->assertEquals(20, $quote->getBaseGrandTotal());
 }
Esempio n. 5
0
 /**
  * Initialize quote items objects
  *
  * @throws Exception
  */
 private function initializeQuoteItems()
 {
     foreach ($this->proxyOrder->getItems() as $item) {
         /** @var $quoteItemBuilder Ess_M2ePro_Model_Magento_Quote_Item */
         $quoteItemBuilder = Mage::getModel('M2ePro/Magento_Quote_Item');
         $quoteItemBuilder->setQuoteBuilder($this)->setProxyItem($item);
         $product = $quoteItemBuilder->getProduct();
         $request = $quoteItemBuilder->getRequest();
         $this->quote->setItemsCount($this->quote->getItemsCount() + 1);
         $this->quote->setItemsQty((double) $this->quote->getItemsQty() + $request->getQty());
         $result = $this->quote->addProduct($product, $request);
         if (is_string($result)) {
             throw new Exception($result);
         }
         $quoteItem = $this->quote->getItemByProduct($product);
         if ($quoteItem !== false) {
             $quoteItem->setOriginalCustomPrice($quoteItemBuilder->getChannelCurrencyPrice());
             $quoteItem->setNoDiscount(1);
             $quoteItem->setGiftMessageId($quoteItemBuilder->getGiftMessageId());
             $quoteItem->setAdditionalData($quoteItemBuilder->getAdditionalData($quoteItem));
         }
     }
 }
 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());
     }
 }