Author Topic: Availability Date question  (Read 10643 times)

bonny

  • Beginner
  • *
  • Posts: 18
Availability Date question
« on: November 12, 2008, 23:29:15 pm »
Is it possible to change the use of the Availability Date feature to function in reverse - in other words to act as an expiry date?

If current date is not > or == availability date then show product
else do not show product

Help would be greatly appreciated :)

johk

  • Jr. Member
  • **
  • Posts: 107
Re: Availability Date question
« Reply #1 on: January 29, 2009, 11:35:02 am »
I would like this too ie to be able to have an expiry date on a product.
Cheers
jonas

klutzon

  • Jr. Member
  • **
  • Posts: 319
  • Knuckles the Echidna
    • Rage3D
Re: Availability Date question
« Reply #2 on: January 29, 2009, 18:42:22 pm »
Hey bonny,

I see what you're saying, I don't think it should be hard to code at all. We'd just need to locate the part in the VirtueMart code that checks the product's availability and displays it if it is beyond that date, and modify it to check the product's availability and display it only if its before that date, then rename the "Availability" to "Expiry date".

I'll have to dig around, feel free to help me look. :)

johk

  • Jr. Member
  • **
  • Posts: 107
Re: Availability Date question
« Reply #3 on: January 29, 2009, 21:04:46 pm »
Maybe it is only a matter of renaming it in the language file?
I don't know though if the Availability date is tied in to any other funcyions/features of VM.
Jonas

klutzon

  • Jr. Member
  • **
  • Posts: 319
  • Knuckles the Echidna
    • Rage3D
Re: Availability Date question
« Reply #4 on: January 30, 2009, 01:48:04 am »
Maybe it is only a matter of renaming it in the language file?
I don't know though if the Availability date is tied in to any other funcyions/features of VM.
Jonas

You're right, I'm not sure if affecting the Availability will affect anything else on the site, but as far as I've seen, the Availability feature is to set when to display products on the front end, so I doubt it plays any effect on any of VM's other functions.

As I see this, you will need to modify the language file to modify the variable that shows the word "Availability" to instead show "Expiry Date", then you'll need to code the following in the backend:

1) Change the word "Availability" in the Product Status tab of the Product Details page to say "Expiry date",
2) Locate the code which displays the product based on whether the availability date is behind or ahead of the current date (if it's the same as or ahead of the current date it gets displayed), and modify it to switch it around and say display the product if the date is today or before the current date.

Or, ideally, you could repeat those two steps but with a duplicate copy of the "Availability" code modified, so that you can have the option to set the "availability" or the "expiry date" on the product details page, and depending on whether the parameters exist, the product will display or not.

The logic seems right, you just need to locate the code and then modify it ever so slightly... :)

Marc O.

  • Jr. Member
  • **
  • Posts: 78
    • Onrust Yacht Charters
Re: Availability Date question
« Reply #5 on: January 30, 2009, 12:23:07 pm »
Yes, I would also be looking for this. I already made a post in the "Feature Requests" topic:
http://forum.virtuemart.net/index.php?topic=50903.msg164167#msg164167


scottaaws

  • Beginner
  • *
  • Posts: 13
Re: Availability Date question
« Reply #6 on: February 21, 2009, 22:09:47 pm »
Did some digging and here is the code that is responsible for availability
Code: [Select]
}
if (empty($d["product_available_date"])) {
$vmLogger->err( $VM_LANG->_('VM_PRODUCT_MISSING_AVAILDATE',false) );
$valid = false;
}
else {
$day = (int) substr ( $d["product_available_date"], 8, 2);
$month= (int) substr ( $d["product_available_date"], 5, 2);
$year = (int) substr ( $d["product_available_date"], 0, 4);
$d["product_available_date_timestamp"] = mktime(0,0,0,$month, $day, $year);
}

it is in ps_product.php

also it has datbase references
Code: [Select]
'product_available_date' => $d['product_available_date_timestamp'],
'product_availability' => vmGet($d,'product_availability'),

and here is the code that attaches it to the product also in ps_product.php
Code: [Select]
/**
* Print the availability HTML code for product $prod_id
*
* @param int $prod_id
*/
function show_availability($prod_id) {
echo $this->get_availability($prod_id);
}

/**
* Returns the availability information as HTML code
* @author soeren
* @param int $prod_id
* @return string
*/
function get_availability($prod_id) {

$html = '';
$availArr = $this->get_availability_data( $prod_id );
if( !empty( $availArr )) {
$tpl = vmTemplate::getInstance();
$tpl->set( 'product_id', $prod_id );
$tpl->set( 'product_available_date', $availArr['product_available_date'] );
$tpl->set( 'product_availability', $availArr['product_availability'] );
$tpl->set( 'product_in_stock', $availArr['product_in_stock'] );
$html = $tpl->fetch( 'common/availability.tpl.php');
}
return $html;
}
/**
* Retrieves the data related to availability information
*
* @param int $prod_id
* @return array
*/
function get_availability_data( $prod_id) {
$is_parent = $this->parent_has_children( $prod_id );
$availArr = array();
if( !$is_parent ) {
$availArr['product_id'] = $prod_id;
$availArr['product_available_date'] = $this->get_field( $prod_id, 'product_available_date');
$availArr['product_availability'] = $this->get_field( $prod_id, 'product_availability');
$availArr['product_in_stock'] = $this->get_field( $prod_id, 'product_in_stock');
}
return $availArr;
}
After searching through the source code i believe all the nessecary code for availabilty is in the ps_product.php file so other than adding to the database it should be only the one file to deal with other than modifying the language file to include an expiry code. I'm going to take a crack at this and see what i can come up with, my skills are only moderate so if someone else wants to give it a try the more the better

Marc O.

  • Jr. Member
  • **
  • Posts: 78
    • Onrust Yacht Charters
Re: Availability Date question
« Reply #7 on: March 14, 2009, 21:01:26 pm »
Any news on this topic?

mxgs

  • Beginner
  • *
  • Posts: 15
Re: Availability Date question
« Reply #8 on: May 17, 2009, 19:05:04 pm »
i try posting this here too (as i did on http://forum.virtuemart.net/index.php?topic=50903.0)
i too am seriously interested on this issue, but i see there has been no more activity on the subject for the last few months...
has anyone tried any hack in the meanwhile?
thanks for sharing any info

razor7

  • Jr. Member
  • **
  • Posts: 360
    • MGSCreativa - Professional VM!
Re: Availability Date question
« Reply #9 on: August 04, 2010, 16:28:39 pm »
Hi...I'm looking into it too. Need to unpublish travel packages that are out of season.

Thanks a lot!
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store