Jump to content

Sync active products between multistores


Recommended Posts

Hi,

I'm using Prestashop 8.1.1 and multistore with different domains.

The main shop (id 1 ) has all the products/categories, and the other stores has only some of those categories/products.

There aren't any extra products on those stores that isn't in store ID 1.

What I would like is a script I can run via cronjob that "syncronize" the active status between those shops based on store ID 1.

An Example:

Product 1 is not activated in store 1  and activated on store 2

When I run this script. the product should be deactivated in store 2.

Do you guys have an idea for this script?

This would saves lots of time on big catalogs with multistore feature.

Any help will be appreciated :)

 

Thanks

Link to comment
Share on other sites

Try this script, put it somewhere in the root folder of your shop nad run in the browser.

<?php

require_once('config/config.inc.php');

$mainShopId = 1;
$query = 'SELECT `id_product`, `active` FROM `' . _DB_PREFIX_ . 'product_shop` WHERE `id_shop` = ' . $mainShopId . ' ORDER BY `id_product`';
$res = Db::getInstance()->executeS($query);
if ($res) {
    foreach ($res as $row) {
        $productId = (int) $row['id_product'];
        $active = (int) $row['active'];
        echo $productId . ' - ' . $active . '<br/>';
        Db::getInstance()->update('product_shop', ['active' => $active], '`id_product` = ' . $productId);
    }
}

 

  • Thanks 1
Link to comment
Share on other sites

thank you so much Daresh for the script!

1 hour ago, Daresh said:

Try this script, put it somewhere in the root folder of your shop nad run in the browser.

<?php

require_once('config/config.inc.php');

$mainShopId = 1;
$query = 'SELECT `id_product`, `active` FROM `' . _DB_PREFIX_ . 'product_shop` WHERE `id_shop` = ' . $mainShopId . ' ORDER BY `id_product`';
$res = Db::getInstance()->executeS($query);
if ($res) {
    foreach ($res as $row) {
        $productId = (int) $row['id_product'];
        $active = (int) $row['active'];
        echo $productId . ' - ' . $active . '<br/>';
        Db::getInstance()->update('product_shop', ['active' => $active], '`id_product` = ' . $productId);
    }
}

 

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...