Author Topic: Problem with multiple prices  (Read 3231 times)

sandomatyas

  • Jr. Member
  • **
  • Posts: 266
Re: Problem with multiple prices
« Reply #15 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

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9825
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Problem with multiple prices
« Reply #16 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.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sandomatyas

  • Jr. Member
  • **
  • Posts: 266
Re: Problem with multiple prices
« Reply #17 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:
Code: [Select]
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9825
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Problem with multiple prices
« Reply #18 on: March 09, 2015, 15:46:57 pm »
Yeh but you just ignore in your answer

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
Code: [Select]
if($pricesToStore['virtuemart_product_price_id'] == $oldprice['virtuemart_product_price_id'] ){
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

moebyus

  • Beginner
  • *
  • Posts: 6
Re: Problem with multiple prices
« Reply #19 on: April 16, 2015, 16:53:39 pm »
Same problem here. Anyone knows how to solve?