VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: sandomatyas on February 25, 2015, 09:22:06 AM

Title: Problem with multiple prices
Post by: sandomatyas on February 25, 2015, 09:22:06 AM
I have a webshop with Joomla 3.3.6 and VirtueMart 3.0.6 and I want to add a special price to one of my products which is available for three days.
So I selected the product to edit, added a new price but I can't set the date ranges

I've just tested it on the official demo site and the problem appears there, too.

Could you fix it please? Or is there a fast hotfix maybe? I should use it very soon.
Thanks
Title: Re: Problem with multiple prices
Post by: Milbo on February 25, 2015, 10:09:16 AM
Thank you, I check it now.
Title: Re: Problem with multiple prices
Post by: Milbo on February 25, 2015, 10:49:03 AM
hunted down
Title: Re: Problem with multiple prices
Post by: sandomatyas on February 26, 2015, 07:34:38 AM
Is there maybe a hotfix?
Title: Re: Problem with multiple prices
Post by: sandomatyas on February 26, 2015, 14:36:03 PM
Couple more things.

Could you help me use this tool? The main goal is create a one day discount. I mean the product have a standard price which is e.g. €10 but I want to set a special discount price just for a day e.g. €8. How can I manage this? What happens if there are two active prices for the product? The first one doesn't have publish_up or publish_down value, because it is the standard price. I add a new price with date limits or even just a publish_up or just a publish_down value but how can I know which one is the active one?
In my opinion the best way would be some kind of ordering of the prices. There is a drag&drop with the price boxes but I can't see an order field in #__virtuemart_product_prices. So if there would be an order field you could use the first matching price. If I check the loadProductPrices function in VirtueMartModelProduct class the value of the ORDER BY clause is 'ORDER BY product_price DESC'. The higher price is always 'stronger'?

Another question: The type of the date range fields in the database is DATETIME. It means VM stores the whole date with time but on the admin I see only a date field. Moreover, the format is with a two-digits year. Can I change it somehow to 4 digits year at least? However a datetime picker would be much better, then I could add a hourly discount, too.

And the third one: What's about the timezones? The created_on and modified_on fields are in UTC but what's about the publish_up or publish_down fields? My shop is in UTC+1 CET timezone. If I set the price ranges to a date it gets a 00:00:00 time in the database. When will be my price active in UTC?

Sorry about the lot of questions :)
Title: Re: Problem with multiple prices
Post by: Milbo on February 26, 2015, 14:52:19 PM
The ordering would lead into big confusion.
The ordering is by value and if there is a conflict (more than one price available) it takes the higher price
Title: Re: Problem with multiple prices
Post by: sandomatyas on February 26, 2015, 15:13:25 PM
Okay I can accept this. But maybe a flag for the direction? Higher/lower price if there is a confict?
Title: Re: Problem with multiple prices
Post by: sandomatyas on March 03, 2015, 10:24:11 AM
I've just checked the latest 3.0.6.2 version.
I can use the datepicker on the fields but I can't use the date reset icon.
I've checked a source a bit and as far as I can see you might need a change in the vmJsApi helper in the line 714.
The original is:
$(".js-date-reset").click(function() {
But it might need this, because the second price is dynamically created:
$(document).on( "click",".js-date-reset", function() {
If I change this line it works well.
Title: Re: Problem with multiple prices
Post by: sandomatyas on March 04, 2015, 10:16:40 AM
Another price-related problem:
Somethimes I can't delete a product price if I have multiple ones. I click on the red icon, the JavaScript removes the box but if I save it comes back.
I checked the sourcecode and found this:
In the VirtueMartModelProduct there is a script to delete prices if there are some unnecessary ones.
Let's assume that I start a new shop and I have one price to one product. It means in the database I have the same virtuemart_product_price_id  and virtuemart_product_id because both tables have autoincrement ID fields.
But now I add a product with two prices. So my virtuemart_product_id==1 and there are two prices with virtuemart_product_price_id==1 and virtuemart_product_price_id==2
Then check the code around line 1771 in the product model:
if(array_search($pricesToStore['virtuemart_product_price_id'], $oldprice )){
If we had two prices and we wanted to delete one of them (e.g the first one), at this point we have one ID in $pricesToStore['virtuemart_product_price_id'] (==2) and the $oldprice array with two elements (both of price record from the database).
The code wants to check if we have a price to keep. But if we use array_search, its always true in this scenario because the function returns true because it finds the $pricesToStore['virtuemart_product_price_id'] (==1) as a 'virtuemart_product_price' field in the $oldprices array which is also equals 1.
So I think it would be better if we wrote a simple check instead the array_search, like this
if($pricesToStore['virtuemart_product_price_id']==$oldprice['virtuemart_product_price_id'] ){
It would find the exact match with the correct field of the array.
I've checked it on my site and I think it works well.
Title: Re: Problem with multiple prices
Post by: lindapowers on March 04, 2015, 10:44:46 AM
I confirm this bug too. The only way to remove multiple prices is removing all prices, saving and adding them again. Bug present in vm2 & 3.
Title: Re: Problem with multiple prices
Post by: Milbo on March 05, 2015, 17:25:32 PM

I cannot reproduce ...

Quote from: sandomatyas on March 04, 2015, 10:16:40 AM
The code wants to check if we have a price to keep. But if we use array_search, its always true in this scenario ....

I doubt it, furthermore the code handling the price is 100 lines. The line you are talking about is checking if an old price entry is to be reused.
Title: Re: Problem with multiple prices
Post by: Milbo on March 06, 2015, 17:11:33 PM
I am sorry, I cannot reproduce it. I also tried with j3.4. I created 5 prices, in 2 steps. I deleted them, one time the last, or one of the middle, or the first, works always for me.
Title: Re: Problem with multiple prices
Post by: Milbo on March 06, 2015, 17:23:15 PM
Quote from: sandomatyas on March 03, 2015, 10:24:11 AM
I've just checked the latest 3.0.6.2 version.
I can use the datepicker on the fields but I can't use the date reset icon.
I've checked a source a bit and as far as I can see you might need a change in the vmJsApi helper in the line 714.
The original is:
$(".js-date-reset").click(function() {
But it might need this, because the second price is dynamically created:
$(document).on( "click",".js-date-reset", function() {
If I change this line it works well.

Thanks, yes that should work. But as you maybe noticed, this parts of the code are quite old. I think the .on method was not even available at that time. One of the changes from 3.0.4 to 3.0.6 was to change at least some of the frontend js to use the new .on method. We are going now more and more to change it. If you have more updates like that, always welcome.
Title: Re: Problem with multiple prices
Post by: sandomatyas on March 07, 2015, 06:53:40 AM
Sure, I'm always looking for a solution too.
BTW I sent you a message yesterday about the multi-price problem
Title: Re: Problem with multiple prices
Post by: Milbo on March 07, 2015, 09:39:02 AM
As I said, it works perfect for me. Do you work maybe with a migrated product?
Title: Re: Problem with multiple prices
Post by: sandomatyas on March 09, 2015, 07:39:32 AM
No, totally fresh install of Joomla and VM, no modifications, basic english lang, etc. Only one product with two prices. I sent you a video and also the login to the demo site by PM
Title: Re: Problem with multiple prices
Post by: Milbo on March 09, 2015, 10:03:13 AM
Interesting, I first tried to delete the last price, did not work. Then I tried to delete the first price, worked.
Title: Re: Problem with multiple prices
Post by: sandomatyas on March 09, 2015, 15:01:21 PM
Exactly. If you try to delete the first price, VM tries to keep the second price.
Here is an example dump of $old_price_ids from the model:
Array
(
    [0] => Array
        (
            [virtuemart_product_price_id] => 1
            [virtuemart_product_id] => 1
            [virtuemart_shoppergroup_id] => 0
            [product_price] => 200.000000
            [override] => 0
            [product_override_price] => 0.00000
            [product_tax_id] => 0
            [product_discount_id] => 0
            [product_currency] => 191
            [product_price_publish_up] => 0000-00-00 00:00:00
            [product_price_publish_down] => 0000-00-00 00:00:00
            [price_quantity_start] => 0
            [price_quantity_end] => 0
            [created_on] => 2015-03-09 13:43:10
            [created_by] => 50
            [modified_on] => 2015-03-09 13:43:10
            [modified_by] => 50
            [locked_on] => 0000-00-00 00:00:00
            [locked_by] => 0
        )

    [1] => Array
        (
            [virtuemart_product_price_id] => 2
            [virtuemart_product_id] => 1
            [virtuemart_shoppergroup_id] => 0
            [product_price] => 100.000000
            [override] => 0
            [product_override_price] => 0.00000
            [product_tax_id] => 0
            [product_discount_id] => 0
            [product_currency] => 191
            [product_price_publish_up] => 0000-00-00 00:00:00
            [product_price_publish_down] => 0000-00-00 00:00:00
            [price_quantity_start] => 0
            [price_quantity_end] => 0
            [created_on] => 2015-03-09 13:43:01
            [created_by] => 50
            [modified_on] => 2015-03-09 13:43:10
            [modified_by] => 50
            [locked_on] => 0000-00-00 00:00:00
            [locked_by] => 0
        )


If you check the product model and the foreach in line 1770 the $old_price_ids array contains both of the prices as above and $pricesToStore['virtuemart_product_price_id'] == 2. The return value of array_search is false in the first case because there is no "2" value anywhere in the $old_price_ids[0] array. The second one is true because $old_price_ids[1]['virtuemart_product_price_id'] == 2. So it'll work well, VM will delete the first price and keep the second one.
But if you try to delete the first price _in this scenario_ array_search returns true. In this case $pricesToStore['virtuemart_product_price_id'] == 1 and array_search will be true because there is value "1" in both of prices. Not as a virtuemart_product_price_id but as a virtuemart_product_id. It souldn't return true with the second element of the array.

I know my English isn't the best, I try to explain it clearly :)
Title: Re: Problem with multiple prices
Post by: Milbo on March 09, 2015, 15:46:57 PM
Yeh but you just ignore in your answer

Quote from: Milbo on March 06, 2015, 17:11:33 PM
I am sorry, I cannot reproduce it. I also tried with j3.4. I created 5 prices, in 2 steps. I deleted them, one time the last, or one of the middle, or the first, works always for me.

I cant find a real cause, but maybe exchange the array_search against

if($pricesToStore['virtuemart_product_price_id'] == $oldprice['virtuemart_product_price_id'] ){
Title: Re: Problem with multiple prices
Post by: moebyus on April 16, 2015, 16:53:39 PM
Same problem here. Anyone knows how to solve?