Author Topic: How does the tableproductprice class know which price is default?  (Read 550 times)

KLH

  • Beginner
  • *
  • Posts: 5
Context: I am fixing a Virtuemart modification that is supposed to allow you to update the product database by uploading an excel spreadsheet. I have it working now, but currently it is only capable of updating the default price associated with a product.

Question: How does the tableproductprice class pick out the default price from multiple prices when querying based on product_id as it does in the load() method (c. Line 22, administrator/components/com_virtuemart/tables/productprice.php)?

Each of our products at http://www.katieslighthouse.com has two prices, one for a wholesale shopper group, one for a retail shopper group. Therefore, when querying the vm_product_price table based on a product id the mysql result object contains two rows. The load method of the tableproductprice class does not contain logic to discern the default price, yet somehow it always manages to return the row containing the default price.

This behavior seems to be the result of the fact that the default price entry is always the first result when the product_price table is queried. I did a manual query based on product price, and sure enough the default price came up first. Then I switched the price_id for each of the entries to see if mysql was automatically sorting by primary key. The default price showed up first even with the id number reversed. Then I thought mysql was returning results based on whatever price was added to the database first. So I deleted the default price and added it again. Again, the query came back with the default price.

I'm relatively new to php and mysql, so I'm certain that I must be missing something. Is there something in the table structure of vm_product_price that is forcing the default price to come up first?

VirtueMart Forum