0

I am working with Drupal Commerce and am trying to copy a field on the product named "copy limit" to the line item when it's added to the cart so that I can access it in shopping cart form view when a user views his/her cart.

I am not sure of the best way to go about this.

I am using Commerce 7.x-1.0 and Drupal 7.7.

2 Answers 2

5

You'll need to add a "copy limit" field to the line item first. If you just want to use the standard "product" line item that will work. Add a "copy limit" field at admin/commerce/config/line-items/product/fields

Then you need a rule that says:

Event: "After adding a product to the cart"

Condition: Entity has field: Entity:commerce_product, Field: field_copy_limit Condition: Entity has field: Entity: commerce_line_item, Field: field_copy_limit

Action: Set a data value. Data: commerce-line-item:field-copy-limit, Value: commerce-product:field-copy-limit

You may then want to add the copy limit to your cart view.

However, If you really want to just validate that the amount in the cart is less than or equal to the copy limit, you may want to do something like this:

  1. Set up as above. The display settings on your product display node add to cart field must be set to "combine like products"

  2. Add a rule like this:

Events: * After adding a product to the cart * After saving a new commerce line item * After updating an existing commerce line item

Conditions: * Entity has field: Parameter: Entity: [commerce-line-item], Field: commerce_product * Entity has field: Parameter: Entity: [commerce-line-item..., Field: field_copy_limit * Data comparison: Parameter: Data to compare: [commerce-line-item:quantity], Operator: is greater than, Data value: [commerce-line-item:commerce-product:field-copy-limit]

Actions: * Set a data value: Parameter: Data: [commerce-line-item:quantity], Value: [commerce-line-item:commerce-product:field-copy-limit] * Show a message on the site: Parameter: Message: No more than [commerce-line-item:quantity] "[commerce-line-item:line-item-label]" may be ordered, so your order has been set to [commerce-line-item:quantity] items.

I put an export of this last rule at http://dl.dropbox.com/u/7350603/stackexchange/commerce_limit_items_in_cart.txt

0
2

Other way you can use this module Commerce Product Limit

1
  • Thanks for the suggestion. Since the site is in production now, we are a little skittish about putting sandbox modules up, but I will play around with it on my local copy of the site and leave feedback Commented Feb 6, 2012 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.