Author Topic: UGLY+HACK? Discounted price not on frontend before removing cookie! v. 1.1.3  (Read 5780 times)

bongobongo

  • Beginner
  • *
  • Posts: 28
Hi

Currently testing VirtueMart version 1.1.3 for a potential customer.
Also using Joomla 1.5.9.

I see that if I change the Discounted Price for a product, then the price does not update on the frontend until I delete the cookies for the site.

It is the same behaviour regardless if I change the discounted price using the "Discount Type" select field or just enter a value into the "Discounted Price" field....

Is there a setting somewhere that force the frontend to fetch data as stored in database, allways, and not from any chache or whatever......

As it is now, it is just NOT WORKING....

Note:
I have in Admin > Configurations turned "Feed Cache Settings" OFF.
And Cache settings for Joomla is OFF.

********************************************************************
After some more searching I found this thread where people report similar problems with the discounted price: Could not see a solution though...
http://forum.virtuemart.net/index.php?topic=44998.msg156449#msg156449
*********************************************************************

*********************************************************
Then, today I found this old thread after google search:
https://forum.virtuemart.net/index.php?action=printpage;topic=13957.0

Here the answers are that one have to set a short cookie lifetime in Joomla
***************************************************************************

In relation to this thread:
https://forum.virtuemart.net/index.php?action=printpage;topic=13957.0

Could some developer from VirtueMart please tell me where these Discounted prices are stored with a session.... These values that are displayed for the Discounted price must be stored somewhere...

I DO NOT want the discounted prices to be stored in any session variables...
It is totally counterintuitive for the visitor...
If the cookie life is very short, then the visitor will/may loose items in his basket, and if it is set to be long (which should be possible) then the visitor has to delete the cookies before seeing the REAL discounted prices.

This is truly weird.
I also see that if I change the actual price for the product then it is visible on the frontend without deleting the cookie(s).
So why is not the discounted price fetched at the same time as one fetch the normal price????

HERE IS WHAT I WOULD LIKE TO DO:
I need to hack into some files to make sure the discounted price are fetched at the same place where the normal price is fetched (from the database that is).
So what file do I have to hack into (could be a nice start), and if someone (developer) has time... what should be changed......


Some more testing show that if I change the Product Price (Net) at the same time as I change the Discounted Type (or Price) then it get updated without deleteing any cookies on visitors browser.

And if I change the Discount Type (or Price), it does not get updated on the product list for a give category, (and this is not good either) nor does the new discounted price get visible to user when he add the product to the basket..... So the customer can add products to cart after I change the discounted price and actually paying to much for the product... NOT GOOD!

What is going on, there must be a way to make sure that the visitors allways see what is stored in database, regardless of cookies or not.

That said... there is much to like with VirtueMart... but at the moment this
issue is a real showstopper for me, my client and their visitors....
And I really hope I do not have to use another e-commerce solution just because this odd thing is not working as it should...  :P

Regards

bongobongo

  • Beginner
  • *
  • Posts: 28
Re: BUG? Discounted price not on frontend before removing cookie! v. 1.1.3
« Reply #1 on: February 24, 2009, 12:33:18 pm »
For those that might be interested, it might save you from scratching your head.....

First: This is NOT a bug.
It is how it works now (depends on cookie settings for Joomla though).

But as most of you know, when the endusers are shopping around, they want a cookie to exist.... if not how would they see the content of their shopping basket etc....

I have found a solution to my initial issue,
the fact that if you change the discounted price, that discounted price will not be visible in products displayed for the visitor, unless his cookie is nonexistent or expired....

To "fix" this so all visitors, allways, see new discounted price, also in products that exist in his shopping basket you can do this:

FIRST A WARNING:

First: If you do not use discounted prices at all, do not consider to implement
this hack at all....

This "fix" is not a good one, but the only one I have found to work so far.
The reason I say "not a good one" is that it will force the backend to execute at least one extra query per product displayed (sometimes two and sometimes three queries)....
And the more traffic you have to your site... this can become an issue....

That said it should probably not cause any big problems for most of you....
And will make sure visitors allways see the correct discounted price...

HOW TO APPLY THE HACK SO DISCOUNTED PRICE ALLWAYS WILL SHOW CORRECT TO VISITOR REGARDLESS OF COOKIE LIFETIME

1.
Open the file:
administrator/components/com_virtuemart/classes/ps_product.php

2.
Find the function get_discount

3.
In the function get_discount, make sure that the discount info allways are fetched from the database and not from the session variable.
If you know PHP this should be easy to do.

WHAT I HOPE FOR FUTURE VERSIONS OF VirtueMart

That they make it so that this can be implemented from the backend administration panel of VirtueMart.

It should be fairly easy to do, just add a new radio button to:
Admin > Configuration > Global (tab) > Frontend Features

Something like:

Fetch discounted price from session (default selected)
As well as showing a meaningful message that tell what the result of this will be, that if cookie not expired bla bla, then the visitors will not allways see the correct discounted price for the product, not even when checking out the content of the shopping basket, or viewing the shopping basket....

Allways fetch discounted price from database
As well as showing a meaningful message that will tell that if this is selected then the correct discounted price will allways be displayed to the enduser, but that there will be extra queries against the database for each product.. bla bla...

Then it is just to add some logic into the function that honors the value in the new parameter.

Please, please VirtueMart developers, give us the administrators and developers this possibility, as to awoid the following without using the hack above:

1.
Developer and/or site admins getting very frustrated because they do not understand why the new discounted price is not visible immediately on the frontend
(depends on cookie setting in Joomla)

2.
Visitor may see or get a wrong discounted price for the product(s)....
(depends on cookie setting in Joomla)

Hope this saves others from getting frustrated....

So far I have not seen any mention about this behaviour in the documentation...
and I hope the developers of VirtueMart can at least make a big notice of how this works in future versions, and hopefully also make it so this unwanted behaviour can optionally be avoided by setting a parameter in the backend (see suggestion above)...

And at last, in future versions (if possible), an even better solution on this would be to work out a totally new way to handle the discounted price for a product, so the application does not have to do all the extra db queries for each product when fetching discounted price from database.
This way one could skip the session storage/fetching alltogether and allways fetch from database... and nobody should ever have to scratch their head again trying to figure out what is going on...


Regards



shackbase

  • Beginner
  • *
  • Posts: 13
    • Joomla Views
Does anyone have an actual hack for this, I appreciate the pointing at the place where to fix the issue but I am unfortunately not a php programmer (or any kind of programmer for that matter ;D)...

Thanks,
Tony Lindskog
For all your Joomla news check out http://www.joomlaviews.com and for specialized WordPress plugins http://cleverplugins.com.

bongobongo

  • Beginner
  • *
  • Posts: 28
Hi

Here is the hack: Use at own risk:

In this file:
administrator/components/com_virtuemart/classes/ps_product.php

Comment out all that is in the function get_discount except this line at the beginning:

Code: [Select]
global $mosConfig_lifetime;

Then add this code:

Code: [Select]
// START HACK: we want to allways fetch discount info from database

$db = new ps_DB;
$starttime = time();
$year = date('Y');
$month = date('n');
$day = date('j');
// get the beginning time of today
$endofday = mktime(0, 0, 0, $month, $day, $year) - 1440;

// Get the DISCOUNT AMOUNT
$q = "SELECT amount,is_percent FROM #__{vm}_product,#__{vm}_product_discount ";
$q .= "WHERE product_id='$product_id' AND (start_date<='$starttime' OR start_date=0) AND (end_date>='$endofday' OR end_date=0) ";
$q .= "AND product_discount_id=discount_id";
$db->query( $q );
if( $db->next_record() ) {
$discount_info["amount"] = $db->f("amount");
$discount_info["is_percent"] = $db->f("is_percent");
            $no_discount = false;
}
else {
$discount_info["amount"] = 0;
$discount_info["is_percent"] = 0;
            $no_discount = true;
}
        if ($no_discount) {
            $q = "SELECT product_parent_id FROM #__{vm}_product WHERE product_id=$product_id";
            $db->query($q);
            if($db->next_record()) {
                $q = "SELECT amount,is_percent FROM #__{vm}_product,#__{vm}_product_discount ";
       $q .= "WHERE product_id='".$db->f("product_parent_id")."' AND (start_date<='$starttime' OR start_date=0) AND (end_date>='$endofday' OR end_date=0) ";
       $q .= "AND product_discount_id=discount_id";
       $db->query( $q );
       if( $db->next_record() ) {
       $discount_info["amount"] = $db->f("amount");
       $discount_info["is_percent"] = $db->f("is_percent");
       }
            }
        }                
$discount_info['create_time'] = time();
$_SESSION['product_sess'][$product_id]['discount_info'] = $discount_info;
return $discount_info;

// END HACK

Regards