VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: saviB on February 13, 2013, 18:19:30 PM

Title: Product Automatic Expiration
Post by: saviB on February 13, 2013, 18:19:30 PM
Hi Folks. Is there a way to make VM products expire? Not an auction, not a coupon, the products themselves. I know there is an availability date - but not expiration. Why would I want this? I have a client that sells workshops (speaking engagements). Because VM is so easy to use, we are setting up each engagement as a product. In other words, a product may be EVENT NAME + February 4. Of course, after Feb 4 passes - the product should terminate automatically.

It seems like a pretty straight forward and useable addition to the VM product editor.
Title: Re: Product Automatic Expiration
Post by: jenkinhill on February 14, 2013, 17:10:40 PM
Not seen anybody else request this, but maybe you could ask for devopment quotes on http://forum.virtuemart.net/index.php?board=18.0 or http://jobs.virtuemart.net/

You can remove price & add to cart button from a product using the price expiry date on the Product pricing panel of the product information page on VM2.0.18a. That prevents anyone "buying" it after that date.
Title: Re: Product Automatic Expiration
Post by: PolishedGeek on February 14, 2013, 17:25:56 PM
As Jenkinhill says, this could certainly be achieved with a customization. I have an idea of how it could be done without any hacks to VM2, which is always an important consideration. If you decide to hire a professional developer to handle this for you, keep us in mind. We do a lot of custom VM extensions, integration and custom development. If you post on the commercial boards that Jenkinhill suggests, please do post the link here so we can take the conversation to the other board. Thanks!   
Title: Re: Product Automatic Expiration
Post by: djold on October 07, 2016, 10:29:45 AM
You can remove price & add to cart button from a product using the price expiry date on the Product pricing panel of the product information page on VM2.0.18a. That prevents anyone "buying" it after that date.
[/quote]

Hi Kelvyn!

The 'Add to cart' button does not dissapear, only the price. So the customer could by the product at price 0 $ for instance.
I wondering that it could be hacking to make a sublayout. (I need this possibility only on product_horizon layout.)
Can You tell me how can I reference to the product price expire date in array $viewData['???'] ?

Best Regards,
Gyula
Title: Re: Product Automatic Expiration
Post by: GJC Web Design on October 07, 2016, 10:59:51 AM
add a snippet of code in the template to test if the exp date is passed.. if so hide the add to cart
Title: Re: Product Automatic Expiration
Post by: jenkinhill on October 07, 2016, 12:01:34 PM
The template system in VM3 is different from that in VM2. The clue is that this thread is 3.5 years old!
Title: Re: Product Automatic Expiration
Post by: djold on October 07, 2016, 12:36:59 PM
I using the latest version of VM 3.0.18. Is there a solutuion already? Maybe a plugin or something?
Title: Re: Product Automatic Expiration
Post by: GJC Web Design on October 07, 2016, 14:36:09 PM
I know of no plugin..
but this is the solution

add a snippet of code in the template to test if the exp date is passed.. if so hide the add to cart
Title: Re: Product Automatic Expiration
Post by: djold on October 10, 2016, 21:35:30 PM
Thank You the good idea. I made a script, but not inside the template.
With mysqli queries I cheking virtuemart_product_prices table and within product_price_publish_down field. If it is older than actual date, product became unpublished.
Finally with crontab I can execute it every day. (I need unpublish daily foods after p.m. 3h.)
Title: Re: Product Automatic Expiration
Post by: GJC Web Design on October 10, 2016, 22:13:22 PM
good solution
Title: Re: Product Automatic Expiration
Post by: djold on October 11, 2016, 10:22:46 AM
If somebody faceing the same problem, here is my code:
(You should insert the proper username, password and dbname of course.)


<?php
$servername 
"localhost";
$username "???";
$password "???";
$dbname "???";

// Create connection
$conn mysqli_connect($servername$username$password$dbname);
// Check connection
if (!$conn) {
    die(
"Connection failed: " mysqli_connect_error());
}

$sql "SELECT virtuemart_product_id, product_price_publish_down FROM cm42j_virtuemart_product_prices";
$result mysqli_query($conn$sql);
$current_date date("Y-m-d h:i:s");

while(
$row mysqli_fetch_assoc($result)) {
if ($row["product_price_publish_down"] <= $current_date) {
  $id $row["virtuemart_product_id"];
  
  $sql_2 "UPDATE cm42j_virtuemart_products SET published = '0' WHERE virtuemart_product_id = $id";
  $result_2 mysqli_query($conn$sql_2);
}
}

mysqli_close($conn);
?>