0

Magento 2.2.9:

I have a multiwebsite-setup. Site 1 is a normal webshop. Site 2 is a satellite page that links to site 1. So I would like to create a product collection from site 1 starting like this:

$products = $this->_collectionFactory->create();

The resulting SQL points to the site we are currently on (site 2):

SELECT 1 AS `status`, `e`.`entity_id`, `e`.`attribute_set_id`, `e`.`type_id`, `e`.`created_at`, `e`.`updated_at`, `e`.`sku` FROM `catalog_product_flat_2` AS `e`

As you can see the query points to catalog_product_flat_2. How can I create a collection specifically pointing to a specific website?

Setting store or website in the returned object does not have any effect:

$products = $this->_collectionFactory->create();
$products
    ->addAttributeToSelect('*')
    ->addStoreFilter(1) // does not work
    ->setStoreId(1) // does not work
    ->addWebsiteFilter(1) // does not work
    ->addAttributeToFilter('status', array('in' => $this->_productStatus->getVisibleStatusIds()))
    ->setVisibility($this->_productVisibility->getVisibleInSiteIds())
    ->addAttributeToFilter('sku', array('in' => $skus))
;

EDIT: This only fails when using catalog flat tables. Without them there is no issue.

  • you means particular Store ??? If yes check this link webkul.com/blog/… – Mohit Patel Jun 8 at 15:59
  • A particular website/store/storeview... yes. But it does not matter, since setting store- or website id on the returned collection does not have any effect no the resulting query. Your proposed code does not work either across websites. – omsta Jun 8 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.