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.
All the products in our system are unique, so they can be bought only once.
the obvious solution would be to go through array of products that were in cart on "after checkout" event and disable them, but this doesn't work for me.
I'm not sure what id should I use to load product entity since only line-items entities are available for Rules, here is my Rule:
{ "rules_disable_invoice_on_checkout_comp" : {
"LABEL" : "Disable invoice on checkout completion",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "commerce_checkout" ],
"ON" : [ "commerce_checkout_complete" ],
"DO" : [
{ "entity_fetch" : {
"USING" : {
"type" : "commerce_product",
"id" : [ "commerce-order:commerce-line-items:0:line-item-id" ]
},
"PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
}
},
{ "data_set" : { "data" : [ "entity-fetched:status" ], "value" : "0" } }
]
}
}
the rule doesn't seem to work (single product in cart!). Any ideas?
Comments
Comment #0.0
restyler CreditAttribution: restyler commentedadding code tag
Comment #1
rszrama CreditAttribution: rszrama commentedYou're trying to load a product using a line item ID. What you really want is commerce-order:commerce-line-items:0:commerce-product:product-id. To get to that data selector, you may need to use an "Entity has field" condition on the line item. But it might not work at all.
Also, I'd probably loop over the line items and use the list item data selector instead of just referencing delta 0. What if the customer orders more than one?
Comment #2
restyler CreditAttribution: restyler commentedMmm.. I've tried to add condition, but I'm not sure that it is located in the right place:
There is still no :commerce-product selector: http://pix.am/GjYG/
I will probably add loops later, I'm not sure that I will allow user to have more than 1 product.
Comment #3
restyler CreditAttribution: restyler commentedComment #4
rszrama CreditAttribution: rszrama commentedI'd go ahead and do the loop. That should clear it up. This may be related to the longstanding issue in Rules that won't let you access the field data of referenced entities.
Comment #6
muschpusch CreditAttribution: muschpusch commentedi want to do the same. Accessing a product in rules when only a line item is available.
Which field?
My use case is a shipping rate per product but defined as a field on the product entity
Comment #7
rszrama CreditAttribution: rszrama commentedWhatever field it is you're looking for. It'd probably be best if you asked for help in IRC, as I can see this being a running conversation. Otherwise the Node One Rules video tutorials may help you.
Comment #7.0
rszrama CreditAttribution: rszrama commentedtt
Comment #8
crispiatico CreditAttribution: crispiatico commentedThis solution not work for me because only the Product variations is not available.
I want that my product is not available or publish after purchase after it was purchased.
How can I do this ?
Thankyou
Comment #9
ziobudda CreditAttribution: ziobudda as a volunteer and commented@crispiatico: have you find a solution ?
Comment #10
crispiatico CreditAttribution: crispiatico commented@ziobudda: no i'm not find a solution :-(