Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getProductTypes()
 {
     $productTypes = array();
     foreach ($this->productTypeConfig->getAll() as $productTypeData) {
         $productTypes[] = $this->productTypeBuilder->setName($productTypeData['name'])->setLabel($productTypeData['label'])->create();
     }
     return $productTypes;
 }
 public function testGetData()
 {
     $items = ['testProduct1', 'testProduct2'];
     $expectedData = ['totalRecords' => count($items), 'items' => $items];
     $this->configMock->expects($this->once())->method('getComposableTypes')->willReturn([self::ALLOWED_TYPE]);
     $this->collectionMock->expects($this->once())->method('isLoaded')->willReturn(false);
     $this->collectionMock->expects($this->once())->method('addAttributeToFilter')->with('type_id', [self::ALLOWED_TYPE]);
     $this->collectionMock->expects($this->once())->method('toArray')->willReturn($items);
     $this->collectionMock->expects($this->once())->method('getSize')->willReturn(count($items));
     $this->assertEquals($expectedData, $this->getModel()->getData());
 }
 /**
  * Initialize stock item
  *
  * @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
  * @param \Magento\Quote\Model\Quote\Item $quoteItem
  * @param int $qty
  *
  * @return \Magento\Framework\DataObject
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function initialize(\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem, \Magento\Quote\Model\Quote\Item $quoteItem, $qty)
 {
     /**
      * When we work with subitem
      */
     if ($quoteItem->getParentItem()) {
         $rowQty = $quoteItem->getParentItem()->getQty() * $qty;
         /**
          * we are using 0 because original qty was processed
          */
         $qtyForCheck = $this->quoteItemQtyList->getQty($quoteItem->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), 0);
     } else {
         $increaseQty = $quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty;
         $rowQty = $qty;
         $qtyForCheck = $this->quoteItemQtyList->getQty($quoteItem->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), $increaseQty);
     }
     $productTypeCustomOption = $quoteItem->getProduct()->getCustomOption('product_type');
     if ($productTypeCustomOption !== null) {
         // Check if product related to current item is a part of product that represents product set
         if ($this->typeConfig->isProductSet($productTypeCustomOption->getValue())) {
             $stockItem->setIsChildItem(true);
         }
     }
     $stockItem->setProductName($quoteItem->getProduct()->getName());
     $result = $this->stockState->checkQuoteItemQty($quoteItem->getProduct()->getId(), $rowQty, $qtyForCheck, $qty, $quoteItem->getProduct()->getStore()->getWebsiteId());
     if ($stockItem->hasIsChildItem()) {
         $stockItem->unsIsChildItem();
     }
     if ($result->getItemIsQtyDecimal() !== null) {
         $quoteItem->setIsQtyDecimal($result->getItemIsQtyDecimal());
         if ($quoteItem->getParentItem()) {
             $quoteItem->getParentItem()->setIsQtyDecimal($result->getItemIsQtyDecimal());
         }
     }
     /**
      * Just base (parent) item qty can be changed
      * qty of child products are declared just during add process
      * exception for updating also managed by product type
      */
     if ($result->getHasQtyOptionUpdate() && (!$quoteItem->getParentItem() || $quoteItem->getParentItem()->getProduct()->getTypeInstance()->getForceChildItemQtyChanges($quoteItem->getParentItem()->getProduct()))) {
         $quoteItem->setData('qty', $result->getOrigQty());
     }
     if ($result->getItemUseOldQty() !== null) {
         $quoteItem->setUseOldQty($result->getItemUseOldQty());
     }
     if ($result->getMessage() !== null) {
         $quoteItem->setMessage($result->getMessage());
     }
     if ($result->getItemBackorders() !== null) {
         $quoteItem->setBackorders($result->getItemBackorders());
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function getProductTypes()
 {
     if ($this->productTypes === null) {
         $productTypes = [];
         foreach ($this->productTypeConfig->getAll() as $productTypeData) {
             /** @var \Magento\Catalog\Api\Data\ProductTypeInterface $productType */
             $productType = $this->productTypeFactory->create();
             $productType->setName($productTypeData['name'])->setLabel($productTypeData['label']);
             $productTypes[] = $productType;
         }
         $this->productTypes = $productTypes;
     }
     return $this->productTypes;
 }
 /**
  * Get data
  *
  * @return array
  */
 public function getData()
 {
     if (!$this->getCollection()->isLoaded()) {
         $this->getCollection()->addAttributeToFilter('type_id', $this->config->getComposableTypes());
         if ($storeId = $this->request->getParam('current_store_id')) {
             /** @var StoreInterface $store */
             $store = $this->storeRepository->getById($storeId);
             $this->getCollection()->setStore($store);
         }
         $this->getCollection()->load();
     }
     $items = $this->getCollection()->toArray();
     return ['totalRecords' => $this->getCollection()->getSize(), 'items' => array_values($items)];
 }
Example #6
0
 /**
  * Add attributes to select
  *
  * @return $this
  */
 public function _initSelect()
 {
     parent::_initSelect();
     $allowedProductTypes = $this->_productTypeConfig->getComposableTypes();
     $this->addAttributeToSelect('name')->addAttributeToSelect('price')->addAttributeToSelect('sku')->addAttributeToSelect('weight')->addAttributeToSelect('image')->addFieldToFilter('type_id', $allowedProductTypes)->addFieldToFilter('entity_id', array('neq' => $this->getProduct()->getId()))->addFilterByRequiredOptions()->joinAttribute('name', 'catalog_product/name', 'entity_id', null, 'inner')->joinTable(array('cisi' => 'cataloginventory_stock_item'), 'product_id=entity_id', array('qty' => 'qty', 'inventory_in_stock' => 'is_in_stock'), null, 'left');
     return $this;
 }
 public function testGetIsQtyTypeIds()
 {
     $configAll = [1 => ['is_qty' => true], 2 => ['is_qty' => false], 3 => []];
     $resultAll = [1 => true, 2 => false, 3 => false];
     $resultTrue = [1 => true];
     $resultFalse = [2 => false, 3 => false];
     $this->config->expects($this->once())->method('getAll')->will($this->returnValue($configAll));
     $this->assertEquals($resultAll, $this->model->getIsQtyTypeIds());
     $this->assertEquals($resultTrue, $this->model->getIsQtyTypeIds(true));
     $this->assertEquals($resultFalse, $this->model->getIsQtyTypeIds(false));
 }
 /**
  * Automaticaly assign backend model to weee attributes
  *
  * @param   \Magento\Framework\Event\Observer $observer
  * @return  $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $backendModel = \Magento\Weee\Model\Attribute\Backend\Weee\Tax::getBackendModelName();
     /** @var $object \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */
     $object = $observer->getEvent()->getAttribute();
     if ($object->getFrontendInput() == 'weee') {
         $object->setBackendModel($backendModel);
         if (!$object->getApplyTo()) {
             $applyTo = [];
             foreach ($this->productType->getOptions() as $option) {
                 if ($this->productTypeConfig->isProductSet($option['value'])) {
                     continue;
                 }
                 $applyTo[] = $option['value'];
             }
             $object->setApplyTo($applyTo);
         }
     }
     return $this;
 }
Example #9
0
 /**
  * Get product types
  *
  * @return array
  */
 public function getTypes()
 {
     if (is_null($this->_types)) {
         $productTypes = $this->_config->getAll();
         foreach ($productTypes as $productTypeKey => $productTypeConfig) {
             $productTypes[$productTypeKey]['label'] = __($productTypeConfig['label']);
         }
         $this->_types = $productTypes;
     }
     return $this->_types;
 }
Example #10
0
 /**
  * Check is product available depending on final price or type set(configurable)
  *
  * @param bool $isInCatalog
  * @return bool
  */
 public function isPriceOrSetAvailable($isInCatalog)
 {
     if ($isInCatalog) {
         // Show PayPal shortcut on a product view page only if product has nonzero price
         /** @var $currentProduct \Magento\Catalog\Model\Product */
         $currentProduct = $this->_registry->registry('current_product');
         if (!is_null($currentProduct)) {
             $productPrice = (double) $currentProduct->getFinalPrice();
             if (empty($productPrice) && !$this->_productTypeConfig->isProductSet($currentProduct->getTypeId())) {
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * @param int|null $filter
  * @return array
  */
 public function getIsQtyTypeIds($filter = null)
 {
     if (null === $this->isQtyTypeIds) {
         $this->isQtyTypeIds = [];
         foreach ($this->config->getAll() as $typeId => $typeConfig) {
             $this->isQtyTypeIds[$typeId] = isset($typeConfig['is_qty']) ? $typeConfig['is_qty'] : false;
         }
     }
     $result = $this->isQtyTypeIds;
     if ($filter !== null) {
         foreach ($result as $key => $value) {
             if ($value !== $filter) {
                 unset($result[$key]);
             }
         }
     }
     return $result;
 }
Example #12
0
 public function testGetAllowedSelectionTypesIfTypesIsNotSet()
 {
     $configData = [];
     $this->config->expects($this->once())->method('getType')->with(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)->will($this->returnValue($configData));
     $this->assertEquals([], $this->helper->getAllowedSelectionTypes());
 }
Example #13
0
 /**
  * Returns whether Qty field is valid for this item
  *
  * @return bool
  */
 public function canHaveQty()
 {
     $product = $this->getProduct();
     return !$this->productTypeConfig->isProductSet($product->getTypeId());
 }
 /**
  * @inheritdoc
  */
 public function _initSelect()
 {
     parent::_initSelect();
     $this->setProduct($this->_getProduct())->addAttributeToSelect('name')->addAttributeToSelect('price')->addAttributeToSelect('sku')->addFilterByRequiredOptions()->addAttributeToFilter('type_id', $this->_config->getComposableTypes());
     return $this;
 }
Example #15
0
 /**
  * Array of SKU to array of super attribute values for all products.
  *
  * @param array $bunch - portion of products to process
  * @param array $newSku - imported variations list
  * @param array $oldSku - present variations list
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _loadSkuSuperAttributeValues($bunch, $newSku, $oldSku)
 {
     if ($this->_superAttributes) {
         $attrSetIdToName = $this->_entityModel->getAttrSetIdToName();
         $productIds = [];
         foreach ($bunch as $rowData) {
             $dataWithExtraVirtualRows = $this->_parseVariations($rowData);
             if (!empty($dataWithExtraVirtualRows)) {
                 array_unshift($dataWithExtraVirtualRows, $rowData);
             } else {
                 $dataWithExtraVirtualRows[] = $rowData;
             }
             foreach ($dataWithExtraVirtualRows as $data) {
                 if (!empty($data['_super_products_sku'])) {
                     if (isset($newSku[$data['_super_products_sku']])) {
                         $productIds[] = $newSku[$data['_super_products_sku']]['entity_id'];
                     } elseif (isset($oldSku[$data['_super_products_sku']])) {
                         $productIds[] = $oldSku[$data['_super_products_sku']]['entity_id'];
                     }
                 }
             }
         }
         foreach ($this->_productColFac->create()->addFieldToFilter('type_id', $this->_productTypesConfig->getComposableTypes())->addFieldToFilter('entity_id', ['in' => $productIds])->addAttributeToSelect(array_keys($this->_superAttributes)) as $product) {
             $attrSetName = $attrSetIdToName[$product->getAttributeSetId()];
             $data = array_intersect_key($product->getData(), $this->_superAttributes);
             foreach ($data as $attrCode => $value) {
                 $attrId = $this->_superAttributes[$attrCode]['id'];
                 $this->_skuSuperAttributeValues[$attrSetName][$product->getId()][$attrId] = $value;
             }
         }
     }
     return $this;
 }
Example #16
0
 /**
  * Check whether quantity field should be rendered
  *
  * @return bool
  */
 public function shouldRenderQuantity()
 {
     return !$this->productTypeConfig->isProductSet($this->getProduct()->getTypeId());
 }
Example #17
0
 /**
  * Get taxable product types
  *
  * @return array
  */
 public function getTaxableItems()
 {
     return $this->productTypeConfig->filter('taxable');
 }
Example #18
0
 /**
  * Returns whether this qty field must be inactive
  *
  * @param \Magento\Framework\DataObject $row
  * @return bool
  */
 protected function _isInactive($row)
 {
     return $this->typeConfig->isProductSet($row->getTypeId());
 }
Example #19
0
 /**
  * Retrieve array of allowed product types for bundle selection product
  *
  * @return array
  */
 public function getAllowedSelectionTypes()
 {
     $configData = $this->config->getType(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
     return isset($configData['allowed_selection_types']) ? $configData['allowed_selection_types'] : [];
 }
Example #20
0
 /**
  * Retrieve array of allowed product types for bundle selection product
  *
  * @return array
  */
 public function getAllowedSelectionTypes()
 {
     $configData = $this->_config->getType('bundle');
     return isset($configData['allowed_selection_types']) ? $configData['allowed_selection_types'] : array();
 }