On quantity change, create individual line items of the same item in Drupal Commerce cart Here is a more detailed explanation:

In Drupal Commerce cart, when a customer sets the quantity of a product from 1 to 5 for example, on 'Update Cart', we'll need 5 individual line items of the same product with quantity 1 each.

I've gotten this far on solving the problem but I'm not sure how to continue:

&lt;?php 
/**
 * Implements hook_entity_update
 */
function mymodule_entity_update($entity, $type){
  if ($type == 'commerce_line_item'){
    $original = intval($entity-&gt;original-&gt;quantity);
    $updated = intval($entity-&gt;quantity);

    if ($original != $updated){
        $new_product = $entity;
        // Create as many individual line items of the same product as needed, save them and add them to the order
    }
  }
}


I've tried to use commerce_line_item_save() to save $new_product, which is in this code snippet should be a clone of the line item. I've tried it with increasing the line item id and save it that way but I just got DB errors.

How can I make this happen in a nice way? Thank you!
It would be possible to create a new views handler based on commerce_line_item_handler_field_edit_quantity that worked the way you want, but IMHO it would be weird from a UX POV to enter 5 into the quantity textfield of 1 line item, submit, and then see 5 distinct line items with quantity 1.

A simple alternative would be to modify the cart view to have something like an Add 1 more button:


Remove the quantity field;
Add a relationship to the product;
Add the product's add to cart form as a field;
Configure the field to not combine products (and you can also modify the text here, eg Add 1 more).


I haven't tested this, but I think it should work.