rdpv Posted August 29, 2018 Share Posted August 29, 2018 (edited) Версия ocStore 2.3 Делаю расчет цены по площади, создал две опции Ширина, Высота тип Текст в product.tpl добавил под вывод цены <h2><?php echo $price; ?></h2> <input type="hidden" id="cena" name="cena" value="<?php echo (float)$price; ?>"> <h2><div id="rash"></div></h2> <input type="button" value="Рассчитать" onclick="addition();"><br> в раздел с опциями добавил скрытый custom_price <div id="product"> <?php if ($options) { ?> <hr> <input type="hidden" id="custom_price" name="custom_price" value=""> и в конец добавил скрипт расчета цены по площади <script type="text/javascript"> function addition() { var shir = parseInt(document.getElementById('input-option25').value); var vis = parseInt(document.getElementById('input-option24').value); var cena = parseInt(document.getElementById('cena').value); if (isNaN(shir)==true) shir=0; if (isNaN(vis)==true) vis=0; var plosh = ((shir * vis)/100)*cena; document.getElementById('custom_price'); document.getElementById('rash').innerHTML = "Расчетная цена: "+plosh; custom_price.value = plosh; } </script> в controller\checkout\cart.php в метод public function add() добавил public function add() { $this->load->language('checkout/cart'); $json = array(); if (isset($this->request->post['product_id'])) { $product_id = (int)$this->request->post['product_id']; } else { $product_id = 0; } $this->load->model('catalog/product'); $product_info = $this->model_catalog_product->getProduct($product_id); if ($product_info) { if (isset($this->request->post['quantity']) && ((int)$this->request->post['quantity'] >= $product_info['minimum'])) { $quantity = (int)$this->request->post['quantity']; } else { $quantity = $product_info['minimum'] ? $product_info['minimum'] : 1; } if (isset($this->request->post['option'])) { $option = array_filter($this->request->post['option']); } else { $option = array(); } if(isset($this->request->post['custom_price'])) { $custom_price = $this->request->post['custom_price']; } else { $custom_price = false; } ниже добавил if (!$json) { $this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id, $custom_price); в /system/library/cart/cart.php добавил public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price= false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { $this->session->data['custom_price'] = $custom_price; } } в метод public function getProducts() { if ($this->session->data['custom_price']) { $price = $this->session->data['custom_price']; } else { $price = $product_query->row['price']; } Цена в корзине меняется согласно расчетам но вот при добавлении другого товара в корзине цены всех товаров меняются на рассчитанную подскажите куда копать заранее благодарен. Edited August 29, 2018 by rdpv Link to comment Share on other sites More sharing options...
fanatic Posted August 29, 2018 Share Posted August 29, 2018 1 час назад, rdpv сказал: подскажите куда копать 1 час назад, rdpv сказал: if ($this->session->data['custom_price']) { $price = $this->session->data['custom_price']; //тут собака зарыта } else { $price = $product_query->row['price']; } нужно рассчитывать цену исходя из опций Link to comment Share on other sites More sharing options... chukcha Posted August 29, 2018 Share Posted August 29, 2018 1 час назад, rdpv сказал: $this->session->data['custom_price'] Что это? Откуда? Link to comment Share on other sites More sharing options... fanatic Posted August 29, 2018 Share Posted August 29, 2018 2 минуты назад, chukcha сказал: Что это? Откуда? он при добавлении товара в корзину кинул в сессиию рассчитанную стоимость товара. 1 час назад, rdpv сказал: if($custom_price) { $this->session->data['custom_price'] = $custom_price; } а в getProduct пихает ее всем товарам Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 8 hours ago, fanatic said: он при добавлении товара в корзину кинул в сессиию рассчитанную стоимость товара. а в getProduct пихает ее всем товарам Я понимаю что она подставляется всем товарам но не понимаю как ее указать конкретному товару. Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Если делать через опции то тогда каким образом увеличить цену при опции "текстовое поле"? } elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') { $option_data[] = array( 'product_option_id' => $product_option_id, 'product_option_value_id' => '', 'option_id' => $option_query->row['option_id'], 'option_value_id' => '', 'name' => $option_query->row['name'], 'value' => $value, 'type' => $option_query->row['type'], 'quantity' => '', 'subtract' => '', 'price' => '', 'price_prefix' => '', 'points' => '', 'points_prefix' => '', 'weight' => '', 'weight_prefix' => '' ); пробовал добавлять в значение price любую цифру и в prefix ставил "плюс", но она не добавляется к стоимости товара в корзине. Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Порыл в интеренете и нашел такой код public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price = false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { if(!isset($this->session->data['cart']['custom_price'])) { $this->session->data['cart']['custom_price'] = array(); } $this->session->data['cart']['custom_price'][$key] = $custom_price; } а в getProducts после $price = $product_query->row['price']; $price = $product_query->row['price']; if(isset($this->session->data['custom_price'][$key])) { $this->data[$key]['price'] = $this->session->data['custom_price'][$key]; } Но в таком случае вываливает ошибки на $key Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred inpublic_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key inpublic_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key inpublic_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170 Link to comment Share on other sites More sharing options... fanatic Posted August 30, 2018 Share Posted August 30, 2018 можно как-то так в getProducts public function getProducts() { $product_data = array(); $cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'"); $option_width = ''; $option_height = ''; foreach ($cart_query->rows as $cart) { $stock = true; } elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') { switch($option_query->row['name']){ case 'длина': $option_width = $value; break; case 'ширина': $option_height = $value; break; } $option_data[] = array( 'product_option_id' => $product_option_id, 'product_option_value_id' => '', $product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1"); if ($product_discount_query->num_rows) { $price = $product_discount_query->row['price']; } // Product Specials $product_special_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($product_special_query->num_rows) { $price = $product_special_query->row['price']; } if(!empty($option_width) && !empty($option_height)){ $price = ($option_width * $option_height)*$price; } Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо все получилось! Но пострадали товары у которых нет опций Ширина и Высота как проверить на наличие опций ширина и высота и если отсутствуют то ставить просто цену? Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 if(!empty($option_width) && !empty($option_height)){ $price = (($option_width * $option_height)/100)*$price; } else { $price = $product_query->row['price']; } Условие не помогает Link to comment Share on other sites More sharing options... fanatic Posted August 30, 2018 Share Posted August 30, 2018 15 минут назад, rdpv сказал: Но пострадали товары у которых нет опций да, я немного протупил перенесите $option_width = ''; $option_height = ''; сюда if ($product_query->num_rows && ($cart['quantity'] > 0)) { $option_price = 0; $option_points = 0; $option_weight = 0; $option_data = array(); $option_width = ''; $option_height = ''; Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо большое! Теперь все работает! Link to comment Share on other sites More sharing options... rdpv Posted August 31, 2018 Author Share Posted August 31, 2018 On 8/29/2018 at 11:17 PM, rdpv said: Версия ocStore 2.3 Делаю расчет цены по площади, создал две опции Ширина, Высота тип Текст в product.tpl добавил под вывод цены <h2><?php echo $price; ?></h2> <input type="hidden" id="cena" name="cena" value="<?php echo (float)$price; ?>"> <h2><div id="rash"></div></h2> <input type="button" value="Рассчитать" onclick="addition();"><br> в раздел с опциями добавил скрытый custom_price <div id="product"> <?php if ($options) { ?> <hr> <input type="hidden" id="custom_price" name="custom_price" value=""> и в конец добавил скрипт расчета цены по площади <script type="text/javascript"> function addition() { var shir = parseInt(document.getElementById('input-option25').value); var vis = parseInt(document.getElementById('input-option24').value); var cena = parseInt(document.getElementById('cena').value); if (isNaN(shir)==true) shir=0; if (isNaN(vis)==true) vis=0; var plosh = ((shir * vis)/100)*cena; document.getElementById('custom_price'); document.getElementById('rash').innerHTML = "Расчетная цена: "+plosh; custom_price.value = plosh; } </script> в controller\checkout\cart.php в метод public function add() добавил public function add() { $this->load->language('checkout/cart'); $json = array(); if (isset($this->request->post['product_id'])) { $product_id = (int)$this->request->post['product_id']; } else { $product_id = 0; } $this->load->model('catalog/product'); $product_info = $this->model_catalog_product->getProduct($product_id); if ($product_info) { if (isset($this->request->post['quantity']) && ((int)$this->request->post['quantity'] >= $product_info['minimum'])) { $quantity = (int)$this->request->post['quantity']; } else { $quantity = $product_info['minimum'] ? $product_info['minimum'] : 1; } if (isset($this->request->post['option'])) { $option = array_filter($this->request->post['option']); } else { $option = array(); } if(isset($this->request->post['custom_price'])) { $custom_price = $this->request->post['custom_price']; } else { $custom_price = false; } ниже добавил if (!$json) { $this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id, $custom_price); в /system/library/cart/cart.php добавил public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price= false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { $this->session->data['custom_price'] = $custom_price; } } в метод public function getProducts() { if ($this->session->data['custom_price']) { $price = $this->session->data['custom_price']; } else { $price = $product_query->row['price']; } Цена в корзине меняется согласно расчетам но вот при добавлении другого товара в корзине цены всех товаров меняются на рассчитанную подскажите куда копать заранее благодарен. Link to comment Share on other sites More sharing options... Create an account or sign in to comment You need to be a member in order to leave a comment Create an account Sign up for a new account in our community. It's easy! Register a new account Sign in Already have an account? Sign in here. Sign In Now Share More sharing options... Followers 0 Go to topic listing Similar Content Изменение цен опций через SQL запрос By openc, March 1 6 replies 386 views Denis80 May 27 Формула в поле Цена товара (опции) By grig2403, March 9 1 reply 191 views nash March 9 [Решено] Изменение модуля "Банковский перевод" 1 2 By pashast, June 14, 2011 28 replies 13,067 views vvkokoev June 3 Noticeup Price Edit/Изменение цены заказа в админке By magzhan9292, February 21, 2019 товары админка (and 2 more) Tagged with: товары админка цены изменения 0 comments 2,840 views magzhan9292 February 22, 2019 Price Control - массовое изменение цены By bokoch1995, March 10, 2018 price control контроль цены (and 3 more) Tagged with: price control контроль цены price managment массовое изменение цены изменение цен 0 comments 3,492 views bokoch1995 March 11, 2018 Recently Browsing 0 members No registered users viewing this page. Последние темы Последние дополнения Последние новости All Activity Home Поддержка и ответы на вопросы Помощь программистам и разработчикам [Решено] Изменение цены по формуле Покупателям Оплата дополнений физическими лицами Оплата дополнений юридическими лицами Политика возвратов Разработчикам Регламент размещения дополнений Регламент продаж и поддержки дополнений Виртуальный аккаунт автора Политика продвижения объявлений API каталога дополнений Урегулирование споров по авторским правам Полезная информация Публичная оферта Политика возвратов Политика конфиденциальности Платежная политика Политика Передачи Персональных Данных Политика прозрачности Последние дополнения Обновление курса валют Приватбанк, Монобанк, НБУ для Opencart/Ocstore By bogdan281989 Deluxe - адаптивный, универсальный шаблон By aridius Кнопка view в списках (товар, категория, производитель, статья) By chukcha Автоматическое заполнение URL для 4.0 By chukcha Шаблон Nice (Free Edition) для OpenCart 3 By SergeTkach × Existing user? Sign In Sign Up Shopping section Back Purchased extensions Invoices Whishlist Alternative Contacts Forums ocStore Back Official site Demo ocStore 3.0.3.2 Demo ocStore 2.3.0.2.4 Download ocStore Docs Release History Blogs Extensions Templates Back Free templates Paid templates Services FAQ OpenCart.Pro Back Demo Buy Compare Hosting for OpenCart × Create New... Important Information On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice. I accept
chukcha Posted August 29, 2018 Share Posted August 29, 2018 1 час назад, rdpv сказал: $this->session->data['custom_price'] Что это? Откуда? Link to comment Share on other sites More sharing options... fanatic Posted August 29, 2018 Share Posted August 29, 2018 2 минуты назад, chukcha сказал: Что это? Откуда? он при добавлении товара в корзину кинул в сессиию рассчитанную стоимость товара. 1 час назад, rdpv сказал: if($custom_price) { $this->session->data['custom_price'] = $custom_price; } а в getProduct пихает ее всем товарам Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 8 hours ago, fanatic said: он при добавлении товара в корзину кинул в сессиию рассчитанную стоимость товара. а в getProduct пихает ее всем товарам Я понимаю что она подставляется всем товарам но не понимаю как ее указать конкретному товару. Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Если делать через опции то тогда каким образом увеличить цену при опции "текстовое поле"? } elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') { $option_data[] = array( 'product_option_id' => $product_option_id, 'product_option_value_id' => '', 'option_id' => $option_query->row['option_id'], 'option_value_id' => '', 'name' => $option_query->row['name'], 'value' => $value, 'type' => $option_query->row['type'], 'quantity' => '', 'subtract' => '', 'price' => '', 'price_prefix' => '', 'points' => '', 'points_prefix' => '', 'weight' => '', 'weight_prefix' => '' ); пробовал добавлять в значение price любую цифру и в prefix ставил "плюс", но она не добавляется к стоимости товара в корзине. Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Порыл в интеренете и нашел такой код public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price = false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { if(!isset($this->session->data['cart']['custom_price'])) { $this->session->data['cart']['custom_price'] = array(); } $this->session->data['cart']['custom_price'][$key] = $custom_price; } а в getProducts после $price = $product_query->row['price']; $price = $product_query->row['price']; if(isset($this->session->data['custom_price'][$key])) { $this->data[$key]['price'] = $this->session->data['custom_price'][$key]; } Но в таком случае вываливает ошибки на $key Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred inpublic_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key inpublic_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key inpublic_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170 Link to comment Share on other sites More sharing options... fanatic Posted August 30, 2018 Share Posted August 30, 2018 можно как-то так в getProducts public function getProducts() { $product_data = array(); $cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'"); $option_width = ''; $option_height = ''; foreach ($cart_query->rows as $cart) { $stock = true; } elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') { switch($option_query->row['name']){ case 'длина': $option_width = $value; break; case 'ширина': $option_height = $value; break; } $option_data[] = array( 'product_option_id' => $product_option_id, 'product_option_value_id' => '', $product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1"); if ($product_discount_query->num_rows) { $price = $product_discount_query->row['price']; } // Product Specials $product_special_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($product_special_query->num_rows) { $price = $product_special_query->row['price']; } if(!empty($option_width) && !empty($option_height)){ $price = ($option_width * $option_height)*$price; } Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо все получилось! Но пострадали товары у которых нет опций Ширина и Высота как проверить на наличие опций ширина и высота и если отсутствуют то ставить просто цену? Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 if(!empty($option_width) && !empty($option_height)){ $price = (($option_width * $option_height)/100)*$price; } else { $price = $product_query->row['price']; } Условие не помогает Link to comment Share on other sites More sharing options... fanatic Posted August 30, 2018 Share Posted August 30, 2018 15 минут назад, rdpv сказал: Но пострадали товары у которых нет опций да, я немного протупил перенесите $option_width = ''; $option_height = ''; сюда if ($product_query->num_rows && ($cart['quantity'] > 0)) { $option_price = 0; $option_points = 0; $option_weight = 0; $option_data = array(); $option_width = ''; $option_height = ''; Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо большое! Теперь все работает! Link to comment Share on other sites More sharing options... rdpv Posted August 31, 2018 Author Share Posted August 31, 2018 On 8/29/2018 at 11:17 PM, rdpv said: Версия ocStore 2.3 Делаю расчет цены по площади, создал две опции Ширина, Высота тип Текст в product.tpl добавил под вывод цены <h2><?php echo $price; ?></h2> <input type="hidden" id="cena" name="cena" value="<?php echo (float)$price; ?>"> <h2><div id="rash"></div></h2> <input type="button" value="Рассчитать" onclick="addition();"><br> в раздел с опциями добавил скрытый custom_price <div id="product"> <?php if ($options) { ?> <hr> <input type="hidden" id="custom_price" name="custom_price" value=""> и в конец добавил скрипт расчета цены по площади <script type="text/javascript"> function addition() { var shir = parseInt(document.getElementById('input-option25').value); var vis = parseInt(document.getElementById('input-option24').value); var cena = parseInt(document.getElementById('cena').value); if (isNaN(shir)==true) shir=0; if (isNaN(vis)==true) vis=0; var plosh = ((shir * vis)/100)*cena; document.getElementById('custom_price'); document.getElementById('rash').innerHTML = "Расчетная цена: "+plosh; custom_price.value = plosh; } </script> в controller\checkout\cart.php в метод public function add() добавил public function add() { $this->load->language('checkout/cart'); $json = array(); if (isset($this->request->post['product_id'])) { $product_id = (int)$this->request->post['product_id']; } else { $product_id = 0; } $this->load->model('catalog/product'); $product_info = $this->model_catalog_product->getProduct($product_id); if ($product_info) { if (isset($this->request->post['quantity']) && ((int)$this->request->post['quantity'] >= $product_info['minimum'])) { $quantity = (int)$this->request->post['quantity']; } else { $quantity = $product_info['minimum'] ? $product_info['minimum'] : 1; } if (isset($this->request->post['option'])) { $option = array_filter($this->request->post['option']); } else { $option = array(); } if(isset($this->request->post['custom_price'])) { $custom_price = $this->request->post['custom_price']; } else { $custom_price = false; } ниже добавил if (!$json) { $this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id, $custom_price); в /system/library/cart/cart.php добавил public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price= false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { $this->session->data['custom_price'] = $custom_price; } } в метод public function getProducts() { if ($this->session->data['custom_price']) { $price = $this->session->data['custom_price']; } else { $price = $product_query->row['price']; } Цена в корзине меняется согласно расчетам но вот при добавлении другого товара в корзине цены всех товаров меняются на рассчитанную подскажите куда копать заранее благодарен. Link to comment Share on other sites More sharing options... Create an account or sign in to comment You need to be a member in order to leave a comment Create an account Sign up for a new account in our community. It's easy! Register a new account Sign in Already have an account? Sign in here. Sign In Now Share More sharing options... Followers 0 Go to topic listing Similar Content Изменение цен опций через SQL запрос By openc, March 1 6 replies 386 views Denis80 May 27 Формула в поле Цена товара (опции) By grig2403, March 9 1 reply 191 views nash March 9 [Решено] Изменение модуля "Банковский перевод" 1 2 By pashast, June 14, 2011 28 replies 13,067 views vvkokoev June 3 Noticeup Price Edit/Изменение цены заказа в админке By magzhan9292, February 21, 2019 товары админка (and 2 more) Tagged with: товары админка цены изменения 0 comments 2,840 views magzhan9292 February 22, 2019 Price Control - массовое изменение цены By bokoch1995, March 10, 2018 price control контроль цены (and 3 more) Tagged with: price control контроль цены price managment массовое изменение цены изменение цен 0 comments 3,492 views bokoch1995 March 11, 2018 Recently Browsing 0 members No registered users viewing this page. Последние темы Последние дополнения Последние новости All Activity Home Поддержка и ответы на вопросы Помощь программистам и разработчикам [Решено] Изменение цены по формуле Покупателям Оплата дополнений физическими лицами Оплата дополнений юридическими лицами Политика возвратов Разработчикам Регламент размещения дополнений Регламент продаж и поддержки дополнений Виртуальный аккаунт автора Политика продвижения объявлений API каталога дополнений Урегулирование споров по авторским правам Полезная информация Публичная оферта Политика возвратов Политика конфиденциальности Платежная политика Политика Передачи Персональных Данных Политика прозрачности Последние дополнения Обновление курса валют Приватбанк, Монобанк, НБУ для Opencart/Ocstore By bogdan281989 Deluxe - адаптивный, универсальный шаблон By aridius Кнопка view в списках (товар, категория, производитель, статья) By chukcha Автоматическое заполнение URL для 4.0 By chukcha Шаблон Nice (Free Edition) для OpenCart 3 By SergeTkach
fanatic Posted August 29, 2018 Share Posted August 29, 2018 2 минуты назад, chukcha сказал: Что это? Откуда? он при добавлении товара в корзину кинул в сессиию рассчитанную стоимость товара. 1 час назад, rdpv сказал: if($custom_price) { $this->session->data['custom_price'] = $custom_price; } а в getProduct пихает ее всем товарам Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 8 hours ago, fanatic said: он при добавлении товара в корзину кинул в сессиию рассчитанную стоимость товара. а в getProduct пихает ее всем товарам Я понимаю что она подставляется всем товарам но не понимаю как ее указать конкретному товару. Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Если делать через опции то тогда каким образом увеличить цену при опции "текстовое поле"? } elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') { $option_data[] = array( 'product_option_id' => $product_option_id, 'product_option_value_id' => '', 'option_id' => $option_query->row['option_id'], 'option_value_id' => '', 'name' => $option_query->row['name'], 'value' => $value, 'type' => $option_query->row['type'], 'quantity' => '', 'subtract' => '', 'price' => '', 'price_prefix' => '', 'points' => '', 'points_prefix' => '', 'weight' => '', 'weight_prefix' => '' ); пробовал добавлять в значение price любую цифру и в prefix ставил "плюс", но она не добавляется к стоимости товара в корзине. Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Порыл в интеренете и нашел такой код public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price = false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { if(!isset($this->session->data['cart']['custom_price'])) { $this->session->data['cart']['custom_price'] = array(); } $this->session->data['cart']['custom_price'][$key] = $custom_price; } а в getProducts после $price = $product_query->row['price']; $price = $product_query->row['price']; if(isset($this->session->data['custom_price'][$key])) { $this->data[$key]['price'] = $this->session->data['custom_price'][$key]; } Но в таком случае вываливает ошибки на $key Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred inpublic_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key inpublic_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key inpublic_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170 Link to comment Share on other sites More sharing options... fanatic Posted August 30, 2018 Share Posted August 30, 2018 можно как-то так в getProducts public function getProducts() { $product_data = array(); $cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'"); $option_width = ''; $option_height = ''; foreach ($cart_query->rows as $cart) { $stock = true; } elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') { switch($option_query->row['name']){ case 'длина': $option_width = $value; break; case 'ширина': $option_height = $value; break; } $option_data[] = array( 'product_option_id' => $product_option_id, 'product_option_value_id' => '', $product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1"); if ($product_discount_query->num_rows) { $price = $product_discount_query->row['price']; } // Product Specials $product_special_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($product_special_query->num_rows) { $price = $product_special_query->row['price']; } if(!empty($option_width) && !empty($option_height)){ $price = ($option_width * $option_height)*$price; } Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо все получилось! Но пострадали товары у которых нет опций Ширина и Высота как проверить на наличие опций ширина и высота и если отсутствуют то ставить просто цену? Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 if(!empty($option_width) && !empty($option_height)){ $price = (($option_width * $option_height)/100)*$price; } else { $price = $product_query->row['price']; } Условие не помогает Link to comment Share on other sites More sharing options... fanatic Posted August 30, 2018 Share Posted August 30, 2018 15 минут назад, rdpv сказал: Но пострадали товары у которых нет опций да, я немного протупил перенесите $option_width = ''; $option_height = ''; сюда if ($product_query->num_rows && ($cart['quantity'] > 0)) { $option_price = 0; $option_points = 0; $option_weight = 0; $option_data = array(); $option_width = ''; $option_height = ''; Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо большое! Теперь все работает! Link to comment Share on other sites More sharing options... rdpv Posted August 31, 2018 Author Share Posted August 31, 2018 On 8/29/2018 at 11:17 PM, rdpv said: Версия ocStore 2.3 Делаю расчет цены по площади, создал две опции Ширина, Высота тип Текст в product.tpl добавил под вывод цены <h2><?php echo $price; ?></h2> <input type="hidden" id="cena" name="cena" value="<?php echo (float)$price; ?>"> <h2><div id="rash"></div></h2> <input type="button" value="Рассчитать" onclick="addition();"><br> в раздел с опциями добавил скрытый custom_price <div id="product"> <?php if ($options) { ?> <hr> <input type="hidden" id="custom_price" name="custom_price" value=""> и в конец добавил скрипт расчета цены по площади <script type="text/javascript"> function addition() { var shir = parseInt(document.getElementById('input-option25').value); var vis = parseInt(document.getElementById('input-option24').value); var cena = parseInt(document.getElementById('cena').value); if (isNaN(shir)==true) shir=0; if (isNaN(vis)==true) vis=0; var plosh = ((shir * vis)/100)*cena; document.getElementById('custom_price'); document.getElementById('rash').innerHTML = "Расчетная цена: "+plosh; custom_price.value = plosh; } </script> в controller\checkout\cart.php в метод public function add() добавил public function add() { $this->load->language('checkout/cart'); $json = array(); if (isset($this->request->post['product_id'])) { $product_id = (int)$this->request->post['product_id']; } else { $product_id = 0; } $this->load->model('catalog/product'); $product_info = $this->model_catalog_product->getProduct($product_id); if ($product_info) { if (isset($this->request->post['quantity']) && ((int)$this->request->post['quantity'] >= $product_info['minimum'])) { $quantity = (int)$this->request->post['quantity']; } else { $quantity = $product_info['minimum'] ? $product_info['minimum'] : 1; } if (isset($this->request->post['option'])) { $option = array_filter($this->request->post['option']); } else { $option = array(); } if(isset($this->request->post['custom_price'])) { $custom_price = $this->request->post['custom_price']; } else { $custom_price = false; } ниже добавил if (!$json) { $this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id, $custom_price); в /system/library/cart/cart.php добавил public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price= false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { $this->session->data['custom_price'] = $custom_price; } } в метод public function getProducts() { if ($this->session->data['custom_price']) { $price = $this->session->data['custom_price']; } else { $price = $product_query->row['price']; } Цена в корзине меняется согласно расчетам но вот при добавлении другого товара в корзине цены всех товаров меняются на рассчитанную подскажите куда копать заранее благодарен. Link to comment Share on other sites More sharing options... Create an account or sign in to comment You need to be a member in order to leave a comment Create an account Sign up for a new account in our community. It's easy! Register a new account Sign in Already have an account? Sign in here. Sign In Now Share More sharing options... Followers 0 Go to topic listing Similar Content Изменение цен опций через SQL запрос By openc, March 1 6 replies 386 views Denis80 May 27 Формула в поле Цена товара (опции) By grig2403, March 9 1 reply 191 views nash March 9 [Решено] Изменение модуля "Банковский перевод" 1 2 By pashast, June 14, 2011 28 replies 13,067 views vvkokoev June 3 Noticeup Price Edit/Изменение цены заказа в админке By magzhan9292, February 21, 2019 товары админка (and 2 more) Tagged with: товары админка цены изменения 0 comments 2,840 views magzhan9292 February 22, 2019 Price Control - массовое изменение цены By bokoch1995, March 10, 2018 price control контроль цены (and 3 more) Tagged with: price control контроль цены price managment массовое изменение цены изменение цен 0 comments 3,492 views bokoch1995 March 11, 2018 Recently Browsing 0 members No registered users viewing this page. Последние темы Последние дополнения Последние новости All Activity Home Поддержка и ответы на вопросы Помощь программистам и разработчикам [Решено] Изменение цены по формуле
rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 8 hours ago, fanatic said: он при добавлении товара в корзину кинул в сессиию рассчитанную стоимость товара. а в getProduct пихает ее всем товарам Я понимаю что она подставляется всем товарам но не понимаю как ее указать конкретному товару. Link to comment Share on other sites More sharing options...
rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Если делать через опции то тогда каким образом увеличить цену при опции "текстовое поле"? } elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') { $option_data[] = array( 'product_option_id' => $product_option_id, 'product_option_value_id' => '', 'option_id' => $option_query->row['option_id'], 'option_value_id' => '', 'name' => $option_query->row['name'], 'value' => $value, 'type' => $option_query->row['type'], 'quantity' => '', 'subtract' => '', 'price' => '', 'price_prefix' => '', 'points' => '', 'points_prefix' => '', 'weight' => '', 'weight_prefix' => '' ); пробовал добавлять в значение price любую цифру и в prefix ставил "плюс", но она не добавляется к стоимости товара в корзине. Link to comment Share on other sites More sharing options...
rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Порыл в интеренете и нашел такой код public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price = false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { if(!isset($this->session->data['cart']['custom_price'])) { $this->session->data['cart']['custom_price'] = array(); } $this->session->data['cart']['custom_price'][$key] = $custom_price; } а в getProducts после $price = $product_query->row['price']; $price = $product_query->row['price']; if(isset($this->session->data['custom_price'][$key])) { $this->data[$key]['price'] = $this->session->data['custom_price'][$key]; } Но в таком случае вываливает ошибки на $key Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred inpublic_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key inpublic_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key inpublic_html/system/library/cart/cart.php on line 169Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170Notice: String offset cast occurred in public_html/system/library/cart/cart.php on line 170Notice: Undefined variable: key in public_html/system/library/cart/cart.php on line 170 Link to comment Share on other sites More sharing options...
fanatic Posted August 30, 2018 Share Posted August 30, 2018 можно как-то так в getProducts public function getProducts() { $product_data = array(); $cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'"); $option_width = ''; $option_height = ''; foreach ($cart_query->rows as $cart) { $stock = true; } elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') { switch($option_query->row['name']){ case 'длина': $option_width = $value; break; case 'ширина': $option_height = $value; break; } $option_data[] = array( 'product_option_id' => $product_option_id, 'product_option_value_id' => '', $product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1"); if ($product_discount_query->num_rows) { $price = $product_discount_query->row['price']; } // Product Specials $product_special_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1"); if ($product_special_query->num_rows) { $price = $product_special_query->row['price']; } if(!empty($option_width) && !empty($option_height)){ $price = ($option_width * $option_height)*$price; } Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо все получилось! Но пострадали товары у которых нет опций Ширина и Высота как проверить на наличие опций ширина и высота и если отсутствуют то ставить просто цену? Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 if(!empty($option_width) && !empty($option_height)){ $price = (($option_width * $option_height)/100)*$price; } else { $price = $product_query->row['price']; } Условие не помогает Link to comment Share on other sites More sharing options... fanatic Posted August 30, 2018 Share Posted August 30, 2018 15 минут назад, rdpv сказал: Но пострадали товары у которых нет опций да, я немного протупил перенесите $option_width = ''; $option_height = ''; сюда if ($product_query->num_rows && ($cart['quantity'] > 0)) { $option_price = 0; $option_points = 0; $option_weight = 0; $option_data = array(); $option_width = ''; $option_height = ''; Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо большое! Теперь все работает! Link to comment Share on other sites More sharing options... rdpv Posted August 31, 2018 Author Share Posted August 31, 2018 On 8/29/2018 at 11:17 PM, rdpv said: Версия ocStore 2.3 Делаю расчет цены по площади, создал две опции Ширина, Высота тип Текст в product.tpl добавил под вывод цены <h2><?php echo $price; ?></h2> <input type="hidden" id="cena" name="cena" value="<?php echo (float)$price; ?>"> <h2><div id="rash"></div></h2> <input type="button" value="Рассчитать" onclick="addition();"><br> в раздел с опциями добавил скрытый custom_price <div id="product"> <?php if ($options) { ?> <hr> <input type="hidden" id="custom_price" name="custom_price" value=""> и в конец добавил скрипт расчета цены по площади <script type="text/javascript"> function addition() { var shir = parseInt(document.getElementById('input-option25').value); var vis = parseInt(document.getElementById('input-option24').value); var cena = parseInt(document.getElementById('cena').value); if (isNaN(shir)==true) shir=0; if (isNaN(vis)==true) vis=0; var plosh = ((shir * vis)/100)*cena; document.getElementById('custom_price'); document.getElementById('rash').innerHTML = "Расчетная цена: "+plosh; custom_price.value = plosh; } </script> в controller\checkout\cart.php в метод public function add() добавил public function add() { $this->load->language('checkout/cart'); $json = array(); if (isset($this->request->post['product_id'])) { $product_id = (int)$this->request->post['product_id']; } else { $product_id = 0; } $this->load->model('catalog/product'); $product_info = $this->model_catalog_product->getProduct($product_id); if ($product_info) { if (isset($this->request->post['quantity']) && ((int)$this->request->post['quantity'] >= $product_info['minimum'])) { $quantity = (int)$this->request->post['quantity']; } else { $quantity = $product_info['minimum'] ? $product_info['minimum'] : 1; } if (isset($this->request->post['option'])) { $option = array_filter($this->request->post['option']); } else { $option = array(); } if(isset($this->request->post['custom_price'])) { $custom_price = $this->request->post['custom_price']; } else { $custom_price = false; } ниже добавил if (!$json) { $this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id, $custom_price); в /system/library/cart/cart.php добавил public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price= false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { $this->session->data['custom_price'] = $custom_price; } } в метод public function getProducts() { if ($this->session->data['custom_price']) { $price = $this->session->data['custom_price']; } else { $price = $product_query->row['price']; } Цена в корзине меняется согласно расчетам но вот при добавлении другого товара в корзине цены всех товаров меняются на рассчитанную подскажите куда копать заранее благодарен. Link to comment Share on other sites More sharing options... Create an account or sign in to comment You need to be a member in order to leave a comment Create an account Sign up for a new account in our community. It's easy! Register a new account Sign in Already have an account? Sign in here. Sign In Now Share More sharing options... Followers 0 Go to topic listing Similar Content Изменение цен опций через SQL запрос By openc, March 1 6 replies 386 views Denis80 May 27 Формула в поле Цена товара (опции) By grig2403, March 9 1 reply 191 views nash March 9 [Решено] Изменение модуля "Банковский перевод" 1 2 By pashast, June 14, 2011 28 replies 13,067 views vvkokoev June 3 Noticeup Price Edit/Изменение цены заказа в админке By magzhan9292, February 21, 2019 товары админка (and 2 more) Tagged with: товары админка цены изменения 0 comments 2,840 views magzhan9292 February 22, 2019 Price Control - массовое изменение цены By bokoch1995, March 10, 2018 price control контроль цены (and 3 more) Tagged with: price control контроль цены price managment массовое изменение цены изменение цен 0 comments 3,492 views bokoch1995 March 11, 2018 Recently Browsing 0 members No registered users viewing this page.
rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо все получилось! Но пострадали товары у которых нет опций Ширина и Высота как проверить на наличие опций ширина и высота и если отсутствуют то ставить просто цену? Link to comment Share on other sites More sharing options...
rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 if(!empty($option_width) && !empty($option_height)){ $price = (($option_width * $option_height)/100)*$price; } else { $price = $product_query->row['price']; } Условие не помогает Link to comment Share on other sites More sharing options...
fanatic Posted August 30, 2018 Share Posted August 30, 2018 15 минут назад, rdpv сказал: Но пострадали товары у которых нет опций да, я немного протупил перенесите $option_width = ''; $option_height = ''; сюда if ($product_query->num_rows && ($cart['quantity'] > 0)) { $option_price = 0; $option_points = 0; $option_weight = 0; $option_data = array(); $option_width = ''; $option_height = ''; Link to comment Share on other sites More sharing options... rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо большое! Теперь все работает! Link to comment Share on other sites More sharing options... rdpv Posted August 31, 2018 Author Share Posted August 31, 2018 On 8/29/2018 at 11:17 PM, rdpv said: Версия ocStore 2.3 Делаю расчет цены по площади, создал две опции Ширина, Высота тип Текст в product.tpl добавил под вывод цены <h2><?php echo $price; ?></h2> <input type="hidden" id="cena" name="cena" value="<?php echo (float)$price; ?>"> <h2><div id="rash"></div></h2> <input type="button" value="Рассчитать" onclick="addition();"><br> в раздел с опциями добавил скрытый custom_price <div id="product"> <?php if ($options) { ?> <hr> <input type="hidden" id="custom_price" name="custom_price" value=""> и в конец добавил скрипт расчета цены по площади <script type="text/javascript"> function addition() { var shir = parseInt(document.getElementById('input-option25').value); var vis = parseInt(document.getElementById('input-option24').value); var cena = parseInt(document.getElementById('cena').value); if (isNaN(shir)==true) shir=0; if (isNaN(vis)==true) vis=0; var plosh = ((shir * vis)/100)*cena; document.getElementById('custom_price'); document.getElementById('rash').innerHTML = "Расчетная цена: "+plosh; custom_price.value = plosh; } </script> в controller\checkout\cart.php в метод public function add() добавил public function add() { $this->load->language('checkout/cart'); $json = array(); if (isset($this->request->post['product_id'])) { $product_id = (int)$this->request->post['product_id']; } else { $product_id = 0; } $this->load->model('catalog/product'); $product_info = $this->model_catalog_product->getProduct($product_id); if ($product_info) { if (isset($this->request->post['quantity']) && ((int)$this->request->post['quantity'] >= $product_info['minimum'])) { $quantity = (int)$this->request->post['quantity']; } else { $quantity = $product_info['minimum'] ? $product_info['minimum'] : 1; } if (isset($this->request->post['option'])) { $option = array_filter($this->request->post['option']); } else { $option = array(); } if(isset($this->request->post['custom_price'])) { $custom_price = $this->request->post['custom_price']; } else { $custom_price = false; } ниже добавил if (!$json) { $this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id, $custom_price); в /system/library/cart/cart.php добавил public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price= false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { $this->session->data['custom_price'] = $custom_price; } } в метод public function getProducts() { if ($this->session->data['custom_price']) { $price = $this->session->data['custom_price']; } else { $price = $product_query->row['price']; } Цена в корзине меняется согласно расчетам но вот при добавлении другого товара в корзине цены всех товаров меняются на рассчитанную подскажите куда копать заранее благодарен. Link to comment Share on other sites More sharing options... Create an account or sign in to comment You need to be a member in order to leave a comment Create an account Sign up for a new account in our community. It's easy! Register a new account Sign in Already have an account? Sign in here. Sign In Now Share More sharing options... Followers 0
rdpv Posted August 30, 2018 Author Share Posted August 30, 2018 Спасибо большое! Теперь все работает! Link to comment Share on other sites More sharing options...
rdpv Posted August 31, 2018 Author Share Posted August 31, 2018 On 8/29/2018 at 11:17 PM, rdpv said: Версия ocStore 2.3 Делаю расчет цены по площади, создал две опции Ширина, Высота тип Текст в product.tpl добавил под вывод цены <h2><?php echo $price; ?></h2> <input type="hidden" id="cena" name="cena" value="<?php echo (float)$price; ?>"> <h2><div id="rash"></div></h2> <input type="button" value="Рассчитать" onclick="addition();"><br> в раздел с опциями добавил скрытый custom_price <div id="product"> <?php if ($options) { ?> <hr> <input type="hidden" id="custom_price" name="custom_price" value=""> и в конец добавил скрипт расчета цены по площади <script type="text/javascript"> function addition() { var shir = parseInt(document.getElementById('input-option25').value); var vis = parseInt(document.getElementById('input-option24').value); var cena = parseInt(document.getElementById('cena').value); if (isNaN(shir)==true) shir=0; if (isNaN(vis)==true) vis=0; var plosh = ((shir * vis)/100)*cena; document.getElementById('custom_price'); document.getElementById('rash').innerHTML = "Расчетная цена: "+plosh; custom_price.value = plosh; } </script> в controller\checkout\cart.php в метод public function add() добавил public function add() { $this->load->language('checkout/cart'); $json = array(); if (isset($this->request->post['product_id'])) { $product_id = (int)$this->request->post['product_id']; } else { $product_id = 0; } $this->load->model('catalog/product'); $product_info = $this->model_catalog_product->getProduct($product_id); if ($product_info) { if (isset($this->request->post['quantity']) && ((int)$this->request->post['quantity'] >= $product_info['minimum'])) { $quantity = (int)$this->request->post['quantity']; } else { $quantity = $product_info['minimum'] ? $product_info['minimum'] : 1; } if (isset($this->request->post['option'])) { $option = array_filter($this->request->post['option']); } else { $option = array(); } if(isset($this->request->post['custom_price'])) { $custom_price = $this->request->post['custom_price']; } else { $custom_price = false; } ниже добавил if (!$json) { $this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id, $custom_price); в /system/library/cart/cart.php добавил public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0, $custom_price= false) { $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); if (!$query->row['total']) { $this->db->query("INSERT " . DB_PREFIX . "cart SET api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "', customer_id = '" . (int)$this->customer->getId() . "', session_id = '" . $this->db->escape($this->session->getId()) . "', product_id = '" . (int)$product_id . "', recurring_id = '" . (int)$recurring_id . "', `option` = '" . $this->db->escape(json_encode($option)) . "', quantity = '" . (int)$quantity . "', date_added = NOW()"); } else { $this->db->query("UPDATE " . DB_PREFIX . "cart SET quantity = (quantity + " . (int)$quantity . ") WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_id . "' AND recurring_id = '" . (int)$recurring_id . "' AND `option` = '" . $this->db->escape(json_encode($option)) . "'"); } if($custom_price) { $this->session->data['custom_price'] = $custom_price; } } в метод public function getProducts() { if ($this->session->data['custom_price']) { $price = $this->session->data['custom_price']; } else { $price = $product_query->row['price']; } Цена в корзине меняется согласно расчетам но вот при добавлении другого товара в корзине цены всех товаров меняются на рассчитанную подскажите куда копать заранее благодарен. Link to comment Share on other sites More sharing options...
Recommended Posts