Question

We have a multi-store with a bunch of products.

For certain categories in specific store views, I'd like to set all products to be in a particular store. Advice on how to achieve this would be greatly appreciated.

One of my biggest missing pieces is how to programmatically set the "Product in Stores" for each product -- I could probably figure out the rest from there. But yes, any thoughts would be appreciated.

Était-ce utile?

La solution

You can easily assign products to different stores from adminpanel. Go to products grid catalog->products select all products or select selected products. Then click on actions dropdown from top left corner. Select Update Attribute then select websites. After that select specific store view's then save.

Autres conseils

For the sake of: If everyone every tries to google 'How to assign products to website or storeview programatically' Magento 1.9

Here's how, source from app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php

Use


//...
$actionModel = Mage::getSingleton('catalog/product_action');
$productIds  = $this->_getHelper()->getProductIds();

if ($websiteRemoveData) {
    $actionModel->updateWebsites($productIds, $websiteRemoveData, 'remove');
}
if ($websiteAddData) {
    $actionModel->updateWebsites($productIds, $websiteAddData, 'add');
}

Mage::dispatchEvent('catalog_product_to_website_change', array(
    'products' => $productIds
));
//...

Where the $websiteAddData and $websiteRemoveData is defined as followed

$websiteRemoveData  = $this->getRequest()->getParam('remove_website_ids', array());
$websiteAddData     = $this->getRequest()->getParam('add_website_ids', array());

Meaning, you will need to specify an array of website ids.

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top