I derive the value from the database for the feed in a loop, pre-calculating the price (there are more values, but they are not important for the question).

The request itself to the database:

$simpla->db->query("SET SQL_BIG_SELECTS=1"); $simpla->db->query("SELECT v.price, v.id as variant_id, p.name as product_name, v.name as variant_name, v.position as variant_position, p.id as product_id, p.url, p.annotation, pc.category_id, c.url as c_url, c.name as c_name, c.percent1, c.percent2, c2.name as brand_name, i.filename as image, v.st_barcode as gtin, v.sale_price as sale_price, p.in_stock, p.sale FROM __variants v LEFT JOIN __products p ON v.product_id=p.id LEFT JOIN __products_categories pc ON p.id = pc.product_id AND pc.position=(SELECT MIN(position) FROM __products_categories WHERE product_id=p.id LIMIT 1) LEFT JOIN __categories c ON pc.category_id = c.id AND c.use_category_persent > 0 LEFT JOIN __categories c2 ON c.parent_id = c2.id LEFT JOIN __images i ON p.id = i.product_id AND i.position=(SELECT MIN(position) FROM __images WHERE product_id=p.id LIMIT 1) WHERE pc.category_id > 0 AND c.visible = 1 AND p.visible = 1 AND v.price > 0 AND (v.stock >0 OR v.stock is NULL) GROUP BY v.id ORDER BY p.id, v.position "); 

Calculations and pricing:

 <?php while($p = $simpla->db->result()) { $price = $simpla->stalker->nuRound($simpla->money->markup($p->variant_id)); ?> <g:price><?=$price.' RUB'?></g:price> <?php } ?> 

When using the markup function for some reason, the while loop is exited. The markup function itself:

 public function markup($variant_id, $price=NULL) { // Расчет стоимости с наценкой брендов // @peram - ИД варианта s_variants.id // @peram - Иная цена, при отсутствии берется цена варианта // @return - Итоговая цена варианта $this->db->query("SELECT c.percent1, c.percent2, v.price FROM __categories c LEFT JOIN __products_categories pc ON c.id=pc.category_id LEFT JOIN __variants v ON pc.product_id=v.product_id WHERE v.id=? ORDER BY pc.position ASC LIMIT 1", (int)$variant_id); $result = $this->db->result(); if(!empty($result)) { if (empty($price)) $price = $result->price; $markup = $result->percent1; $markdown = $result->percent2; if($markup > 0) { $price *= 1 + $markup / 100; } if($markdown > 0) { $price *= 1 - $markdown / 100; } return round($price, 2); } return 0; } } 

Problem: I can not understand why the while loop conflicts with the markup function. Maybe you can suggest something worthwhile :) CMS, in which SIMPLA is working.

  • Apparently the work class with the base of this store curve (for $ 400 :)). We made the first request and take all the data into the array (there seems to be a results () method for that), and then loop through the array. - Visman
  • Your code rapes the base. If the first query returns 20-30 results, then you will make another 20-30 queries to the database. This is extremely not optimal. It is better to get all the necessary prices for a paste in one separate request, stuff it into a hash and get the price out of it. - Arnial
  • Thank you all) It helped! - Yumie

0