Jump to content

Edit History

Titi2

Titi2

Hello guys. I hope you are well.

In multistore i need to copy a product from Store A to Store B. Everything is almost okay! Copy products works. But i want to prevent the copy of products if the copy already exists in database. Let me more precise:

If a product from Store A is copied to Store B, but the product already exists in Store B, then the product in store B is overrided. And i would like to prevent it! So i need to check in which stores the product already exist before the copy.

Here my code in my controller:

    $id_product = $product_source->id;
    // If product source object is valid then the product exist in the default shop. $product_source is a product object.
    if (Validate::isLoadedObject($product_source)) { 
        // or ObjectModel::existsInDatabase($id_product, Product::$definition['table'])
        // or Product::existsInDatabase($id_product)
        // I think theses 3 methods does the same thing.

        // Now, it's possible to create the product clone object
        // My code to create the cloned product goes here and works perfectly but maybe the product already exists in the targeted shop so i need 
		// to check it before copying the data.
    } else {
        // No product id found in the database (product doesn't exist, we can't clone it)
        $product_error = $this->trans("Product doesn't exists anywhere. It can't be cloned to the targeted shop", "Modules.Mymodule");
    }

 

So, how can i get all stores associated to my product? Cause when i check if the product exists in database, it return only one result: The default id shop. Not all its id shops.

Titi2

Titi2

Hello guys. I hope you are well.

In multistore i need to copy a product from Store A to Store B. Everything is almost okay! Copy products works. But i want to prevent the copy of products if the copy already exists in database. Let me more precise:

If a product from Store A is copied to Store B, but the product already exists in Store B, then the product in store B is overrided. And i would like to prevent it! So i need to check in which store the product already exist before the copy.

Here my code in my controller:

    $id_product = $product_source->id;
    // If product source object is valid then the product exist in the default shop. $product_source is a product object.
    if (Validate::isLoadedObject($product_source)) { 
        // or ObjectModel::existsInDatabase($id_product, Product::$definition['table'])
        // or Product::existsInDatabase($id_product)
        // I think theses 3 methods does the same thing.

        // Now, it's possible to create the product clone object
        // My code to create the cloned product goes here and works perfectly but maybe the product already exists in the targeted shop so i need 
		// to check it before copying the data.
    } else {
        // No product id found in the database (product doesn't exist, we can't clone it)
        $product_error = $this->trans("Product doesn't exists anywhere. It can't be cloned to the targeted shop", "Modules.Mymodule");
    }

 

So, how can i get all stores associated to my product? Cause when i check if the product exists in database, it return only one result: The default id shop. Not all its id shops.

Titi2

Titi2

Hello guys. I hope you are well.

In multistore i need to copy a product from Store A to Store B. Everything is almost okay! Copy products works. But i want to prevent the copy of products if the copy already exists in database. Let me more precise:

If a product from Store A is copied to Store B, but the product already exists in Store B, then the product in store B is overrided. And i would like to prevent it! So i need to check in wich store the product already exist before the copy.

Here my code in my controller:

    $id_product = $product_source->id;
    // If product source object is valid then the product exist in the default shop. $product_source is a product object.
    if (Validate::isLoadedObject($product_source)) { 
        // or ObjectModel::existsInDatabase($id_product, Product::$definition['table'])
        // or Product::existsInDatabase($id_product)
        // I think theses 3 methods does the same thing.

        // Now, it's possible to create the product clone object
        // My code to create the cloned product goes here and works perfectly but maybe the product already exists in the targeted shop so i need 
		// to check it before copying the data.
    } else {
        // No product id found in the database (product doesn't exist, we can't clone it)
        $product_error = $this->trans("Product doesn't exists anywhere. It can't be cloned to the targeted shop", "Modules.Mymodule");
    }

 

So, how can i get all stores associated to my product? Cause when i check if the product exists in database, it return only one result: The default id shop. Not all its id shops.

Titi2

Titi2

Hello guys. I hope you are well.

In multistore i need to copy a product from Store A to Store B. Everything is almost okay! Copy products works. But i want to prevent the copy of products if the copy already exists in database. Let me more precise:

If a product from Store A is copied to Store B, but the product already exists in Store B, then the product in store B is overrided. And i would like to prevent it! So i need to check in wich store the product already exist before the copy.

Here my code in my controller:

    $id_product = $product_source->id;
    // If product source object is valid then the product exist in the default shop. $product_source is a product object.
    if (Validate::isLoadedObject($product_source)) { 
        // or ObjectModel::existsInDatabase($id_product, Product::$definition['table'])
        // or Product::existsInDatabase($id_product)
        // I think theses 3 methods does the same thing.

        // Now, it's possible to create the product clone object
        // My code to create the cloned product goes here and works perfectly but maybe the product already exists in the targeted shop so i need 
		// to check it before copying the data.
    } else {
        // No product id found in the database (product doesn't exist, we can't clone it)
        $product_error = $this->trans('Product doesn\\'t exists anywhere. It can't be cloned to the targeted shop', 'Modules.Mymodule');
    }

 

So, how can i get all stores associated to my product? Cause when i check if the product exists in database, it return only one result: The default id shop. Not all its id shops.

Titi2

Titi2

Hello guys. I hope you are well.

In multistore i need to copy a product from Store A to Store B. Everything is almost okay! Copy products works. But i want to prevent the copy of products if the copy already exists in database. Let me more precise:

If a product from Store A is copied to Store B, but the product already exists in Store B, then the product in store B is overrided. And i would like to prevent it! So i need to check in wich store the product already exist before the copy.

Here my code in my controller:

    $id_product = $product_source->id;
    // If product source object is valid then the product exist in the default shop. $product_source is a product object.
    if (Validate::isLoadedObject($product_source)) { 
        // or ObjectModel::existsInDatabase($id_product, Product::$definition['table'])
        // or Product::existsInDatabase($id_product)
        // I think theses 3 methods does the same thing.

        // Now, it's possible to create the product clone object
        // My code to create the cloned product goes here and works perfectly but maybe the product already exists in the targeted shop so i need 
		// to check it before copying the data.
    } else {
        // No product id found in the database (product doesn't exist, we can't clone it)
        $product_error = $this->trans('Product doesn\'t exists anywhere. It can't be cloned to the targeted shop', 'Modules.Mymodule');
    }

 

So, how can i get all stores associated to my product? Cause when i check if the product exists in database, it return only one result: The default id shop. Not all its id shops.

×
×
  • Create New...