簡體   English   中英

Opencart在類別頁面上顯示庫存數量

[英]Opencart Display Stock Quantity On Category Page

我們有一個運行Opencart 1.5.2.1的二手家具網站,並希望在類別頁面上顯示數量值,以使人們無需單擊商品即可知道有多少存貨,以及產品代碼/型號,因為我們擁有大量我們網站上的商品數量,但有些可能數量很少,但他們必須手動檢查每個商品才能找到數量。 我確信這樣做很簡單,但是我的嘗試沒有奏效。 我不需要它,以便客戶可以添加到購物籃中,只需顯示庫存值即可。 這是因為我們通常不會兩次獲得相同的物料,因此庫存價值非常重要。

給出的第一個答案無助於解決我的問題,該網站為http://www.mayfairfurnitureclearance.co.uk/index.php?route=product/category&path=112_157 ,該鏈接將您直接帶到我一直在嘗試的類別,此時,通過使用第一個答案中的代碼並對其進行更改以得到結果,它在某些類別中僅顯示數字2或數字1。 當前僅在“網格”顯示模式下顯示,因為此時沒有多少人使用它。

您需要在controller / catalog / category.php中進行位修改

$this->data['products'][] = array(
                    'product_id'  => $result['product_id'],
                    'thumb'       => $image,
                    'name'        => $result['name'],
                    'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
                    'price'       => $price,
                    'special'     => $special,
                    'tax'         => $tax,
                    'rating'      => $result['rating'],
                    'reviews'     => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
                    'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])
                );

您需要將庫存值轉發到上述產品數組,並需要在類別頁面上進行回顯,例如

 $this->data['products'][] = array(
                        'product_id'  => $result['product_id'],
                        'thumb'       => $image,
                        'name'        => $result['name'],
                        'stock'       => $result['quantity']  

在view / catalog / category.tpl中

<div><?php echo $product['stock']; ?></div>

它將在類別頁面中顯示類似數量的值

如果庫存數量為零,這是在類別頁面中隱藏項目的另一種選擇。

轉到controller / product / product.php

搜索此行:

$this->data['products'][] = array(
                    'product_id'  => $result['product_id'],
                    'thumb'       => $image,
                    'name'        => $result['name'],

在“名稱” => $ result ['名稱']下,添加以下代碼:

                'stock'       => $result['quantity'],

成為:

        $this->data['products'][] = array(
            'product_id'  => $result['product_id'],
            'thumb'       => $image,
            'name'        => $result['name'],
            'stock'       => $result['quantity'],

這將獲得opencart中指示的庫存。 添加以上代碼后,請轉到view / theme / default / template / product / product.tpl

search: foreach ($products as $product) {

並添加如下內容:

<?php
foreach ($products as $product) { 
if($product['stock'] > 0) { ?> 

上面的代碼將檢查每種產品的相應庫存是否有數量。 不要忘記合上支架。

快樂編碼!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM