Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I've to build a complex site with a lot of custom product types (from hotel room to a balneotherapy package), I've chosen Commerce to run the eCommerce part.
No problem to create a custom entity and manage associated fields or workflow. But I'm stuck on doing the same with Commerce products.
There was this clue : http://drupal.org/node/1014602 and now I can see the product type in product types list, but no way to edit it or to add fields...
Does someone have a simple but working example of a product type creation?
Regards,
TahitiClic
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedSorry, we aren't handling support requests for documentation in the tracker... we'd lose too much good information to the netherworld of the issue queue. Instead, please refer to the example in my Commerce Dev installation profile for now... http://github.com/rszrama/commercedev
Comment #2
tahiticlic CreditAttribution: tahiticlic commentedOk, thanks Ryan, I've posted the same post on the Commerce forum (General Discussion).
I shall have a look on your example.
[Edit] I've downloaded the example, there's no such example (I want to create a Product Type programmatically that works fine). I'll investigate the Commerce code, hoping that it is possible : since it was in Ubercart I think so
Comment #3
rszrama CreditAttribution: rszrama commentedI'm sorry, I mistook your post to be referring to a product display node type. Look in commerce_product_ui.install for an example of creating a product type through the Product UI - but those can be edited / deleted. Really it should just take an implementation of hook_commerce_product_type_info() in your module. On a simple test, this allows me to manage fields for the product type just fine:
Comment #4
tahiticlic CreditAttribution: tahiticlic commentedHummm... I should review my install since that's what I did and it didn't work.
I had to return an object by the way.
I'll try with a Commerce dev version install.
Comment #5
rszrama CreditAttribution: rszrama commentedAhh, yeah, alpha5 still used objects, but that has all since been converted to arrays.
Comment #6
tahiticlic CreditAttribution: tahiticlic commentedWell... I've tried with a fresh D7 install, with up to date dev versions of dependancies and Commerce. That doesn't work at all : could you precise which versions you're using?
Using this, it works well :
}
Comment #7
tahiticlic CreditAttribution: tahiticlic commentedComment #8
rszrama CreditAttribution: rszrama commentedI really do think this work is working, though I'm not sure why your code wouldn't suffice. Install functions shouldn't actually be returning anything... they're just executed when a module is first installed. Have you tried using the hook I posted above? Just put that in an example.module and see what happens.
Dev should be up to date, but there was a lack of synchronization between Git and CVS that could have it out of date. Use my dev version from http://github.com/rszrama/drupalcommerce.
Comment #9
tahiticlic CreditAttribution: tahiticlic commentedThat's this version I've used and your exact code.
That's not a real install function (I've return a value only to avoid blank screen), since it would be useless using hook_commerce_product_info, that's just a fast test to see if it can work this way.
I guess I will stand with this for a while and then use hook_commerce_product_info later. Right now with all most recent versions it doesn't work on a fresh install. Maybe something is wrong with my install (I've used D7 stable version, not the dev one), I'll investigate as soon I'll have time.
Thanks for your time though, I go back on Commerce exploration! ;-)
Comment #10
rszrama CreditAttribution: rszrama commentedHmm, ok... that's very weird. You should be fine using D7 1.0, my Github repo, and dev versions of dependencies. Ahh, I do see that you mention using hook_commerce_product_info(). The most current code changed this to hook_commerce_product_type_info() (see my example above).
Comment #11
tahiticlic CreditAttribution: tahiticlic commentedIndeed, that was a problem, now using the hook, I've the product type listed in products list, but when I click on I've this output :
"This product type cannot be edited, because it is not defined by the Product UI module."
Is this normal? I guess I'll have to do something more.
Comment #12
KingdutchI realise this is quite an old post however for people who find this through google the above code will give an error as each product type needs a key, the correct snippet would be:
Comment #13
cllamas CreditAttribution: cllamas commentedKingdutch,
should we put this snippet in the mymodule.install or in mymodule.module? :)
Thanks.
Comment #14
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedReopening this support request because the answer doesn't seem to completely solve the question. #11 is the issue I see with simply implementing the hook and nothing else.
How do we get rid of that when trying to edit the product that we added with the
hook_commerce_product_type_info()
?Comment #15
alexverb CreditAttribution: alexverb commentedMaybe you need to define the module?
Always check out the api:
http://api.drupalcommerce.org/api
Comment #16
rszrama CreditAttribution: rszrama commentedI'm not sure I really understood comment #14, but I think the answer is just if it's defined in code, you need to edit it in code. The fields are still editable via the UI, though.
Comment #17
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedOkay, thanks I will review. As I see this issue, it is an issue with Documentation and a support request by users here. The answer that was accepted in this thread did not quite solve the issue for me so thank you for your clarification and hopefully it solves the issue altogether.
Comment #18
xaffimarc CreditAttribution: xaffimarc commentedHi there!
Apologies for re-opening this ticket, but I'm really struggling with implementing this.
I'm trying to define a new product type (display and variation type) in my module .install file. I have tried the code from this discussion:
Sadly, not only does this not really make sense in terms of defining both display and referenced entity, i don't see how i can create fields here either.
Please, can someone point me to some resources that might help me out... ?
Really appreciate your help in advance.
Comment #19
xaffimarc CreditAttribution: xaffimarc commentedUpdate :
I have managed to create a product type (variation entity), by creating a module.install file and add the following code:
Now, when the module installs it creates this vraiation type, and adds a deafult "price" field... there are no other fields added here.
Can anyone help me figure our how to add custom fields to this please?
Thanks
Comment #20
ram4nd CreditAttribution: ram4nd as a volunteer commentedDrupal 7 commerce add product variation types programmatically
Comment #21
theThinkrium CreditAttribution: theThinkrium commentedDrupal 8 context-
Okay i know this is an old thread but i found a solution by reading the source code and several articles that seems reliable and very "drupally"
if you create the folder structure inside your code /my_module/config/install/
and then create a yml file like this pattern
commerce_product.commerce_product_type.my_type_name.yml
and than put something like whats in the actual commerce product source code
This is an example:
langcode: en
status: true
dependencies: { }
id: lower_case_example_name
label: ExampleName
description: 'This is a example product type'
variationType: default
multipleVariations: true
injectVariationFields: true
traits: { }
locked: false
You can do the same things with a variation type default
same file structure
commerce_product.commerce_product_variation_type.my_variateion_type_name.yml
langcode: en
status: true
dependencies: { }
id: recurring
label: Default
orderItemType: default
generateTitle: true
traits: { }
locked: false
Thats what im doing....
im building a recurring commerce module because i dont have time to sort through the bugs in commerce recurring too much going on...
i fully intend on contributing to commerce recurring if it helps but i dont have time right now so im building my own...