Example #1
0
 public function testGetTotalModelsSortingSubroutine()
 {
     $total = $this->getMockForAbstractClass('Magento\\Sales\\Model\\Order\\Total\\AbstractTotal');
     $this->salesConfig->expects($this->once())->method('getGroupTotals')->will($this->returnValue(['some_code' => ['instance' => 'Magento\\Sales\\Model\\Order\\Total\\AbstractTotal', 'sort_order' => 1903], 'other_code' => ['instance' => 'Magento\\Sales\\Model\\Order\\Total\\AbstractTotal', 'sort_order' => 1112], 'equal_order' => ['instance' => 'Magento\\Sales\\Model\\Order\\Total\\AbstractTotal', 'sort_order' => 1112], 'big_order' => ['instance' => 'Magento\\Sales\\Model\\Order\\Total\\AbstractTotal', 'sort_order' => 3000], 'no_order' => ['instance' => 'Magento\\Sales\\Model\\Order\\Total\\AbstractTotal']]));
     $this->orderTotalFactory->expects($this->any())->method('create')->with('Magento\\Sales\\Model\\Order\\Total\\AbstractTotal')->will($this->returnValue($total));
     $this->assertSame(['no_order' => $total, 'equal_order' => $total, 'other_code' => $total, 'some_code' => $total, 'big_order' => $total], $this->object->getTotalModels());
 }
Example #2
0
 public function testGetAvailableProductTypes()
 {
     $productTypes = ['simple'];
     $this->configDataMock->expects($this->once())->method('get')->with($this->equalTo('order/available_product_types'))->will($this->returnValue($productTypes));
     $result = $this->model->getAvailableProductTypes();
     $this->assertEquals($productTypes, $result);
 }
Example #3
0
 /**
  * Initialize total models configuration and objects
  *
  * @return $this
  */
 protected function _initModels()
 {
     $totals = $this->_salesConfig->getGroupTotals($this->_configSection, $this->_configGroup);
     foreach ($totals as $totalCode => $totalConfig) {
         $class = $totalConfig['instance'];
         if (!empty($class)) {
             $this->_models[$totalCode] = $this->_initModelInstance($class, $totalCode, $totalConfig);
         }
     }
     return $this;
 }
Example #4
0
 /**
  * Prepare collection to be displayed in the grid
  *
  * @return $this
  */
 protected function _prepareCollection()
 {
     $attributes = $this->_catalogConfig->getProductAttributes();
     /* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
     $collection = $this->_productFactory->create()->getCollection();
     $collection->setStore($this->getStore())->addAttributeToSelect($attributes)->addAttributeToSelect('sku')->addStoreFilter()->addAttributeToFilter('type_id', $this->_salesConfig->getAvailableProductTypes())->addAttributeToSelect('gift_message_available');
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
Example #5
0
 /**
  * @param string $code
  * @return BlockInterface
  */
 protected function _getTotalRenderer($code)
 {
     $blockName = $code . '_total_renderer';
     $block = $this->getLayout()->getBlock($blockName);
     if (!$block) {
         $renderer = $this->_salesConfig->getTotalsRenderer('quote', 'totals', $code);
         if (!empty($renderer)) {
             $block = $renderer;
         } else {
             $block = $this->_defaultRenderer;
         }
         $block = $this->getLayout()->createBlock($block, $blockName);
     }
     /**
      * Transfer totals to renderer
      */
     $block->setTotals($this->getTotals());
     return $block;
 }
Example #6
0
 /**
  * @param string $itemKey
  * @param string $type
  * @param int $calledTimes
  * @dataProvider applySalableProductTypesFilterDataProvider
  */
 public function testApplySalableProductTypesFilter($itemKey, $type, $calledTimes)
 {
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $productMock->expects($this->any())->method('getTypeId')->will($this->returnValue($type));
     $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->setMethods(['__wakeup', 'getProductType'])->getMock();
     $orderMock->expects($this->any())->method('getProductType')->will($this->returnValue($type));
     $quoteMock = $this->getMockBuilder('Magento\\Sales\\Model\\Quote\\Item')->disableOriginalConstructor()->getMock();
     $quoteMock->expects($this->any())->method('getProductType')->will($this->returnValue($type));
     $items = ['product' => $productMock, 'order' => $orderMock, 'quote' => $quoteMock, 'other' => 'other'];
     $collectionMock = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Db\\Collection\\AbstractCollection')->disableOriginalConstructor()->getMock();
     $collectionMock->expects($this->any())->method('getItems')->will($this->returnValue([$items[$itemKey]]));
     $collectionMock->expects($this->exactly($calledTimes))->method('removeItemByKey');
     $this->salesConfigMock->expects($this->any())->method('getAvailableProductTypes')->will($this->returnValue(['validProductType']));
     $this->adminHelper->applySalableProductTypesFilter($collectionMock);
 }
Example #7
0
 /**
  * Filter collection by removing not available product types
  *
  * @param \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection $collection
  * @return \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection
  */
 public function applySalableProductTypesFilter($collection)
 {
     $productTypes = $this->_salesConfig->getAvailableProductTypes();
     foreach ($collection->getItems() as $key => $item) {
         if ($item instanceof \Magento\Catalog\Model\Product) {
             $type = $item->getTypeId();
         } elseif ($item instanceof \Magento\Sales\Model\Order\Item) {
             $type = $item->getProductType();
         } elseif ($item instanceof \Magento\Quote\Model\Quote\Item) {
             $type = $item->getProductType();
         } else {
             $type = '';
         }
         if (!in_array($type, $productTypes)) {
             $collection->removeItemByKey($key);
         }
     }
     return $collection;
 }
 /**
  * Retrieve all items
  *
  * @return array
  */
 public function getItems()
 {
     $items = array();
     $collection = $this->getItemCollection();
     if ($collection) {
         $productTypes = $this->_salesConfig->getAvailableProductTypes();
         if (is_array($collection)) {
             $items = $collection;
         } else {
             $items = $collection->getItems();
         }
         /*
          * Filtering items by allowed product type
          */
         foreach ($items as $key => $item) {
             if ($item instanceof \Magento\Catalog\Model\Product) {
                 $type = $item->getTypeId();
             } else {
                 if ($item instanceof \Magento\Sales\Model\Order\Item) {
                     $type = $item->getProductType();
                 } else {
                     if ($item instanceof \Magento\Sales\Model\Quote\Item) {
                         $type = $item->getProductType();
                     } else {
                         $type = '';
                         // Maybe some item, that can give us product via getProduct()
                         if ($item instanceof \Magento\Framework\Object || method_exists($item, 'getProduct')) {
                             $product = $item->getProduct();
                             if ($product && $product instanceof \Magento\Catalog\Model\Product) {
                                 $type = $product->getTypeId();
                             }
                         }
                     }
                 }
             }
             if (!in_array($type, $productTypes)) {
                 unset($items[$key]);
             }
         }
     }
     return $items;
 }
Example #9
0
 /**
  * Initialize creation data from existing order
  *
  * @param \Magento\Sales\Model\Order $order
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function initFromOrder(\Magento\Sales\Model\Order $order)
 {
     $session = $this->getSession();
     $session->setData($order->getReordered() ? 'reordered' : 'order_id', $order->getId());
     $session->setCurrencyId($order->getOrderCurrencyCode());
     /* Check if we edit guest order */
     $session->setCustomerId($order->getCustomerId() ?: false);
     $session->setStoreId($order->getStoreId());
     /* Initialize catalog rule data with new session values */
     $this->initRuleData();
     foreach ($order->getItemsCollection($this->_salesConfig->getAvailableProductTypes(), true) as $orderItem) {
         /* @var $orderItem \Magento\Sales\Model\Order\Item */
         if (!$orderItem->getParentItem()) {
             $qty = $orderItem->getQtyOrdered();
             if (!$order->getReordered()) {
                 $qty -= max($orderItem->getQtyShipped(), $orderItem->getQtyInvoiced());
             }
             if ($qty > 0) {
                 $item = $this->initFromOrderItem($orderItem, $qty);
                 if (is_string($item)) {
                     throw new \Magento\Framework\Exception\LocalizedException(__($item));
                 }
             }
         }
     }
     $shippingAddress = $order->getShippingAddress();
     if ($shippingAddress) {
         $addressDiff = array_diff_assoc($shippingAddress->getData(), $order->getBillingAddress()->getData());
         unset($addressDiff['address_type'], $addressDiff['entity_id']);
         $shippingAddress->setSameAsBilling(empty($addressDiff));
     }
     $this->_initBillingAddressFromOrder($order);
     $this->_initShippingAddressFromOrder($order);
     $quote = $this->getQuote();
     if (!$quote->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
         $this->setShippingAsBilling(1);
     }
     $this->setShippingMethod($order->getShippingMethod());
     $quote->getShippingAddress()->setShippingDescription($order->getShippingDescription());
     $paymentData = $order->getPayment()->getData();
     unset($paymentData['cc_type'], $paymentData['cc_last_4']);
     unset($paymentData['cc_exp_month'], $paymentData['cc_exp_year']);
     $quote->getPayment()->addData($paymentData);
     $orderCouponCode = $order->getCouponCode();
     if ($orderCouponCode) {
         $quote->setCouponCode($orderCouponCode);
     }
     if ($quote->getCouponCode()) {
         $quote->collectTotals();
     }
     $this->_objectCopyService->copyFieldsetToTarget('sales_copy_order', 'to_edit', $order, $quote);
     $this->_eventManager->dispatch('sales_convert_order_to_quote', ['order' => $order, 'quote' => $quote]);
     if (!$order->getCustomerId()) {
         $quote->setCustomerIsGuest(true);
     }
     if ($session->getUseOldShippingMethod(true)) {
         /*
          * if we are making reorder or editing old order
          * we need to show old shipping as preselected
          * so for this we need to collect shipping rates
          */
         $this->collectShippingRates();
     } else {
         /*
          * if we are creating new order then we don't need to collect
          * shipping rates before customer hit appropriate button
          */
         $this->collectRates();
     }
     $this->quoteRepository->save($quote);
     return $this;
 }
Example #10
0
 /**
  * @param \Magento\Sales\Model\Order $order
  * @return array
  */
 protected function getNonEditableTypes($order)
 {
     return array_keys($this->getOrder()->getResource()->aggregateProductsByTypes($order->getId(), $this->_salesConfig->getAvailableProductTypes(), false));
 }