Post by lepe » Thu Mar 26, 2009 10:42 am

I noticed that until you add to cart, the discount is displayed... So why not showing it before adding it to the cart automatically?

This is what you need to do. I'm using v.1.2, but it may work for you.

Files to be edited:
catalog/.../template/product/product.tpl
catalog/controller/product/product.php
model/catalog/product.php

First: catalog/.../template/product/product.tpl

Change where the price is shown by:

Code: Select all

        <tr>
          <td><b><?php echo $text_price; ?></b></td>
          <td>
          <?php if (!$discount) { ?>
          <?php echo $price; ?>
          <?php } else { ?>
          <u style="color: #F00; text-decoration: line-through;"><?php echo $price; ?></u>&nbsp;>
          <?php echo $discount; ?>
          <?php } ?>
          </td>
        </tr>
You may change the "&nbsp;>" by "<br>" if you want.

Then, catalog/controller/product.php:

Add it below " $this->data['price']"

Code: Select all

$this->data['discount'] = ($product_info['discount'] ? $this->currency->format($this->tax->calculate($product_info['price'] - $product_info['discount'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : NULL);
Finally, model/catalog/product.php:

You will need to replace the whole function. Basically I Added: "d.discount" AND "LEFT JOIN product_discount d ON (p.product_id = d.product_id)" to the query.

Code: Select all

public function getProduct($product_id) {
        $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, d.discount FROM product p LEFT JOIN product_description pd ON (p.product_id = pd.product_id) LEFT JOIN product_discount d ON (p.product_id = d.product_id) LEFT JOIN manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->language->getId() . "' AND ss.language_id = '" . (int)$this->language->getId() . "' AND p.date_available <= NOW() AND p.status = '1'");
        return $query->row;
    }
That's it... still I will later add the discount to be displayed at the product list as well... that will be other post.

New member

Posts

Joined
Thu Mar 19, 2009 2:10 pm
Location - Japan

Post by lepe » Thu Mar 26, 2009 11:03 am

In order to add it to the Product List do almost the same as before, but the files to modify are:

catalog/.../template/product/category.tpl
catalog/controller/product/category.php
model/catalog/product.php

In: catalog/.../template/product/category.tpl:

Change this:

Code: Select all

<span style="color: #900; font-weight: bold;"><?php echo $products[$j]['price']; ?></span>
For this: (I changed the default red price color so the discount is more visible)

Code: Select all

        <span style="color: #000; font-weight: bold;">
          <?php if (!$products[$j]['discount']) { ?>
          <?php echo $products[$j]['price']; ?>
          <?php } else { ?>
          <u style="color: #F00; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></u><br />
          <?php echo $products[$j]['discount']; ?>
          <?php } ?>
        </span>
Then: catalog/controller/product/category.php:
Insert the line that is between the //------------ comments

Code: Select all

                    $this->data['products'][] = array(
                        'name'   => $result['name'],
                        'model'  => $result['model'],
                        'rating' => $rating,
                        'stars'  => sprintf($this->language->get('text_stars'), $rating),
                        'thumb'  => HelperImage::resize($image, 120, 120),
                        'price'  => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
//-------------------------- ADD THIS PART: --------------------------
                        'discount' => ($result['discount'] ? $this->currency->format($this->tax->calculate($result['price'] - $result['discount'], $result['tax_class_id'], $this->config->get('config_tax'))) : NULL),
//-------------------------------------------------------------------------
                        'href'   => $this->url->http('product/product&path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])
                    );
Finally: model/catalog/product.php:
I made the same as before, so basically just replace the query in
function getProductsByCategoryId()

Code: Select all

        $sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, d.discount, (SELECT AVG(r.rating) FROM review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM product p LEFT JOIN product_description pd ON (p.product_id = pd.product_id) LEFT JOIN product_discount d ON (p.product_id = d.product_id) LEFT JOIN manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN product_to_category p2c ON (p.product_id = p2c.product_id) WHERE p.status = '1' AND pd.language_id = '" . (int)$this->language->getId() . "' AND ss.language_id = '" . (int)$this->language->getId() . "' AND p2c.category_id = '" . (int)$category_id. "' AND p.date_available <= NOW() AND p.status = '1'";
That's all... It would be almost the same procedure to make the changes in the "Lastest Products"

New member

Posts

Joined
Thu Mar 19, 2009 2:10 pm
Location - Japan

Post by lepe » Thu Mar 26, 2009 11:29 am

The same as before, so I will just add this time the important things.

Files to be modified:
catalog/.../template/common/home.tpl
catalog/controller/common/home.php
model/catalog/product.php

For the model/catalog/product:
function: getLatestProducts()

Code: Select all

$query = $this->db->query("SELECT * FROM product p LEFT JOIN product_description pd ON (p.product_id = pd.product_id)  LEFT JOIN product_discount d ON (p.product_id = d.product_id) WHERE p.status = '1' AND pd.language_id = '" . (int)$this->language->getId() . "' AND p.date_available <= NOW() AND p.status = '1' ORDER BY p.date_added DESC LIMIT " . (int)$limit);
You can imagine now how to do it if you want to add it to any other place where the price is displayed without discount.

Cheers!

New member

Posts

Joined
Thu Mar 19, 2009 2:10 pm
Location - Japan

Post by lepe » Thu Mar 26, 2009 3:59 pm

The query in LastestProducts should be:

Code: Select all

            $query = $this->db->query("SELECT p.*,pd.*,d.discount FROM product p LEFT JOIN product_description pd ON (p.product_id = pd.product_id) LEFT JOIN product_discount d ON (p.product_id = d.product_id) WHERE p.status = '1' AND pd.language_id = '" . (int)$this->language->getId() . "' AND p.date_available <= NOW() AND p.status = '1' ORDER BY p.date_added DESC LIMIT " . (int)$limit);
Otherwise the d.product_id overwrites the p.product_id with NULL when no discount is applied.

New member

Posts

Joined
Thu Mar 19, 2009 2:10 pm
Location - Japan

Post by lepe » Tue Mar 31, 2009 11:06 am

NOTE: in 1.2.5 "Special" was introduced, so you may want to use that feature instead of this procedure.

If you want still to use "Discount" as your default setting to be displayed in products, then follow this procedure which its the enhanced version of the previous posts:

I noticed that if you use a quantity discount greater than 1, it will display wrongly that the article has discount. I fixed this, showing it only when the discount_quantity=1.

So, THIS alternative is better to be used to prevent messing the default queries (which will not affect if you merge files while updating):

First, in: model/catalog/product.php:
Add (at the end of the file):

Code: Select all

    public function getProductDiscount($product_id) {
        $query = $this->db->query("SELECT discount FROM product_discount pd WHERE pd.quantity = '1' AND pd.product_id = '$product_id'");
        return isset($query->row['discount']) ? $query->row['discount'] : 0;
    }
Now, modify these files in catalog/controller/product/:
* category.php
* manufacturer.php
* search.php
* special.php

Add (preferable right before " $this->data['products']"):

Code: Select all

 $discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
in "$this->data['products'][] = array("
...

Code: Select all

'discount' => ($discount ? $this->currency->format($this->tax->calculate($result['price'] - $discount, $result['tax_class_id'], $this->config->get('config_tax'))) : NULL),
...

Add in "product.php" (after "$this->data['price']"):

Code: Select all

 $discount = $this->model_catalog_product->getProductDiscount($this->request->get['product_id']);
$this->data['discount'] = ($discount ? $this->currency->format($this->tax->calculate($product_info['price'] - $discount, $product_info['tax_class_id'], $this->config->get('config_tax'))) : NULL);

Now, to show it, modify in "template/products/*" where the price is shown to:

Code: Select all

<span style="color: #000; font-weight: bold;">
          <?php if (!$products[$j]['discount']) { ?>
          <?php echo $products[$j]['price']; ?>
          <?php } else { ?>
          <u style="color: #F00; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></u><br />
          <?php echo $products[$j]['discount']; ?>
          <?php } ?>
</span><br />
except for product.tpl, that is:

Code: Select all

        <tr>
          <td><b><?php echo $text_price; ?></b></td>
          <td>
          <?php if (!$discount) { ?>
          <?php echo $price; ?>
          <?php } else { ?>
          <u style="color: #F00; text-decoration: line-through;"><?php echo $price; ?></u>&nbsp;>
          <?php echo $discount; ?>
          <?php } ?>
          </td>
        </tr>

New member

Posts

Joined
Thu Mar 19, 2009 2:10 pm
Location - Japan

Post by kris » Fri Sep 18, 2009 10:28 am

HI HELP,

I'm very new to programing in SQL , If I could do it in the Opencart admin, that would be better.
I have entered in all my products and discounts/ specials. but neither one is being displayed. All I get is the original price.
In 1.3.0 it showed the price crossed out with the discounted price next to it.
I upgraded to 1.3.2, with many headaches and the everything is working except the pricing discount/specials. I only get the original price.

Please Help.

I am using the default template. Are there any other templates I can use, if so, where can i get them.

thanks

Newbie

Posts

Joined
Thu Sep 10, 2009 9:53 am
Who is online

Users browsing this forum: No registered users and 11 guests