/**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing MAP:');
     $this->configWriter->save('sales/msrp/enabled', 1);
     $fixtureFile = 'Msrp/products_msrp.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $row) {
         $productId = $this->getProductIdBySku($row['sku']);
         if (!$productId) {
             continue;
         }
         /** @var \Magento\Catalog\Model\Product $product */
         $product = $this->productCollection->getItemById($productId);
         $product->setMsrpDisplayActualPriceType(\Magento\Msrp\Model\Product\Attribute\Source\Type::TYPE_ON_GESTURE);
         if (!empty($row['msrp'])) {
             $price = $row['msrp'];
         } else {
             $price = $product->getPrice() * 1.1;
         }
         $product->setMsrp($price);
         $product->save();
         $this->logger->logInline('.');
     }
 }
예제 #2
0
 /**
  * Prepare configurable data for export
  *
  * @param \Magento\Catalog\Model\Resource\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 = [];
             $variationsPrices = [];
             $variationsLabels = [];
             foreach ($productAttributeOption as $optValues) {
                 $variations[$optValues['sku']][] = $optValues['attribute_code'] . '=' . $optValues['option_title'];
                 $priceType = $optValues['pricing_is_percent'] ? 'percent' : 'fixed';
                 $variationsPrices[] = 'name=' . $optValues['attribute_code'] . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'value=' . $optValues['option_title'] . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'price=' . $optValues['pricing_value'] . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . 'price_type=' . $priceType;
                 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);
             $variationsPrices = array_unique($variationsPrices);
             $variationsPrices = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variationsPrices);
             $variationsLabels = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $variationsLabels);
             $this->configurableData[$product->getId()] = ['configurable_variations' => $variations, 'configurable_variation_prices' => $variationsPrices, 'configurable_variation_labels' => $variationsLabels];
         }
     }
 }
예제 #3
0
파일: Cart.php 프로젝트: aiesh/magento2
 /**
  * Make collection not to load products that are in specified quote
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @param int $quoteId
  * @return $this
  */
 public function addExcludeProductFilter($collection, $quoteId)
 {
     $adapter = $this->_getReadAdapter();
     $exclusionSelect = $adapter->select()->from($this->getTable('sales_flat_quote_item'), array('product_id'))->where('quote_id = ?', $quoteId);
     $condition = $adapter->prepareSqlCondition('e.entity_id', array('nin' => $exclusionSelect));
     $collection->getSelect()->where($condition);
     return $this;
 }
예제 #4
0
 /**
  * @param \Magento\Catalog\Api\CategoryManagementInterface $categoryReadService
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory
  * @param \Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
  * @param \Magento\Catalog\Model\Resource\Product\Collection $productCollection
  */
 public function __construct(\Magento\Catalog\Api\CategoryManagementInterface $categoryReadService, \Magento\Eav\Model\Config $eavConfig, \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory, \Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Catalog\Model\Resource\Product\Collection $productCollection)
 {
     $this->categoryReadService = $categoryReadService;
     $this->eavConfig = $eavConfig;
     $this->attributeCollectionFactory = $attributeCollectionFactory;
     $this->attrOptionCollectionFactory = $attrOptionCollectionFactory;
     $this->productCollection = $productCollection->removeAllItems()->clear()->addAttributeToSelect('sku');
 }
예제 #5
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/product_simple_multistore.php
  * @magentoConfigFixture current_store customer/account_share/scope 0
  */
 public function testStoreDependentAttributeValue()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     /** @var \Magento\Store\Model\Store $store */
     $store = $objectManager->create('Magento\\Store\\Model\\Store');
     $store->load('fixturestore', 'code');
     $product = $this->_collection->addAttributeToSelect('name')->load()->getFirstItem();
     $this->assertEquals('Simple Product One', $product->getName());
     $product = $this->_collection->clear()->addAttributeToSelect('name')->addStoreFilter($store)->load()->getFirstItem();
     $this->assertEquals("StoreTitle", $product->getName());
 }
예제 #6
0
 /**
  * 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);
 }
예제 #7
0
 /**
  * Prepare configurable data for export
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @param int $productIds
  * @return void
  */
 public function prepareData($collection, $productIds)
 {
     $collection->addAttributeToFilter('entity_id', array('in' => $productIds))->addAttributeToFilter('type_id', array('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()] = array();
             foreach ($productAttributeOption as $optionValues) {
                 $priceType = $optionValues['pricing_is_percent'] ? '%' : '';
                 $this->configurableData[$product->getId()][] = array('_super_products_sku' => $optionValues['sku'], '_super_attribute_code' => $optionValues['attribute_code'], '_super_attribute_option' => $optionValues['option_title'], '_super_attribute_price_corr' => $optionValues['pricing_value'] . $priceType);
             }
         }
     }
 }
예제 #8
0
 /**
  * Get products by IDs
  * @param array    $productIds
  * @param null|int $chunkSize
  * @param bool     $filterVisibility
  * @return \Magento\Catalog\Model\Resource\Product\Collection
  */
 public function getProducts(array $productIds = [], $chunkSize = null, $filterVisibility = true)
 {
     $this->_productCollection->addAttributeToSelect('sku')->addAttributeToSelect($this->_config->getProductAttributes())->addAttributeToSelect('status')->addAttributeToSelect('visibility');
     if ($filterVisibility) {
         $this->_productCollection->addAttributeToFilter('visibility', ['in' => [Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH]])->addAttributeToFilter('status', Status::STATUS_ENABLED);
     }
     if (!empty($productIds)) {
         $this->_productCollection->addIdFilter($productIds);
     }
     if ($chunkSize !== null) {
         $this->_productCollection->setPageSize($chunkSize);
     }
     return $this->_productCollection;
 }
 protected function _initConfigurableData()
 {
     $productIds = [1, 2, 3];
     $attributes = [[['pricing_is_percent' => true, 'sku' => '_sku_', 'attribute_code' => 'code_of_attribute', 'option_title' => 'Option Title', 'pricing_value' => 12345], ['pricing_is_percent' => false, 'sku' => '_sku_', 'attribute_code' => 'code_of_attribute', 'option_title' => 'Option Title', 'pricing_value' => 12345]]];
     $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId', 'getTypeInstance', '__wakeup'], [], '', false);
     $productMock->expects($this->any())->method('getId')->will($this->returnValue(11));
     $typeInstanceMock = $this->getMock('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', [], [], '', false);
     $typeInstanceMock->expects($this->any())->method('getConfigurableOptions')->will($this->returnValue($attributes));
     $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);
 }
예제 #10
0
파일: Related.php 프로젝트: nja78/magento2
 /**
  * @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;
 }
예제 #11
0
 /**
  * Add attribute to sort
  *
  * @param string $attribute
  * @param string $dir
  * @return $this|\Magento\Catalog\Model\Resource\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);
 }
예제 #12
0
 /**
  * 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;
 }
예제 #13
0
파일: Upsell.php 프로젝트: nja78/magento2
 /**
  * @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;
 }
예제 #14
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $item = new \Magento\Framework\Object(['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\\Resource\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $this->attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\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', 'getAttributeOptions'], [], '', false);
     $this->params = [0 => $this->_entityModel, 1 => 'configurable'];
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $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', 'getAdapter'], [], '', 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));
     $adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $adapter->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $this->select->expects($this->any())->method('getAdapter')->willReturn($adapter);
     $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('fetchPairs')->will($this->returnValue([]));
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\Resource', ['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\\Resource\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->productCollection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\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\\Object', ['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]);
 }
예제 #15
0
 /**
  * Prepare select query for products in carts report
  *
  * @return $this
  */
 public function prepareForProductsInCarts()
 {
     $productAttrName = $this->_productResource->getAttribute('name');
     $productAttrNameId = (int) $productAttrName->getAttributeId();
     $productAttrNameTable = $productAttrName->getBackend()->getTable();
     $productAttrPrice = $this->_productResource->getAttribute('price');
     $productAttrPriceId = (int) $productAttrPrice->getAttributeId();
     $productAttrPriceTable = $productAttrPrice->getBackend()->getTable();
     $this->getSelect()->useStraightJoin(true)->reset(\Zend_Db_Select::COLUMNS)->joinInner(['quote_items' => $this->getTable('quote_item')], 'quote_items.quote_id = main_table.entity_id', null)->joinInner(['e' => $this->getTable('catalog_product_entity')], 'e.entity_id = quote_items.product_id', null)->joinInner(['product_name' => $productAttrNameTable], 'product_name.entity_id = e.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' => $productAttrPriceTable], "product_price.entity_id = e.entity_id AND product_price.attribute_id = {$productAttrPriceId}", ['price' => new \Zend_Db_Expr('product_price.value * main_table.base_to_global_rate')])->joinLeft(['order_items' => new \Zend_Db_Expr(sprintf('(%s)', $this->getOrdersSubSelect()))], 'order_items.product_id = e.entity_id', [])->columns('e.*')->columns(['carts' => new \Zend_Db_Expr('COUNT(quote_items.item_id)')])->columns('order_items.orders')->where('main_table.is_active = ?', 1)->group('quote_items.product_id');
     return $this;
 }
예제 #16
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('read');
     $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;
 }
예제 #17
0
 /**
  * @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', array('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());
 }
예제 #18
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\Framework\App\Resource $resource
  * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
  * @param \Magento\Catalog\Model\Resource\Helper $resourceHelper
  * @param \Magento\Framework\Validator\UniversalFactory $universalFactory
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\Module\Manager $moduleManager
  * @param \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory
  * @param \Magento\Catalog\Model\Resource\Url $catalogUrl
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  * @param \Magento\Customer\Model\Session $customerSession
  * @param \Magento\Framework\Stdlib\DateTime $dateTime
  * @param \Magento\Customer\Api\GroupManagementInterface $groupManagement
  * @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory
  * @param \Zend_Db_Adapter_Abstract $connection
  *
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\App\Resource $resource, \Magento\Eav\Model\EntityFactory $eavEntityFactory, \Magento\Catalog\Model\Resource\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Module\Manager $moduleManager, \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory, \Magento\Catalog\Model\Resource\Url $catalogUrl, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Customer\Api\GroupManagementInterface $groupManagement, \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $attributeCollectionFactory, $connection = null)
 {
     $this->_attributeCollectionFactory = $attributeCollectionFactory;
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $eavConfig, $resource, $eavEntityFactory, $resourceHelper, $universalFactory, $storeManager, $moduleManager, $catalogProductFlatState, $scopeConfig, $productOptionFactory, $catalogUrl, $localeDate, $customerSession, $dateTime, $groupManagement, $connection);
 }
예제 #19
0
 /**
  * Helper function that adds a FilterGroup to the collection.
  *
  * @param FilterGroup $filterGroup
  * @param Collection $collection
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection)
 {
     $fields = [];
     foreach ($filterGroup->getFilters() as $filter) {
         $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
         $field = $this->translateField($filter->getField());
         $fields[] = array('attribute' => $field, $condition => $filter->getValue());
     }
     if ($fields) {
         $collection->addFieldToFilter($fields);
     }
 }
예제 #20
0
 /**
  * @param \Magento\Core\Model\EntityFactory $entityFactory
  * @param \Magento\Framework\Logger $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\Framework\App\Resource $resource
  * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
  * @param \Magento\Catalog\Model\Resource\Helper $resourceHelper
  * @param \Magento\Framework\Validator\UniversalFactory $universalFactory
  * @param \Magento\Framework\StoreManagerInterface $storeManager
  * @param \Magento\Catalog\Helper\Data $catalogData
  * @param \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory
  * @param \Magento\Catalog\Model\Resource\Url $catalogUrl
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  * @param \Magento\Customer\Model\Session $customerSession
  * @param \Magento\Framework\Stdlib\DateTime $dateTime
  * @param \Magento\Customer\Model\Visitor $customerVisitor
  * @param mixed $connection
  * 
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Core\Model\EntityFactory $entityFactory, \Magento\Framework\Logger $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\App\Resource $resource, \Magento\Eav\Model\EntityFactory $eavEntityFactory, \Magento\Catalog\Model\Resource\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Framework\StoreManagerInterface $storeManager, \Magento\Catalog\Helper\Data $catalogData, \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory, \Magento\Catalog\Model\Resource\Url $catalogUrl, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Customer\Model\Visitor $customerVisitor, $connection = null)
 {
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $eavConfig, $resource, $eavEntityFactory, $resourceHelper, $universalFactory, $storeManager, $catalogData, $catalogProductFlatState, $scopeConfig, $productOptionFactory, $catalogUrl, $localeDate, $customerSession, $dateTime, $connection);
     $this->_customerVisitor = $customerVisitor;
 }
 /**
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _joinInventoryFields(\Magento\Catalog\Model\Resource\Product\Collection $collection)
 {
     if (!empty($this->_inventoryFields) && $this->moduleManager->isEnabled('Magento_CatalogInventory')) {
         foreach ($this->_inventoryFields as $field) {
             $collection->joinField($field, 'cataloginventory_stock_item', $field, 'product_id=entity_id', '{{table}}.stock_id=1', 'left');
         }
     }
 }
예제 #22
0
 /**
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @param \Magento\Catalog\Model\Category $category
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function filter($collection, \Magento\Catalog\Model\Category $category)
 {
     $collection->addAttributeToSelect($this->catalogConfig->getProductAttributes())->addSearchFilter($this->helper->getQuery()->getQueryText())->setStore($this->storeManager->getStore())->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addStoreFilter()->addUrlRewrite()->setVisibility($this->productVisibility->getVisibleInSearchIds());
 }
예제 #23
0
 /**
  * Set order
  *
  * @param string $attribute
  * @param string $dir
  * @return $this
  */
 public function setOrder($attribute, $dir = self::SORT_ORDER_DESC)
 {
     if (in_array($attribute, ['carts'])) {
         $this->getSelect()->order($attribute . ' ' . $dir);
     } else {
         parent::setOrder($attribute, $dir);
     }
     return $this;
 }
예제 #24
0
 /**
  * Redeclare parent method for store filters applying
  *
  * @return $this
  */
 protected function _beforeLoad()
 {
     parent::_beforeLoad();
     $this->_applyStoresFilterToSelect();
     return $this;
 }
예제 #25
0
 /**
  * Initialize collection select
  *
  * @return $this|void
  */
 protected function _initSelect()
 {
     parent::_initSelect();
     $this->getSelect()->join(array('selection' => $this->_selectionTable), 'selection.product_id = e.entity_id', array('*'));
 }
예제 #26
0
 /**
  * Add only is in stock products filter to product collection
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @return $this
  */
 public function addIsInStockFilterToCollection($collection)
 {
     $websiteId = $this->_storeManager->getStore($collection->getStoreId())->getWebsiteId();
     $joinCondition = $this->_getReadAdapter()->quoteInto('e.entity_id = stock_status_index.product_id' . ' AND stock_status_index.website_id = ?', $websiteId);
     $joinCondition .= $this->_getReadAdapter()->quoteInto(' AND stock_status_index.stock_id = ?', Stock::DEFAULT_STOCK_ID);
     $collection->getSelect()->join(array('stock_status_index' => $this->getMainTable()), $joinCondition, array())->where('stock_status_index.stock_status=?', Stock\Status::STATUS_IN_STOCK);
     return $this;
 }
예제 #27
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;
 }
예제 #28
0
 /**
  * Helper function that adds a FilterGroup to the collection.
  *
  * @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
  * @param Collection $collection
  * @return void
  */
 protected function addFilterGroupToCollection(\Magento\Framework\Api\Search\FilterGroup $filterGroup, Collection $collection)
 {
     $fields = [];
     foreach ($filterGroup->getFilters() as $filter) {
         $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
         $fields[] = ['attribute' => $filter->getField(), $condition => $filter->getValue()];
     }
     if ($fields) {
         $collection->addFieldToFilter($fields);
     }
 }
예제 #29
0
 /**
  * Collect validated attributes
  *
  * @param \Magento\Catalog\Model\Resource\Product\Collection $productCollection
  * @return $this
  */
 public function collectValidatedAttributes($productCollection)
 {
     $attribute = $this->getAttribute();
     if ('category_ids' != $attribute) {
         if ($this->getAttributeObject()->isScopeGlobal()) {
             $attributes = $this->getRule()->getCollectedAttributes();
             $attributes[$attribute] = true;
             $this->getRule()->setCollectedAttributes($attributes);
             $productCollection->addAttributeToSelect($attribute, 'left');
         } else {
             $this->_entityAttributeValues = $productCollection->getAllAttributeValues($attribute);
         }
     }
     return $this;
 }
예제 #30
0
 /**
  * Retrieve is flat enabled flag
  * Overwrite disable flat for compared item if required EAV resource
  *
  * @return bool
  */
 public function isEnabledFlat()
 {
     if (!$this->_catalogProductCompare->getAllowUsedFlat()) {
         return false;
     }
     return parent::isEnabledFlat();
 }