Jump to content

Welcome, Guest!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

  • 0
SeaSky

Product Accessories - Mass Update / Assign

Question

Hi everyone,

I've been trying to find a way to mass update accessories to the whole store with no luck.

- I tried to download the whole product category in CSV format, but the accessories field is not displayed, is there a way to activate this field or something like that?

- I also tried to create and download a list in CSV using Data Kick module, but the accesories field is not there neither.

- Also tried to use xml, but the accessories field doesn't exist as an attribute in Data Kick module.

As I've not been able to mass update the accessories for my products I've come to the conclusion that the best way to resolve this for the moment is to assign the same 5 - 6 products as accessories to all my products using the 5 - 6 products Id's.

In product.tpl:

{include file="$tpl_dir./product-list.tpl" products=$accessories}

How can I modfiy this line to be able to display 5 - 6 products by id?

Thanks a lot!

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I dont know about datakicks module. Probably he will respond here too.

If you really wanna add this fastly you could use the following script. But please make a backup before. 

$ids_add_accessory = [3862, 3861];

        $query = new DbQuery();
        $query->select('id_product');
        $query->from('product');
        $ids_product = array_column(Db::getInstance()->ExecuteS($query), 'id_product');

        $inserts = array();

        foreach ($ids_product as $id_product) {
            foreach ($ids_add_accessory as $id_add_accessory) {
                if ($id_product!=$id_add_accessory) {
                    $inserts[] = array(
                        'id_product_1' => $id_product,
                        'id_product_2' => $id_add_accessory,
                    );
                }
            }
        }

        Db::getInstance()->insert('accessory', $inserts, false, true, 2);

You basically change the values in $ids_add_accessory. If you want to just add this tags to some products (instead of all), you could also work with $ids_product manually. 

Example: $ids_add_accessory = [1,2,3] and $ids_product = [100,101] 
This means that products with id 100 and 101 get the accessoires 1, 2 and 3.

Share this post


Link to post
Share on other sites
  • 0
20 minutes ago, wakabayashi said:

I dont know about datakicks module. Probably he will respond here too.

If you really wanna add this fastly you could use the following script. But please make a backup before. 


$ids_add_accessory = [3862, 3861];

        $query = new DbQuery();
        $query->select('id_product');
        $query->from('product');
        $ids_product = array_column(Db::getInstance()->ExecuteS($query), 'id_product');

        $inserts = array();

        foreach ($ids_product as $id_product) {
            foreach ($ids_add_accessory as $id_add_accessory) {
                if ($id_product!=$id_add_accessory) {
                    $inserts[] = array(
                        'id_product_1' => $id_product,
                        'id_product_2' => $id_add_accessory,
                    );
                }
            }
        }

        Db::getInstance()->insert('accessory', $inserts, false, true, 2);

You basically change the values in $ids_add_accessory. If you want to just add this tags to some products (instead of all), you could also work with $ids_product manually. 

Example: $ids_add_accessory = [1,2,3] and $ids_product = [100,101] 
This means that products with id 100 and 101 get the accessoires 1, 2 and 3.

Thank you for your reply Wakabayashi, I'll try to understeand and apply your solution and come back with an answer, as I first need to find where and how I have to execute the script. (Should I just put it in the header, execute it once then comment it?)

By the way, would it be possible to do something like this:

{include file="$tpl_dir./product-list.tpl" products=$accessories} - > {include file="$tpl_dir./product-list.tpl" products=product1, product2, product3, product4, product5}

Share this post


Link to post
Share on other sites
  • 0

Yeah you would need to copy it somewhere and then execute it. I normally add it to the get_content method of a module. Then go to modules page and click on configuration. Thath will trigger it.

4 hours ago, SeaSky said:

{include file="$tpl_dir./product-list.tpl" products=product1, product2, product3, product4, product5}

I don't think there is an easy solution, to achieve this. You need an array with all the info. Unfortunately I can't find any function that allows this. Of course you could create a function that returns the needed info.

Share this post


Link to post
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...