brdgrn Posted December 26, 2017 Share Posted December 26, 2017 Hello and thank you for your time helping me with this issue.... Here is my situation. We sell bolts and screws. On product pages, we list items by diameter then have customers select their wanted length via options. By doing it this way, we do not have a "price" in the standard "price" field. It is left blank. I use a PHP script that pulls the lowest price from the options table and displays it in the OC price field on the product page. My problem is this > On products with more than 1 option (select length, add hex nuts, add washers) the lowest price is being pulled from the 2nd and 3rd options. I want it to only pull the price from the 1st option field (length) Below is the script I am using (written by another and yes I have tried to contact them to no avail) <modification> <id>Starting At Option Price</id> <version>1.5.x</version> <vqmver>2.1.5</vqmver> <author>qphoria</author> <file name="catalog/model/catalog/product.php"> <operation info="Move price manipulation up so it can be managed"> <search position="before"><![CDATA[ return array( ]]></search> <add><![CDATA[ $query->row['price'] = ($query->row['discount'] ? $query->row['discount'] : $query->row['price']); // Show first (lowest) option price as "Starting at" price // But for product page, to avoid issues with option price update, use a different method if ($query->row['price'] == 0) { $options = $this->getProductOptions($product_id); $option_prices = array(); if ($options) { foreach ($options as $j => $option) { if (!$option['option_value']) { continue; } foreach ($option['option_value'] as $l => $option_value) { if (!(float)$option_value['price']) { continue; } if ($option_value['price_prefix'] == '-') { $option_prices[] = -$option_value['price']; } else { $option_prices[] = $option_value['price']; } $options[$j]['option_value'][$l]['price_prefix'] = ''; } } } if ($option_prices) { sort($option_prices); //if (!isset($this->request->get['product_id']) && !isset($this->request->post['product_id'])) { //if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || $_SERVER['HTTP_X_REQUESTED_WITH']!='XMLHttpRequest' && !isset($this->request->get['product_id']) && !isset($this->request->post['product_id'])) { //if (isset($this->request->get['route']) && $this->request->get['route'] != 'product/product') { if ((!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || $_SERVER['HTTP_X_REQUESTED_WITH']!='XMLHttpRequest') && ((isset($this->request->get['route']) && $this->request->get['route'] != 'product/product') || !isset($this->request->get['route']))) { $query->row['price'] = reset($option_prices); } else { $this->session->data['start_at_price'] = $this->tax->calculate($option_prices[0], $query->row['tax_class_id']); $this->session->data['start_at_price_ex_tax'] = $option_prices[0]; } } } ]]></add> </operation> <operation info="replace the original with the new variable"> <search position="replace"><![CDATA[ ($query->row['discount'] ? $query->row['discount'] : $query->row['price']), ]]></search> <add><![CDATA[ $query->row['price'], ]]></add> </operation> </file> <file name="system/library/currency.php"> <operation> <search position="after"><![CDATA[ public function format($number, ]]></search> <add><![CDATA[ $trace = debug_backtrace(); if (isset($trace[1]['class']) && $trace[1]['class'] == 'ControllerProductProduct') { if ($number == 0 && !empty($this->session->data['start_at_price'])) { $number = $this->session->data['start_at_price']; $starting = true; unset($this->session->data['start_at_price']); } if ($number == 0 && !empty($this->session->data['start_at_price_ex_tax'])) { $number = $this->session->data['start_at_price_ex_tax']; $starting = true; unset($this->session->data['start_at_price_ex_tax']); } } ]]></add> </operation> <operation> <search position="before"><![CDATA[ return $string; ]]></search> <add><![CDATA[ if (isset($starting) && $starting) { $starting = false; $string = "Starting at $string"; } ]]></add> </operation> </file> </modification> Any help is greatly appreciated ! ! ! ! ! ! Thank you again ~ Brdgrn Quote Link to comment https://forums.phpfreaks.com/topic/305994-need-help-with-opencart-15x-price-options-script/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.