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:
<?php
/**
* Implements hook_entity_update
*/
function mymodule_entity_update($entity, $type){
if ($type == 'commerce_line_item'){
$original = intval($entity->original->quantity);
$updated = intval($entity->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!