6

I am making a website in Drupal 7 and Drupal Commerce with some custom modules. Now, I have a set of Products.

The Products are, - Product 1 - Product 2 - Product 3 I have two line items. Lets say Product Sizes. And product weight. Each have select or another module implemented. I have followed the concept of Randy Fay's Screencasts. http://www.commerceguys.com/resources/articles/237
http://www.commerceguys.com/resources/articles/238

Now with each line items the cost of the product changes. As per the screenscasts, the process will be,

  1. Create Line Items
  2. Create Products
  3. Create Product Display and add a Product Field Reference to it.
  4. Then it will display the line item in the product display page.

But, I am not creating the Product display. This is going to be via the custom module. So can you tell me from the coding point of view, what is the relation between a line item and a product. So that I can list all the created line items for a displayed product.

1 Answer 1

7

It sounds like you are confused.

Short answer:
Line items has a reference to a product.

Explaination
Line items are only used when you add something to your order (cart), they have a relationship between the order and the product and hold data like price quantity, but can hold additional data, like the address (in case of subscriptions), which a unique each time you buy something.

If you have product attributes like size or weight, you probably want to store this on the product, since a products with different sizes and weight should be different products (A S size t-shirt is not the same as a L sized t-shirt).

So it really sounds like you are doing this the wrong way.

4
  • I am using line item because I need to change the price of the product based on the types the user choose. Using attributes is fine but I need to change the price. So using select or another module to set different ratio buttons as well. As you told, they have a relationship between the order and the product. So, what is the relation in terms of table.? Please let me know. Feb 28, 2012 at 14:14
  • @AneekMukhopadhyay If you create 3 products, one for S, M and L sizes they can have different prices just fine. With regards of SQL, the relation between line item and product is stored in a field, I believe it's called commerce_product, you can see the name on the line item configuration page.
    – googletorp
    Feb 28, 2012 at 14:25
  • Suppose I have 3 products. Those are displayed via commerce APIs. Once a product is chosen I want to add it to the order and then add a line item to it programmatically. The line item will have some extra features like custom Prices etc. It needs to be done before it goes to the cart. Steps, 1. Select a product 2. Add Line Items to the order loaded from the product id. Add additional prices to it. 3. Add that product and show it in cart. Note, the cart has to show the updated price. Any ideas? Please help.. Feb 29, 2012 at 12:48
  • I'm not remember previous version of commerce, but now we can handle different price based on attributes using variation types Oct 3, 2013 at 13:12

Your Answer

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

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