Discussions

Hide Add to Cart for a product if it is already in the Cart

Is there a way using Rules to hide the Add to Cart for a product if it is already in the Cart?

Posted: Nov 11, 2013

Comments

MarioBrus on November 11, 2013

I am trying this but doesnt work:

{ "rules_unset_the_price_of_products_already_buyed" : {
    "LABEL" : "Unset the price of products already buyed",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "commerce_order", "rules", "commerce_product_reference" ],
    "ON" : { "commerce_product_calculate_sell_price" : [] },
    "IF" : [
      { "commerce_order_contains_product" : {
          "commerce_order" : [ "site:current-cart-order" ],
          "product_id" : [ "commerce-line-item:line-item-id" ],
          "operator" : "=",
          "value" : "1"
        }
      }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "commerce-line-item:commerce-unit-price:amount" ] } }
    ]
  }
}

MarioBrus on November 11, 2013

And I tried this:

{ "rules_unset_the_price_of_products_already_buyed" : {
    "LABEL" : "Unset the price of products already buyed",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_order", "commerce_product_reference" ],
    "ON" : { "commerce_product_calculate_sell_price" : [] },
    "IF" : [
      { "NOT data_is_empty" : { "data" : [ "commerce-line-item:line-item-id" ] } },
      { "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
      { "commerce_order_contains_product" : {
          "commerce_order" : [ "site:current-cart-order" ],
          "product_id" : [ "commerce-line-item:commerce-product:sku" ],
          "operator" : "=",
          "value" : "1"
        }
      }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "commerce-line-item:commerce-unit-price:amount" ] } }
    ]
  }
}