drupal commerce rule to skip duplicate sku in cart I have a site and i am using drupal commerce module. i want to set a rule which will prevent the user to add a product twice in the cart. suppose a user add a product A and after that if he add the same product in the same cart than the system should generate a message that the same product is already added in your cart you can add another product.

I tried to create a rule but it works on the total quantity of cart not on total quantity of same product in the cart. please help 

Thanks
You can use unique field , autosku and tokens module

using that module set the name of sku using tokens
While generating sku use tokens

the parameters which u know differentiates 2 products should be used in tokens

Like if quantity and size is the parameter which differentiates your 2 products and defines two products as unique
then 
using tokens(for e.g.) [product:qty] and [product:size]
set the sku title
and using unique field set the sku as required and unique field

You can try the following function to edit the quantity :
you can set cart quantity for a single item to be default value 1.
hook_commerce_cart_line_item_refresh($line_item, $order_wrapper)


  Allows modules to perform additional processing to refresh an
  individual line item on a shopping cart order.
  
  Prior to this hook being invoked, product line items will have already
  had their sell prices refreshed via the creation of a new line item
  for the same product being passed through Rules for calculation.
  
  Parameters
  
  $line_item: A line item object that should be updated as necessary for
  the refresh.
  
  $order_wrapper: An EntityMetadataWrapper for the order the line item
  is attached to.