Example #1
0
 /**
  * {@inheritdoc}
  */
 public function install(array $fixtures)
 {
     $this->configWriter->save('sales/msrp/enabled', 1);
     foreach ($fixtures as $fileName) {
         $fileName = $this->fixtureManager->getFixture($fileName);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fileName);
         $header = array_shift($rows);
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             $row = $data;
             $productId = $this->getProductIdBySku($row['sku']);
             if (!$productId) {
                 continue;
             }
             /** @var \Magento\Catalog\Model\Product $product */
             $product = $this->productCollection->getItemById($productId);
             $product->setMsrpDisplayActualPriceType(Type::TYPE_ON_GESTURE);
             if (!empty($row['msrp'])) {
                 $price = $row['msrp'];
             } else {
                 $price = $product->getPrice() * 1.1;
             }
             $product->setMsrp($price);
             $product->save();
         }
     }
 }
 public function testGetCollection()
 {
     $this->collectionMock->expects($this->once())->method('addAttributeToFilter');
     $this->productLinkRepositoryMock->expects($this->once())->method('getList')->willReturn([]);
     $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturn(1);
     $this->assertInstanceOf(Collection::class, $this->getModel()->getCollection());
 }
 /**
  * Set up
  */
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->rowCustomizerMock = $this->objectManagerHelper->getObject('\\Magento\\BundleImportExport\\Model\\Export\\RowCustomizer');
     $this->productResourceCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addAttributeToFilter', 'getIterator'], [], '', false);
     $this->product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'getPriceType', 'getSkuType', 'getPriceView', 'getWeightType', 'getTypeInstance', 'getOptionsCollection', 'getSelectionsCollection'], [], '', false);
     $this->product->expects($this->any())->method('getId')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceType')->willReturn(1);
     $this->product->expects($this->any())->method('getSkuType')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceView')->willReturn(1);
     $this->product->expects($this->any())->method('getWeightType')->willReturn(1);
     $this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
     $this->optionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', ['setOrder', 'getIterator'], [], '', false);
     $this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
     $this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
     $this->option = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getId', 'getTitle', 'getType', 'getRequired'], [], '', false);
     $this->option->expects($this->any())->method('getId')->willReturn(1);
     $this->option->expects($this->any())->method('getTitle')->willReturn('title');
     $this->option->expects($this->any())->method('getType')->willReturn(1);
     $this->option->expects($this->any())->method('getRequired')->willReturn(1);
     $this->optionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->option])));
     $this->selection = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'], [], '', false);
     $this->selection->expects($this->any())->method('getSku')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceValue')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
     $this->selectionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', ['getIterator', 'addAttributeToSort'], [], '', false);
     $this->selectionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->selection])));
     $this->selectionsCollection->expects($this->any())->method('addAttributeToSort')->willReturnSelf();
     $this->product->expects($this->any())->method('getSelectionsCollection')->willReturn($this->selectionsCollection);
     $this->productResourceCollection->expects($this->any())->method('addAttributeToFilter')->willReturnSelf();
     $this->productResourceCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->product])));
 }
Example #4
0
 /**
  * Make collection not to load products that are in specified quote
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @param int $quoteId
  * @return $this
  */
 public function addExcludeProductFilter($collection, $quoteId)
 {
     $connection = $this->getConnection();
     $exclusionSelect = $connection->select()->from($this->getTable('quote_item'), ['product_id'])->where('quote_id = ?', $quoteId);
     $condition = $connection->prepareSqlCondition('e.entity_id', ['nin' => $exclusionSelect]);
     $collection->getSelect()->where($condition);
     return $this;
 }
Example #5
0
 /**
  * Collect validated attributes for Product Collection
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
  * @return $this
  */
 public function collectValidatedAttributes($productCollection)
 {
     $alias = array_keys($productCollection->getSelect()->getPart('from'))[0];
     foreach ($this->getConditions() as $condition) {
         $condition->setData('attribute', $alias . '.' . $condition->getData('attribute'));
         $condition->addToCollection($productCollection);
     }
     return $this;
 }
Example #6
0
 /**
  * {@inheritDoc}
  */
 protected function addFilterByAttributes(ProductCollection $productCollection, array $attributes)
 {
     foreach ($attributes as $code => $option) {
         if (!is_array($option)) {
             $option = [$option];
         }
         $productCollection->addAttributeToFilter($code, ['in' => $option]);
     }
 }
 /**
  * Execute per test cleanup
  */
 public function tearDown()
 {
     /** @var \Magento\Framework\Registry $registry */
     $registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Registry');
     $registry->unregister('isSecureArea');
     $registry->register('isSecureArea', true);
     $this->productCollection->addFieldToFilter('entity_id', ['in' => [10, 11, 12]])->delete();
     unset($this->productCollection);
     $registry->unregister('isSecureArea');
     $registry->register('isSecureArea', false);
 }
 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());
 }
Example #9
0
 public function testAddProductCategoriesFilter()
 {
     $condition = ['in' => [1, 2]];
     $values = [1, 2];
     $conditionType = 'nin';
     $preparedSql = "category_id IN(1,2)";
     $tableName = "catalog_category_product";
     $this->connectionMock->expects($this->any())->method('getId')->willReturn(1);
     $this->connectionMock->expects($this->exactly(2))->method('prepareSqlCondition')->withConsecutive(['cat.category_id', $condition], ['e.entity_id', [$conditionType => $this->selectMock]])->willReturnOnConsecutiveCalls($preparedSql, 'e.entity_id IN (1,2)');
     $this->selectMock->expects($this->once())->method('from')->with(['cat' => $tableName], 'cat.product_id')->willReturnSelf();
     $this->selectMock->expects($this->exactly(2))->method('where')->withConsecutive([$preparedSql], ['e.entity_id IN (1,2)'])->willReturnSelf();
     $this->collection->addCategoriesFilter([$conditionType => $values]);
 }
 /**
  * Replace WHERE-filtering by HAVING-filtering.
  *
  * @param \Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFilterToCollection $subject
  * @param \Closure $proceed
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @param $field
  * @param null $condition
  */
 public function aroundAddFilter(\Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFilterToCollection $subject, \Closure $proceed, \Magento\Catalog\Model\ResourceModel\Product\Collection $collection, $field, $condition = null)
 {
     /* skip identical conditions () */
     $regKey = print_r($condition, true);
     if (!isset($this->_regCond[$regKey])) {
         $conn = $collection->getConnection();
         $select = $collection->getSelect();
         $equation = $this->_repoModifierProductGFrid->getEquationQty();
         $prepared = $conn->prepareSqlCondition($equation, $condition);
         $select->having($prepared);
         $this->_regCond[$regKey] = true;
     }
     return;
 }
 /**
  * Replace default stock id in the where clause by stock id corresponded with store id.
  *
  * @param \Magento\CatalogInventory\Model\ResourceModel\Stock\Status $subject
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $result
  * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
  */
 public function afterAddStockDataToCollection(\Magento\CatalogInventory\Model\ResourceModel\Stock\Status $subject, \Magento\Catalog\Model\ResourceModel\Product\Collection $result)
 {
     /** @var \Magento\Framework\Db\Select $select */
     $select = $result->getSelect();
     $from = $select->getPart('from');
     $join = $from['stock_status_index'];
     $cond = $join['joinCondition'];
     $stockId = $this->_manStock->getCurrentStockId();
     $fixed = str_replace('.stock_id = 1', '.stock_id = ' . $stockId, $cond);
     $join['joinCondition'] = $fixed;
     $from['stock_status_index'] = $join;
     $select->setPart('from', $from);
     return $result;
 }
Example #12
0
 /**
  * @return $this
  */
 protected function _prepareData()
 {
     $product = $this->_coreRegistry->registry('product');
     /* @var $product \Magento\Catalog\Model\Product */
     $this->_itemCollection = $product->getRelatedProductCollection()->addAttributeToSelect('required_options')->setPositionOrder()->addStoreFilter();
     if ($this->moduleManager->isEnabled('Magento_Checkout')) {
         $this->_addProductAttributesAndPrices($this->_itemCollection);
     }
     $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $this->_itemCollection->load();
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }
 public function testFindAttributeIdsByProductIds()
 {
     $productIds = [1, 2, 3];
     $attributeSetIds = [3, 4, 6];
     $select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
     $select->expects($this->once())->method('reset')->with(Select::COLUMNS)->willReturnSelf();
     $select->expects($this->once())->method('columns')->with(ProductInterface::ATTRIBUTE_SET_ID)->willReturnSelf();
     $select->expects($this->once())->method('where')->with('entity_id IN (?)', $productIds)->willReturnSelf();
     $select->expects($this->once())->method('group')->with(ProductInterface::ATTRIBUTE_SET_ID)->willReturnSelf();
     $connection = $this->getMock(AdapterInterface::class);
     $connection->expects($this->once())->method('fetchCol')->with($select)->willReturn($attributeSetIds);
     $this->productCollection->expects($this->once())->method('getSelect')->willReturn($select);
     $this->productCollection->expects($this->once())->method('getConnection')->willReturn($connection);
     $this->assertEquals($attributeSetIds, $this->attributeSetFinder->findAttributeSetIdsByProductIds($productIds));
 }
 /**
  * Premare block data
  * @return $this
  */
 protected function _prepareCollection()
 {
     $post = $this->_coreRegistry->registry('current_blog_post');
     $this->_itemCollection = $this->_productCollectionFactory->create()->addAttributeToSelect('required_options')->addStoreFilter()->addAttributeToFilter('entity_id', array('in' => $post->getRelatedProductIds() ?: array(0)));
     if ($this->_moduleManager->isEnabled('Magento_Checkout')) {
         $this->_addProductAttributesAndPrices($this->_itemCollection);
     }
     $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $this->_itemCollection->setPageSize((int) $this->_scopeConfig->getValue('mfblog/post_view/related_products/number_of_products', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
     $this->_itemCollection->load();
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }
Example #15
0
 /**
  * Premare block data
  * @return $this
  */
 protected function _prepareCollection()
 {
     $post = $this->getPost();
     $this->_itemCollection = $post->getRelatedProducts()->addAttributeToSelect('required_options');
     if ($this->_moduleManager->isEnabled('Magento_Checkout')) {
         $this->_addProductAttributesAndPrices($this->_itemCollection);
     }
     $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $this->_itemCollection->setPageSize((int) $this->_scopeConfig->getValue('mfblog/post_view/related_products/number_of_products', \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
     $this->_itemCollection->getSelect()->order('rl.position', 'ASC');
     $this->_itemCollection->load();
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }
Example #16
0
 /**
  * Add attribute to sort
  *
  * @param string $attribute
  * @param string $dir
  * @return $this|\Magento\Catalog\Model\ResourceModel\Product\Collection
  */
 public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC)
 {
     if (in_array($attribute, ['review_cnt', 'last_created', 'avg_rating', 'avg_rating_approved'])) {
         $this->getSelect()->order($attribute . ' ' . $dir);
         return $this;
     }
     return parent::addAttributeToSort($attribute, $dir);
 }
Example #17
0
 protected function addfilterByParent()
 {
     $this->productCollectionMock->method('getTable')->with('catalog_product_relation')->willReturn('catalog_product_relation');
     $zendDbSelectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->productCollectionMock->method('getSelect')->willReturn($zendDbSelectMock);
     $zendDbSelectMock->method('join')->willReturn($zendDbSelectMock);
     $zendDbSelectMock->method('where')->willReturn($zendDbSelectMock);
 }
 protected function _initConfigurableData()
 {
     $productIds = [1, 2, 3];
     $productAttributesOptions = [[['pricing_is_percent' => true, 'sku' => '_sku_', 'attribute_code' => 'code_of_attribute', 'option_title' => 'Option Title', 'pricing_value' => 112345, 'super_attribute_label' => 'Super attribute label'], ['pricing_is_percent' => false, 'sku' => '_sku_', 'attribute_code' => 'code_of_attribute', 'option_title' => 'Option Title', 'pricing_value' => 212345, 'super_attribute_label' => ''], ['pricing_is_percent' => false, 'sku' => '_sku_2', 'attribute_code' => 'code_of_attribute_2', 'option_title' => 'Option Title 2', 'pricing_value' => 312345, 'super_attribute_label' => 'Super attribute label 2']]];
     $expectedConfigurableData = $this->getExpectedConfigurableData();
     $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId', 'getTypeInstance', '__wakeup'], [], '', false);
     $productMock->expects($this->any())->method('getId')->will($this->returnValue($this->initiatedProductId));
     $typeInstanceMock = $this->getMock('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', [], [], '', false);
     $typeInstanceMock->expects($this->any())->method('getConfigurableOptions')->will($this->returnValue($productAttributesOptions));
     $productMock->expects($this->any())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock));
     $this->_collectionMock->expects($this->at(0))->method('addAttributeToFilter')->with('entity_id', ['in' => $productIds])->will($this->returnSelf());
     $this->_collectionMock->expects($this->at(1))->method('addAttributeToFilter')->with('type_id', ['eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE])->will($this->returnSelf());
     $this->_collectionMock->expects($this->at(2))->method('fetchItem')->will($this->returnValue($productMock));
     $this->_collectionMock->expects($this->at(3))->method('fetchItem')->will($this->returnValue(false));
     $this->_model->prepareData($this->_collectionMock, $productIds);
     $configurableData = $this->getPropertyValue($this->_model, 'configurableData');
     $this->assertEquals($expectedConfigurableData, $configurableData);
 }
Example #19
0
 /**
  * @return $this
  */
 protected function _prepareData()
 {
     $product = $this->_coreRegistry->registry('product');
     /* @var $product \Magento\Catalog\Model\Product */
     $this->_itemCollection = $product->getUpSellProductCollection()->setPositionOrder()->addStoreFilter();
     if ($this->moduleManager->isEnabled('Magento_Checkout')) {
         $this->_addProductAttributesAndPrices($this->_itemCollection);
     }
     $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $this->_itemCollection->load();
     /**
      * Updating collection with desired items
      */
     $this->_eventManager->dispatch('catalog_product_upsell', ['product' => $product, 'collection' => $this->_itemCollection, 'limit' => null]);
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }
Example #20
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/products.php
  * @magentoAppIsolation enabled
  */
 public function testAddPriceDataOnSave()
 {
     $this->processor->getIndexer()->setScheduled(false);
     $this->assertFalse($this->processor->getIndexer()->isScheduled());
     $productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Api\\ProductRepositoryInterface');
     /** @var \Magento\Catalog\Api\Data\ProductInterface $product */
     $product = $productRepository->get('simple');
     $this->assertNotEquals(15, $product->getPrice());
     $product->setPrice(15);
     $productRepository->save($product);
     $this->collection->addPriceData(0, 1);
     $this->collection->load();
     /** @var \Magento\Catalog\Api\Data\ProductInterface[] $product */
     $items = $this->collection->getItems();
     /** @var \Magento\Catalog\Api\Data\ProductInterface $product */
     $product = reset($items);
     $this->assertCount(2, $items);
     $this->assertEquals(15, $product->getPrice());
 }
 /**
  * Add filtering
  *
  * @param string $field
  * @param null|string $condition
  * @return $this
  */
 public function addFieldToFilter($field, $condition = null)
 {
     if ($field == 'link_title') {
         $conditionSql = $this->_getConditionSql('l.title', $condition);
         $this->getSelect()->where($conditionSql);
     } else {
         parent::addFieldToFilter($field, $condition);
     }
     return $this;
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     parent::setUp();
     $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $item = new \Magento\Framework\DataObject(['id' => 1, 'attribute_set_name' => 'Default', '_attribute_set' => 'Default']);
     $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([$item]));
     $this->attrCollectionFactory = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $this->attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Collection', ['setAttributeSetFilter'], [], '', false);
     $superAttributes = [];
     foreach ($this->_getSuperAttributes() as $superAttribute) {
         $item = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['isStatic'], $superAttribute, '', false);
         $item->setData($superAttribute);
         $item->method('isStatic')->will($this->returnValue(false));
         $superAttributes[] = $item;
     }
     $this->attrCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->attrCollection));
     $this->attrCollection->expects($this->any())->method('setAttributeSetFilter')->will($this->returnValue($superAttributes));
     $this->_entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getNewSku', 'getOldSku', 'getNextBunch', 'isRowAllowedToImport', 'getConnection', 'getAttrSetIdToName', 'getErrorAggregator', 'getAttributeOptions'], [], '', false);
     $this->_entityModel->method('getErrorAggregator')->willReturn($this->getErrorAggregatorObject());
     $this->params = [0 => $this->_entityModel, 1 => 'configurable'];
     $this->_connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto'], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where', 'joinLeft', 'getConnection'], [], '', false);
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $this->_connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $this->select->expects($this->any())->method('getConnection')->willReturn($connectionMock);
     $this->_connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf();
     $this->_connection->expects($this->any())->method('delete')->willReturnSelf();
     $this->_connection->expects($this->any())->method('quoteInto')->willReturn('');
     $this->_connection->expects($this->any())->method('fetchAll')->will($this->returnValue([]));
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName'));
     $this->_entityModel->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connection));
     $this->productCollectionFactory = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->productCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addFieldToFilter', 'addAttributeToSelect'], [], '', false);
     $products = [];
     $testProducts = [['id' => 1, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1], ['id' => 2, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1], ['id' => 20, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1]];
     foreach ($testProducts as $product) {
         $item = $this->getMock('\\Magento\\Framework\\DataObject', ['getAttributeSetId'], [], '', false);
         $item->setData($product);
         $item->expects($this->any())->method('getAttributeSetId')->willReturn(4);
         $products[] = $item;
     }
     $this->productCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->productCollection));
     $this->productCollection->expects($this->any())->method('addFieldToFilter')->will($this->returnValue($this->productCollection));
     $this->productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnValue($products));
     $this->_entityModel->expects($this->any())->method('getAttributeOptions')->will($this->returnValue(['attr2val1' => '1', 'attr2val2' => '2', 'attr2val3' => '3', 'testattr3v1' => '4', 'testattr30v1' => '4', 'testattr3v2' => '5', 'testattr3v3' => '6']));
     $this->configurable = $this->objectManagerHelper->getObject('Magento\\ConfigurableImportExport\\Model\\Import\\Product\\Type\\Configurable', ['attrSetColFac' => $this->setCollectionFactory, 'prodAttrColFac' => $this->attrCollectionFactory, 'params' => $this->params, 'resource' => $this->resource, 'productColFac' => $this->productCollectionFactory]);
 }
Example #23
0
 /**
  * Separate query for product and order data
  *
  * @param array $productIds
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function getProductData(array $productIds)
 {
     $productConnection = $this->productResource->getConnection();
     $productAttrName = $this->productResource->getAttribute('name');
     $productAttrNameId = (int) $productAttrName->getAttributeId();
     $productAttrPrice = $this->productResource->getAttribute('price');
     $productAttrPriceId = (int) $productAttrPrice->getAttributeId();
     $select = clone $this->productResource->getSelect();
     $select->reset();
     $select->from(['main_table' => $this->getTable('catalog_product_entity')])->useStraightJoin(true)->joinInner(['product_name' => $productAttrName->getBackend()->getTable()], 'product_name.entity_id = main_table.entity_id' . ' AND product_name.attribute_id = ' . $productAttrNameId . ' AND product_name.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID, ['name' => 'product_name.value'])->joinInner(['product_price' => $productAttrPrice->getBackend()->getTable()], "product_price.entity_id = main_table.entity_id AND product_price.attribute_id = {$productAttrPriceId}", ['price' => new \Zend_Db_Expr('product_price.value')])->where('main_table.entity_id IN (?)', $productIds);
     $productData = $productConnection->fetchAssoc($select);
     return $productData;
 }
Example #24
0
 /**
  * Retrieve product ID by sku
  *
  * @param string $sku
  * @return int|null
  */
 protected function getProductIdBySku($sku)
 {
     if (empty($this->productIds)) {
         $this->productCollection->addAttributeToSelect('sku');
         foreach ($this->productCollection as $product) {
             $this->productIds[$product->getSku()] = $product->getId();
         }
     }
     if (isset($this->productIds[$sku])) {
         return $this->productIds[$sku];
     }
     return null;
 }
 public function testGetData()
 {
     $items = ['testProduct1', 'testProduct2'];
     $expectedData = ['totalRecords' => count($items), 'items' => $items];
     $this->dataHelperMock->expects($this->once())->method('getAllowedSelectionTypes')->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('addFilterByRequiredOptions');
     $this->collectionMock->expects($this->once())->method('addStoreFilter')->with(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $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());
 }
 /**
  * @return array|\Magento\Framework\Data\Collection\AbstractDb
  */
 public function getItems()
 {
     $order = $this->getOrder();
     if (!$order) {
         return [];
     }
     $items = $order->getAllVisibleItems();
     $productIds = [];
     //get the product ids for the collection
     foreach ($items as $item) {
         $productIds[] = $item->getProductId();
     }
     $items = $this->productCollection->addAttributeToSelect('*')->addFieldToFilter('entity_id', ['in' => $productIds]);
     return $items;
 }
 /**
  * Prepare configurable data for export
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @param int $productIds
  * @return void
  */
 public function prepareData($collection, $productIds)
 {
     $collection->addAttributeToFilter('entity_id', ['in' => $productIds])->addAttributeToFilter('type_id', ['eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE]);
     while ($product = $collection->fetchItem()) {
         $productAttributesOptions = $product->getTypeInstance()->getConfigurableOptions($product);
         foreach ($productAttributesOptions as $productAttributeOption) {
             $this->configurableData[$product->getId()] = [];
             $variations = [];
             $variationsLabels = [];
             foreach ($productAttributeOption as $optValues) {
                 $variations[$optValues['sku']][] = $optValues['attribute_code'] . '=' . $optValues['option_title'];
                 if (!empty($optValues['super_attribute_label'])) {
                     $variationsLabels[$optValues['attribute_code']] = $optValues['attribute_code'] . '=' . $optValues['super_attribute_label'];
                 }
             }
             foreach ($variations as $sku => $values) {
                 $variations[$sku] = 'sku=' . $sku . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $values);
             }
             $variations = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations);
             $variationsLabels = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $variationsLabels);
             $this->configurableData[$product->getId()] = ['configurable_variations' => $variations, 'configurable_variation_labels' => $variationsLabels];
         }
     }
 }
 /**
  * @magentoDataFixture Magento/Catalog/_files/products_crosssell.php
  */
 public function testAddLinkAttributeToFilterNoResults()
 {
     $om = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $link = $om->get('Magento\\Catalog\\Model\\Product\\Link')->useCrossSellLinks();
     $this->collection->setLinkModel($link);
     $this->collection->addLinkAttributeToFilter('position', ['from' => 2, 'to' => 3]);
     $product = $om->get('Magento\\Catalog\\Model\\Product')->load(2);
     $this->collection->setProduct($product);
     $this->collection->load();
     $this->assertCount(0, $this->collection->getItems());
 }
Example #29
0
 public function getAllIds($limit = null, $offset = null)
 {
     if (!$this->listingProductMode) {
         return parent::getAllIds($limit, $offset);
     }
     // hack for selecting listing product ids instead entity ids
     $idsSelect = clone $this->getSelect();
     $idsSelect->reset(\Zend_Db_Select::ORDER);
     $idsSelect->reset(\Zend_Db_Select::LIMIT_COUNT);
     $idsSelect->reset(\Zend_Db_Select::LIMIT_OFFSET);
     $idsSelect->columns('lp.' . $this->getIdFieldName());
     $idsSelect->limit($limit, $offset);
     $data = $this->getConnection()->fetchAll($idsSelect, $this->_bindParams);
     $ids = array();
     foreach ($data as $row) {
         $ids[] = $row[$this->getIdFieldName()];
     }
     return $ids;
 }
Example #30
0
 /**
  * Add only is in stock products filter to product collection
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @return $this
  */
 public function addIsInStockFilterToCollection($collection)
 {
     $websiteId = $this->_storeManager->getStore($collection->getStoreId())->getWebsiteId();
     $joinCondition = $this->getConnection()->quoteInto('e.entity_id = stock_status_index.product_id' . ' AND stock_status_index.website_id = ?', $websiteId);
     $joinCondition .= $this->getConnection()->quoteInto(' AND stock_status_index.stock_id = ?', Stock::DEFAULT_STOCK_ID);
     $collection->getSelect()->join(['stock_status_index' => $this->getMainTable()], $joinCondition, [])->where('stock_status_index.stock_status=?', Stock\Status::STATUS_IN_STOCK);
     return $this;
 }