Here is a simplified use case.

I have 400 products in my store. They all share the same option set (a select).

  • Option-1 has a pricing attribute of +1$
  • Option-2 has a pricing attribute of +2$
  • Option-3 has a pricing attribute of +3$

All is well and works fine. Then the owner, who has ambitions, wants to add 1 more option and change the scheme of pricing attributes.

  • Option-1 has a pricing attribute of +1$
  • Option-2 has a pricing attribute of +3$
  • Option-3 has a pricing attribute of +5$
  • Option-4 has a pricing attribute of +7$

It's easy to add the 4th option and change the default values of the option set. All is well and the owner is impressed.

But wait, the new price scheme is only applied to new products. Well, that won't do says the store owner with a big grin. You need to update all 400 existing products too!

Oy! I need a vacation!

Seriously, any ideas how this can be automated?

Comments

bisonbleu created an issue. See original summary.

bisonbleu’s picture

I considered doing this with Commerce Feeds using a custom module and changing it as suggested here. Although Feeds feedback is 'positive', I was unable to change the original Option set for a new one. But I did not push to hard in that direction.

Then I figured I would try/explore with Rules. Took me a bit of time but in the end I was able to create a simple component which, when executed, made it possible, using an 'Execute custom PHP code' action to change the [price] of each option in the original Option set.

From there, VBO did its usual magic*: updated commerce pricing attributes for 460 products in a matter of seconds. Kudos to the maintainers of Rules and VBO!

Can anyone think of a better way?

* Rules' Components are available for bulk operations (loops if you prefer) in Views Bulk Operations.

bisonbleu’s picture

Status: Active » Needs work

Update: as mentioned above, I was able to update the option set. But I'm running into a secondary issue: event though the updated option set is showing and on spec, when viewing the product, the drop down menu is still only showing the 3 original options.

At the present time, I can only fix this manually by editing the product display node, opening all its variations from the inline entity form Edit link and then saving the product display node without further action on the variations.

Stron’s picture

It is easy! Sorry for my english :)

You should use the https://www.drupal.org/project/views_bulk_operations

Add new view with selected "Show: commerce product"

In the view add field "bulk operation", select what option you want to change.

So you can SET the SAME options to many commerce products.

At the page of view, select what products you want to shange, then choose action and run it. On the next page set all options attribute and price as you need.

bisonbleu’s picture

Status: Needs work » Needs review

Hey Stron, thanks for the suggestion :)

My VBO was not where I had a problem. My issue - which I've just resolved - was because I was only setting the ['price'] item of the options array:

[enabled] => 1
[price_op] => multiply
[price] => 100
[currency_code] => CAD
[calculate] => per_item
[weight] => 0

Changing the code of my component so that all items (5) are set for each option fixed everything.