当前位置: 首页>>代码示例>>PHP>>正文


PHP Visibility::getVisibleInCatalogIds方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Product\Visibility::getVisibleInCatalogIds方法的典型用法代码示例。如果您正苦于以下问题:PHP Visibility::getVisibleInCatalogIds方法的具体用法?PHP Visibility::getVisibleInCatalogIds怎么用?PHP Visibility::getVisibleInCatalogIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\Product\Visibility的用法示例。


在下文中一共展示了Visibility::getVisibleInCatalogIds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * Enable requested attribute for products, if no products are using it
  *
  * Date attributes is supported for attribute_from values only.
  *
  * @param  array $data Key => Value pairs of attribute_code and count
  * @return void
  */
 public function execute($data)
 {
     $visibility = $this->catalogProductVisibility->getVisibleInCatalogIds();
     $attributes = $this->attributeCollectionFactory->create()->addFieldToFilter('attribute_code', ['in' => array_keys($data)]);
     foreach ($attributes as $attribute) {
         $collection = $this->productCollectionFactory->create()->setPageSize(1)->setCurPage(1);
         switch ($attribute->getFrontendInput()) {
             case 'boolean':
                 $value = 1;
                 $collection->addAttributeToFilter($attribute, 1);
                 break;
             case 'date':
                 $value = $this->localeDate->date()->format('Y-m-d H:i:s');
                 $collection->addAttributeToFilter($attribute, [['date' => true, 'to' => $value]]);
                 break;
         }
         if ($collection->getSize()) {
             // customer already has some products with specified attribute
             continue;
         }
         foreach ($this->getStoreIds() as $storeId) {
             $visibleProducts = $this->productCollectionFactory->create()->setStoreId($storeId)->setVisibility($visibility)->addStoreFilter($storeId)->setPageSize($data[$attribute->getAttributeCode()])->setCurPage(1);
             if (!$visibleProducts->getSize()) {
                 continue;
             }
             foreach ($visibleProducts as $product) {
                 $product->addAttributeUpdate($attribute->getAttributeCode(), (int) in_array(0, $this->getStoreIds()), 0);
                 $product->setStoreId($storeId)->setData($attribute->getAttributeCode(), $value)->save();
             }
         }
     }
 }
开发者ID:swissup,项目名称:core,代码行数:40,代码来源:Products.php

示例2: _getProductCollection

 /**
  * @return \Magento\Eav\Model\Entity\Collection\AbstractCollection
  */
 protected function _getProductCollection()
 {
     if (is_null($this->productCollection)) {
         $collection = $this->getAuthor()->getSelectedProductsCollection()->setStore($this->_storeManager->getStore())->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addStoreFilter()->addUrlRewrite()->setVisibility($this->productVisibility->getVisibleInCatalogIds());
         $collection->getSelect()->order('position');
         $this->productCollection = $collection;
     }
     return $this->productCollection;
 }
开发者ID:sz-bill,项目名称:Magento2.x,代码行数:12,代码来源:Product.php

示例3: getFeaturedProduct

 /**
  * get featured product collection
  */
 public function getFeaturedProduct()
 {
     $limit = $this->getProductLimit();
     $collection = $this->_productCollectionFactory->create();
     $collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $collection->addMinimalPrice()->addFinalPrice()->addTaxPercents()->setPageSize($limit)->addAttributeToSelect('*');
     $collection->addAttributeToFilter('et_featured', '1');
     return $collection;
 }
开发者ID:emizentech,项目名称:magento2-featured-products,代码行数:12,代码来源:Featuredproduct.php

示例4: execute

 /**
  * Append bundles in upsell list for current product
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     /* @var $product \Magento\Catalog\Model\Product */
     $product = $observer->getEvent()->getProduct();
     /**
      * Check is current product type is allowed for bundle selection product type
      */
     if (!in_array($product->getTypeId(), $this->bundleData->getAllowedSelectionTypes())) {
         return $this;
     }
     /* @var $collection \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection */
     $collection = $observer->getEvent()->getCollection();
     $limit = $observer->getEvent()->getLimit();
     if (is_array($limit)) {
         if (isset($limit['upsell'])) {
             $limit = $limit['upsell'];
         } else {
             $limit = 0;
         }
     }
     /* @var $resource \Magento\Bundle\Model\ResourceModel\Selection */
     $resource = $this->bundleSelection;
     $productIds = array_keys($collection->getItems());
     if ($limit !== null && $limit <= count($productIds)) {
         return $this;
     }
     // retrieve bundle product ids
     $bundleIds = $resource->getParentIdsByChild($product->getId());
     // exclude up-sell product ids
     $bundleIds = array_diff($bundleIds, $productIds);
     if (!$bundleIds) {
         return $this;
     }
     /* @var $bundleCollection \Magento\Catalog\Model\ResourceModel\Product\Collection */
     $bundleCollection = $product->getCollection()->addAttributeToSelect($this->config->getProductAttributes())->addStoreFilter()->addMinimalPrice()->addFinalPrice()->addTaxPercents()->setVisibility($this->productVisibility->getVisibleInCatalogIds());
     if ($limit !== null) {
         $bundleCollection->setPageSize($limit);
     }
     $bundleCollection->addFieldToFilter('entity_id', ['in' => $bundleIds])->setFlag('do_not_use_category_id', true);
     if ($collection instanceof \Magento\Framework\Data\Collection) {
         foreach ($bundleCollection as $item) {
             $collection->addItem($item);
         }
     } elseif ($collection instanceof \Magento\Framework\DataObject) {
         $items = $collection->getItems();
         foreach ($bundleCollection as $item) {
             $items[$item->getEntityId()] = $item;
         }
         $collection->setItems($items);
     }
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:60,代码来源:AppendUpsellProductsObserver.php

示例5: getProductsCollection

 /**
  * @param int $storeId
  * @return \Magento\Catalog\Model\ResourceModel\Product\Collection
  */
 public function getProductsCollection($storeId)
 {
     /** @var $product \Magento\Catalog\Model\Product */
     $product = $this->productFactory->create();
     $todayStartOfDayDate = $this->localeDate->date()->setTime(0, 0)->format('Y-m-d H:i:s');
     $todayEndOfDayDate = $this->localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s');
     /** @var $products \Magento\Catalog\Model\ResourceModel\Product\Collection */
     $products = $product->getResourceCollection();
     $products->setStoreId($storeId);
     $products->addStoreFilter()->addAttributeToFilter('news_from_date', ['or' => [0 => ['date' => true, 'to' => $todayEndOfDayDate], 1 => ['is' => new \Zend_Db_Expr('null')]]], 'left')->addAttributeToFilter('news_to_date', ['or' => [0 => ['date' => true, 'from' => $todayStartOfDayDate], 1 => ['is' => new \Zend_Db_Expr('null')]]], 'left')->addAttributeToFilter([['attribute' => 'news_from_date', 'is' => new \Zend_Db_Expr('not null')], ['attribute' => 'news_to_date', 'is' => new \Zend_Db_Expr('not null')]])->addAttributeToSort('news_from_date', 'desc')->addAttributeToSelect(['name', 'short_description', 'description'], 'inner')->addAttributeToSelect(['price', 'special_price', 'special_from_date', 'special_to_date', 'msrp_display_actual_price_type', 'msrp', 'thumbnail'], 'left')->applyFrontendPriceLimitations();
     $products->setVisibility($this->visibility->getVisibleInCatalogIds());
     return $products;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:NewProducts.php

示例6: _prepareData

 /**
  * @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;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:Related.php

示例7: _prepareCollection

 /**
  * 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;
 }
开发者ID:samitrimal,项目名称:Blog-Extension-for-Magento-2,代码行数:19,代码来源:RelatedProducts.php

示例8: getProductCollection

 /**
  * @param \Magento\Catalog\Model\Category $category
  * @param int $storeId
  * @return $this
  */
 public function getProductCollection(\Magento\Catalog\Model\Category $category, $storeId)
 {
     /** @var $layer \Magento\Catalog\Model\Layer */
     $layer = $this->catalogLayer->setStore($storeId);
     $collection = $category->getResourceCollection();
     $collection->addAttributeToSelect('url_key')->addAttributeToSelect('name')->addAttributeToSelect('is_anchor')->addAttributeToFilter('is_active', 1)->addIdFilter($category->getChildren())->load();
     /** @var $productCollection \Magento\Catalog\Model\ResourceModel\Product\Collection */
     $productCollection = $this->collectionFactory->create();
     $currentCategory = $layer->setCurrentCategory($category);
     $layer->prepareProductCollection($productCollection);
     $productCollection->addCountToCategories($collection);
     $category->getProductCollection()->setStoreId($storeId);
     $products = $currentCategory->getProductCollection()->addAttributeToSort('updated_at', 'desc')->setVisibility($this->visibility->getVisibleInCatalogIds())->setCurPage(1)->setPageSize(50);
     return $products;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:Category.php

示例9: _getCollection

 /**
  * Get crosssell products collection
  *
  * @return \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection
  */
 protected function _getCollection()
 {
     /** @var \Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection $collection */
     $collection = $this->_productLinkFactory->create()->useCrossSellLinks()->getProductCollection()->setStoreId($this->_storeManager->getStore()->getId())->addStoreFilter()->setPageSize($this->_maxItemCount)->setVisibility($this->_productVisibility->getVisibleInCatalogIds());
     $this->_addProductAttributesAndPrices($collection);
     return $collection;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:Crosssell.php

示例10: _prepareCollection

 /**
  * 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;
 }
开发者ID:magefan,项目名称:module-blog,代码行数:20,代码来源:RelatedProducts.php

示例11: _toHtml

 /**
  * @return string
  */
 protected function _toHtml()
 {
     $storeId = $this->_getStoreId();
     $storeModel = $this->_storeManager->getStore($storeId);
     $newUrl = $this->_urlBuilder->getUrl('rss/catalog/new/store_id/' . $storeId);
     $title = __('New Products from %1', $storeModel->getFrontendName());
     $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeModel);
     /** @var $rssObj \Magento\Rss\Model\Rss */
     $rssObj = $this->_rssFactory->create();
     $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang));
     /** @var $product \Magento\Catalog\Model\Product */
     $product = $this->_productFactory->create();
     $todayStartOfDayDate = $this->_localeDate->date()->setTime('00:00:00')->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
     $todayEndOfDayDate = $this->_localeDate->date()->setTime('23:59:59')->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
     /** @var $products \Magento\Catalog\Model\Resource\Product\Collection */
     $products = $product->getCollection();
     $products->setStoreId($storeId);
     $products->addStoreFilter()->addAttributeToFilter('news_from_date', array('or' => array(0 => array('date' => true, 'to' => $todayEndOfDayDate), 1 => array('is' => new \Zend_Db_Expr('null')))), 'left')->addAttributeToFilter('news_to_date', array('or' => array(0 => array('date' => true, 'from' => $todayStartOfDayDate), 1 => array('is' => new \Zend_Db_Expr('null')))), 'left')->addAttributeToFilter(array(array('attribute' => 'news_from_date', 'is' => new \Zend_Db_Expr('not null')), array('attribute' => 'news_to_date', 'is' => new \Zend_Db_Expr('not null'))))->addAttributeToSort('news_from_date', 'desc')->addAttributeToSelect(array('name', 'short_description', 'description'), 'inner')->addAttributeToSelect(array('price', 'special_price', 'special_from_date', 'special_to_date', 'msrp_enabled', 'msrp_display_actual_price_type', 'msrp', 'thumbnail'), 'left')->applyFrontendPriceLimitations();
     $products->setVisibility($this->_visibility->getVisibleInCatalogIds());
     /*
     using resource iterator to load the data one by one
     instead of loading all at the same time. loading all data at the same time can cause the big memory allocation.
     */
     $this->_resourceIterator->walk($products->getSelect(), array(array($this, 'addNewItemXmlCallback')), array('rssObj' => $rssObj, 'product' => $product));
     return $rssObj->createRssXml();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:29,代码来源:NewCatalog.php

示例12: _getProductCollection

 /**
  * Prepare and return product collection
  *
  * @return \Magento\Catalog\Model\Resource\Product\Collection|Object|\Magento\Framework\Data\Collection
  */
 protected function _getProductCollection()
 {
     $todayStartOfDayDate = $this->_localeDate->date()->setTime('00:00:00')->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
     $todayEndOfDayDate = $this->_localeDate->date()->setTime('23:59:59')->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
     $collection = $this->_productCollectionFactory->create();
     $collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $collection = $this->_addProductAttributesAndPrices($collection)->addStoreFilter()->addAttributeToFilter('news_from_date', array('or' => array(0 => array('date' => true, 'to' => $todayEndOfDayDate), 1 => array('is' => new \Zend_Db_Expr('null')))), 'left')->addAttributeToFilter('news_to_date', array('or' => array(0 => array('date' => true, 'from' => $todayStartOfDayDate), 1 => array('is' => new \Zend_Db_Expr('null')))), 'left')->addAttributeToFilter(array(array('attribute' => 'news_from_date', 'is' => new \Zend_Db_Expr('not null')), array('attribute' => 'news_to_date', 'is' => new \Zend_Db_Expr('not null'))))->addAttributeToSort('news_from_date', 'desc')->setPageSize($this->getProductsCount())->setCurPage(1);
     return $collection;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:15,代码来源:NewProduct.php

示例13: _getProductCollection

 /**
  * Prepare and return product collection
  *
  * @return \Magento\Catalog\Model\Resource\Product\Collection|Object|\Magento\Framework\Data\Collection
  */
 protected function _getProductCollection()
 {
     $todayStartOfDayDate = $this->_localeDate->date()->setTime(0, 0, 0)->format('Y-m-d H:i:s');
     $todayEndOfDayDate = $this->_localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s');
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
     $collection = $this->_productCollectionFactory->create();
     $collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
     $collection = $this->_addProductAttributesAndPrices($collection)->addStoreFilter()->addAttributeToFilter('news_from_date', ['or' => [0 => ['date' => true, 'to' => $todayEndOfDayDate], 1 => ['is' => new \Zend_Db_Expr('null')]]], 'left')->addAttributeToFilter('news_to_date', ['or' => [0 => ['date' => true, 'from' => $todayStartOfDayDate], 1 => ['is' => new \Zend_Db_Expr('null')]]], 'left')->addAttributeToFilter([['attribute' => 'news_from_date', 'is' => new \Zend_Db_Expr('not null')], ['attribute' => 'news_to_date', 'is' => new \Zend_Db_Expr('not null')]])->addAttributeToSort('news_from_date', 'desc')->setPageSize($this->getProductsCount())->setCurPage(1);
     return $collection;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:NewProduct.php

示例14: _prepareData

 /**
  * @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;
 }
开发者ID:nja78,项目名称:magento2,代码行数:22,代码来源:Upsell.php

示例15: createCollection

 /**
  * Prepare and return product collection
  *
  * @return \Magento\Catalog\Model\Resource\Product\Collection
  */
 public function createCollection()
 {
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
     $collection = $this->productCollectionFactory->create();
     $collection->setVisibility($this->catalogProductVisibility->getVisibleInCatalogIds());
     $collection = $this->_addProductAttributesAndPrices($collection)->addStoreFilter()->setPageSize($this->getProductsPerPage())->setCurPage($this->getRequest()->getParam(self::PAGE_VAR_NAME, 1));
     $conditions = $this->getConditions();
     $conditions->collectValidatedAttributes($collection);
     $this->sqlBuilder->attachConditionToCollection($collection, $conditions);
     return $collection;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:16,代码来源:ProductsList.php


注:本文中的Magento\Catalog\Model\Product\Visibility::getVisibleInCatalogIds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。