Jump to content
Sign in to follow this  
SWORDMAN

[Решено] Вывести 2 цены в карточке товара

Recommended Posts

Здравствуйте. Есть 2 группы покупателей - розница и опт. Подскажите пожалуйста как для группы "розница" (по умолчанию) вывести в карточке товара кроме розничной цены еще и оптовую.

 

Пытался выводить переменную $special в product.tpl - ничего не выводит. Также пробовал в product.php создать переменную "opt" и туда записать:



 $this->data['opt'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));$this->data['otp'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));

выводит '0 грн'.

 

PS Opencart 1.5.5.1 

Цена для оптовиков вводилась как акции

Share this post


Link to post
Share on other sites

Поддерживаю. Тоже прикупил бы данный модуль в готовом решении.

Share this post


Link to post
Share on other sites

Или по другому вопрос) В какой переменной хранится акционная цена товара? По идее должна в переменной $special в product.tpl. И выводится здесь:



<?php if (!$special) { ?>
<?php echo $price; ?>
<?php } else { ?>
<span class="price-old"><?php echo $price; ?></span> <span class="price-new"><?php echo $special; ?></span>
<?php } ?>

Но если попробовать ее вывести в 



<?php echo $price; echo $special; ?>

ничего не выводится

Share this post


Link to post
Share on other sites

цены выбираются по группам покупателей.

чтобы для розницы показать оптовые цены надо проделать несколько больше телодвижений, нежели

...echo $special;...
и делать эти оптовые цены советую скидками, а не акциями.

при чем тут модуль?

Share this post


Link to post
Share on other sites

Было сделано акциями, поздно переделывать. Так подскажите что именно надо поменять, думаю многим будет интересно. Нигде в интернете решения не нашел

Share this post


Link to post
Share on other sites

В /www/catalog/model/catalog/product.php (перед public function getProduct($product_id) {) добавить 









public function getProductSword($product_id) {
		if ($this->customer->isLogged()) {
			$customer_group_id = '2';
		} else {
			$customer_group_id = '2';
		}	
				
		$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < '" . $this->NOW . "') AND (pd2.date_end = '0000-00-00' OR pd2.date_end > '" . $this->NOW . "')) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < '" . $this->NOW . "') AND (ps.date_end = '0000-00-00' OR ps.date_end > '" . $this->NOW . "')) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= '" . $this->NOW . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
		
		
		if ($query->num_rows) {
		
		
		
			return array(
				
				'special'          => $query->row['special'],
				'tax_class_id'     => $query->row['tax_class_id']
				
			);
		} else {
			return false;
		}
	}

В /www/catalog/controller/product/product.php (после $this->load->model('catalog/product');









$product_infoSword = $this->model_catalog_product->getProductSword($product_id);
		if ($product_infoSword) {
					
		$this->data['special2'] = $this->currency->format($this->tax->calculate($product_infoSword['special'], $product_infoSword['tax_class_id'], $this->config->get('config_tax')));
					
		}

После 

			foreach ($results as $result) {
				$this->data['images'][] = array(
					'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
					'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
				);
			}

Добавить

	if ((float)$product_info['special']) {
			$this->data['special2'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));	
			}

В /www/catalog/view/theme/default/template/product/product.tpl ( после <?php if (!$special) { ?> <?php echo $price;







echo "<br><font size='2' color='green'>".$special2."</font>";

Share this post


Link to post
Share on other sites

А где задаётся вторая цена?

 

У меня в акциях. Табличка в бд oc_product_special, поле price 

 

Или может вы об этой строчке 

if ((float)$product_info['special']) {
			$this->data['special2'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));	
			}

Забыл ее написать, исправил

Share this post


Link to post
Share on other sites

Как сделать вывод двух цен на странице с категорией?

Share this post


Link to post
Share on other sites
57 минут назад, indaled72 сказал:

Как это повторить для opecart 2.1?

 

Для этого нужно изменить запрос к БД в решении предложенном выше

 

$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, (SELECT md.name FROM " . DB_PREFIX . "manufacturer_description md WHERE md.manufacturer_id = p.manufacturer_id AND md.language_id = '" . (int)$this->config->get('config_language_id') . "') AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");

Share this post


Link to post
Share on other sites

В /www/catalog/model/catalog/product.php (перед public function getProduct($product_id) {) добавить 

public function getProductSword($product_id) {
   if ($this->customer->isLogged()) {
      $customer_group_id = '2';
   } else {
      $customer_group_id = '2';
   }

   $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special,  p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");

   if ($query->num_rows) {
      return array(
         'special2'          => $query->row['special'],
         'tax_class_id'     => $query->row['tax_class_id']
      );
   } else {
      return false;
   }
}

В /www/catalog/controller/product/product.php (после $this->load->model('catalog/product');  (вставлять именно в таком виде, а не как у автора)

$product_infoSword = $this->model_catalog_product->getProductSword($product_id);
if ($product_infoSword) {

   $data['special2'] = $this->currency->format($this->tax->calculate($product_infoSword['special2'], $product_infoSword['tax_class_id'], $this->config->get('config_tax')));

   if ((float)$product_infoSword['special2']) {
      $data['special2'] = $this->currency->format($this->tax->calculate($product_infoSword['special2'], $product_infoSword['tax_class_id'], $this->config->get('config_tax')));
   } else {
      $data['special2'] = false;
   }
   
}

В /www/catalog/view/theme/default/template/product/product.tpl

<?php if ($price) { ?>
<ul class="list-unstyled">
    <?php if ($special2)  { ?>
        <li><span style="text-decoration: line-through;"><?php echo $price; ?></span></li>
        <li>
            <h2><?php echo $special2; ?></h2>
        </li>
        <?php } else { ?>
        <?php if (!$special) { ?>
        <li>
            <h2><?php echo $price; ?></h2>
        </li>
        <?php } else { ?>
        <li><span style="text-decoration: line-through;"><?php echo $price; ?></span></li>
        <li>
            <h2><?php echo $special; ?></h2>
        </li>
        <?php } ?>
        <?php if ($points) { ?>
        <li><?php echo $text_points; ?> <?php echo $points; ?></li>
        <?php } ?>
        <?php if ($discounts) { ?>
        <li>
            <hr>
        </li>
        <?php foreach ($discounts as $discount) { ?>
        <li><?php echo $discount['quantity']; ?><?php echo $text_discount; ?><?php echo $discount['price']; ?></li>
        <?php } ?>
        <?php } ?>
    <?php } ?>
</ul>
<?php } ?>

 

Edited by indaled72

Share this post


Link to post
Share on other sites

а что курить в опенкарте 3.0 для решения этой же задачи?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

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.