Discussions

Auto expire product?

Hi,

Just wondering if anybody has had any experience setting a product to disable itself based on the current date.

I've been building a DC site for our college's one day cooking courses and everything has gone well except that it would be nice if the courses (products) could turn themselves off once they are over.

I've been trying to do it via rules but haven't had much luck as it seems that I can't create a condition against the date field that I added to the product.

Any help would be greatly appreciated.

Thanks.

Posted: Jan 23, 2012

Comments

rfay Randy Fay on January 24, 2012

There's no reason this shouldn't work, although I think I'd use rules scheduler to do it. Some event has to be used to disable the product (look through all products and disable the ones that need to be disabled). But I don't see any reason rules couldn't be in charge of this.

brendan on September 16, 2012

Did you ever create a rules solution for this? Would be so useful!

Adam Bińkowski on May 30, 2014

I know its old, but maybe this will be halpfull for somebody.
Rules scheduler needed.

field_meeting_time - to change for name of your date field name

Component:

{ "rules_disable_product" : {
"LABEL" : "Disable product",
"PLUGIN" : "rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "product" : { "label" : "Product", "type" : "commerce_product" } },
"IF" : [
{ "entity_has_field" : { "entity" : [ "product" ], "field" : "field_meeting_time" } },
{ "NOT data_is_empty" : { "data" : [ "product:field-meeting-time" ] } }
],
"DO" : [ { "data_set" : { "data" : [ "product:status" ], "value" : 0 } } ]
}
}

Rule:

{ "rules_disable_outdated_products" : {
"LABEL" : "Disable outdated products",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "rules_scheduler", "entity" ],
"ON" : { "commerce_product_insert" : [] },
"IF" : [
{ "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_meeting_time" } }
],
"DO" : [
{ "schedule" : {
"component" : "rules_disable_product",
"date" : {
"select" : "commerce-product:field-meeting-time:value",
"date_offset" : { "value" : 600 }
},
"identifier" : [ "commerce-product:product-id" ],
"param_product" : [ "commerce-product" ]
}
}
]
}
}