Skip to main content
added 1 character in body
Source Link
Jeremy Daalder
  • 7.6k
  • 14
  • 26

Commerce will by default combine line items that have the same hash value for the options (that is, the values of the items chosechosen options are run through md5 to get a hash - if the hash matches, the lineItems quantity is increased as the item is seen as the same item.

If you want line items with the same options to remain as separate line items, then you can simply add another unique option to the product as you add it to the cart (you don't need to display this of course).

<input type="hidden" name="options['whatevs']" value="somethingRandom">

Twig isn't actually ideal at generating random things I believe, I'd personally create a template variable in my Business Logic plugin that returns a random value, e.g. something like:

public function random(){
    srand(time());
    return rand(1,time()); 
}

You can e.g. call the current timestamp in twig but there's always a chance that might not end up as random I suppose?

<input type="hidden" name="options['time']" value="{{ date().timestamp }}">

(Calling twigs own random (https://twig.sensiolabs.org/doc/2.x/functions/random.html) - doesn't seem ideal as that's inclusive so you might see the edge values returned more than you'd like).

Commerce will by default combine line items that have the same hash value for the options (that is, the values of the items chose options are run through md5 to get a hash - if the hash matches, the lineItems quantity is increased as the item is seen as the same item.

If you want line items with the same options to remain as separate line items, then you can simply add another unique option to the product as you add it to the cart (you don't need to display this of course).

<input type="hidden" name="options['whatevs']" value="somethingRandom">

Twig isn't actually ideal at generating random things I believe, I'd personally create a template variable in my Business Logic plugin that returns a random value, e.g. something like:

public function random(){
    srand(time());
    return rand(1,time()); 
}

You can e.g. call the current timestamp in twig but there's always a chance that might not end up as random I suppose?

<input type="hidden" name="options['time']" value="{{ date().timestamp }}">

(Calling twigs own random (https://twig.sensiolabs.org/doc/2.x/functions/random.html) - doesn't seem ideal as that's inclusive so you might see the edge values returned more than you'd like).

Commerce will by default combine line items that have the same hash value for the options (that is, the values of the items chosen options are run through md5 to get a hash - if the hash matches, the lineItems quantity is increased as the item is seen as the same item.

If you want line items with the same options to remain as separate line items, then you can simply add another unique option to the product as you add it to the cart (you don't need to display this of course).

<input type="hidden" name="options['whatevs']" value="somethingRandom">

Twig isn't actually ideal at generating random things I believe, I'd personally create a template variable in my Business Logic plugin that returns a random value, e.g. something like:

public function random(){
    srand(time());
    return rand(1,time()); 
}

You can e.g. call the current timestamp in twig but there's always a chance that might not end up as random I suppose?

<input type="hidden" name="options['time']" value="{{ date().timestamp }}">

(Calling twigs own random (https://twig.sensiolabs.org/doc/2.x/functions/random.html) - doesn't seem ideal as that's inclusive so you might see the edge values returned more than you'd like).

Source Link
Jeremy Daalder
  • 7.6k
  • 14
  • 26

Commerce will by default combine line items that have the same hash value for the options (that is, the values of the items chose options are run through md5 to get a hash - if the hash matches, the lineItems quantity is increased as the item is seen as the same item.

If you want line items with the same options to remain as separate line items, then you can simply add another unique option to the product as you add it to the cart (you don't need to display this of course).

<input type="hidden" name="options['whatevs']" value="somethingRandom">

Twig isn't actually ideal at generating random things I believe, I'd personally create a template variable in my Business Logic plugin that returns a random value, e.g. something like:

public function random(){
    srand(time());
    return rand(1,time()); 
}

You can e.g. call the current timestamp in twig but there's always a chance that might not end up as random I suppose?

<input type="hidden" name="options['time']" value="{{ date().timestamp }}">

(Calling twigs own random (https://twig.sensiolabs.org/doc/2.x/functions/random.html) - doesn't seem ideal as that's inclusive so you might see the edge values returned more than you'd like).