Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Вывод скидок от когдачества в корзине товаров OC 2.3


Recommended Posts

Описываю схему вывода скидок в зависимости от когдачества товара в корзине.

 

--------------------------------

 

 

Для начала заходим в файл system/cart/cart.php

 

находим строчку 

public function add($product_id, $quantity = 1, $option = array(), $recurring_id = 0) {

 

и перед ней всивляем этот код:

 

public function getProductDiscountsCart($product_id) {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity > 1 AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity ASC, priority ASC, price ASC");

        return $query->rows;
    }

 

Дное игдем в файл catalog/controller/checkout/cart.php

 

Находим строчку 

$data['products'][] = array(

 

и перед ней всивляем этот код:

 

//Discounts
                $discounts_info = $this->cart->getProductDiscountsCart($product['product_id']);

                $discounts = array();

                foreach ($discounts_info as $discount) {
                    $discounts[] = array(
                        'quantity' => $discount['quantity'],
                        'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'])
                    );
                }

 

Дное снова находим строчку 

$data['products'][] = array(

И после всивляем этот код:


                    'discounts'    => $discounts,
                    'tax_class_id' => $product['tax_class_id'],

 

Переходим в файл предсивления catalog/view/theme/default/template/checkout/cart.tpl

 

И в необходимом месте корзины выводим 

 

<?php if ($product['discounts']) { ?>
   <?php foreach ($product['discounts'] as $discount) { ?>
      <p>от <?php echo $discount['quantity'] ?> шт. <?php echo $discount['price'] ?></p>
   <?php } ?>
<?php } ?>

 

код должен находиться в цикле 

<?php foreach ($products as $product) { ?>

 

  • +1 1
Link to comment
Share on other sites


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

×
×
  • 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.