1
Answers
Vote up!
0
Vote down!

Setting pricing attribute fields programmatically

I am importing a very large selection of products with option sets into Drupal 7. The import works fine with all custom fields, builds the option sets with prices added, and creates commerce_pricing_attribute fields on the content types. What I'm running into is that I can't seem to programmatically select the option sets on the products, if I add a commerce_attribute_pricing field the product has "none" selected once the import is completed.

I've tried adding "set_id" to match the appropriate option set, but as I look through the module code it seems that everything uses the form api, so I'm concerned the only way I'll be able to do this is to run the products submit handlers programmatically which I would very much like to avoid.

Asked by: Trey Felton
on July 8, 2014

1 Answer

Vote up!
-1
Vote down!

When you go around the data model that Drupal Commerce sets up, you will have problems. Attributes should not have pricing except in very unique ecommerce situations. Everything else should come back to a unique and specific product/SKU combination.

Josh

Josh Miller
Answer by: Josh Miller
Posted: Sep 24, 2014

Comments

Our company has 4300 products with a number of attributes (between 5 and 15) that may, or may not, affect the price. That puts the permutations in the hundreds of millions so adding a unique sku for each is simply bad use of a database. Your answer is also wrong. I managed to get it working because this is an API question, not a data model question. Unless you are suggesting that we not use the contributed modules? (i.e. option sets & pricing attributes).

The fact that it took you 2 1/2 months to respond with a useless answer does not fill me with confidence that we have chosen the right commerce solution at any rate. I appreciate the fact that Drupal Commerce separates the data and structure from the display and that was a primary reason for us choosing it over ubercart, even though I have years of experience with the latter.

Also, I was never notified of this comment despite the fact that am "tracking" it. I sincerely hope that this is not indicative of the future of this project.

- Trey Felton on October 6, 2014