News:

Looking for documentation? Take a look on our wiki

Main Menu

Problem with multiple prices

Started by sandomatyas, February 25, 2015, 09:22:06 AM

Previous topic - Next topic

sandomatyas

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

Milbo

Interesting, I first tried to delete the last price, did not work. Then I tried to delete the first price, worked.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sandomatyas

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 :)

Milbo

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'] ){
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

moebyus

Same problem here. Anyone knows how to solve?