PV
Asked
Can I not show brand or category with 0 quantity on SHOP? I don’t want the customer to experience the brand or category that has product but no qty.
by default I set the products to load only the items those are not 0 qty but on the menu of category or brand still show up, but some of them when we click it just show nothing because those brands or categories contain products but 0 QTY.
is there anyway to fix that?
Attachments
- MSAnswered
Hello,
You can hide the categories & brands in shop settings.
If you want to check for quantity then you can replace the
getAllBrands
andgetAllCategories
methods ofapp/models/shop/Shop_model.php
public function getAllBrands() { if ($this->shop_settings->hide0) { // Only check attachment not quantity // $pc = "(SELECT count(*) FROM {$this->db->dbprefix('products')} WHERE {$this->db->dbprefix('products')}.brand = {$this->db->dbprefix('brands')}.id)"; // $this->db->select("{$this->db->dbprefix('brands')}.*, {$pc} AS product_count", false)->order_by('name'); // Check for all warehouses // $this->db->select("{$this->db->dbprefix('brands')}.*, SUM({$this->db->dbprefix('products')}.quantity) AS product_count", false)->having('product_count >', 0); // Only check shop warehouse $this->db->select("{$this->db->dbprefix('brands')}.*, SUM({$this->db->dbprefix('warehouses_products')}.quantity) AS warehouses_products_quantity", false) ->join('products', 'products.brand=brands.id', 'left') ->join('warehouses_products', 'warehouses_products.product_id=products.id', 'left') ->group_by('brands.id')->order_by('name') ->having('warehouses_products_quantity >', 0) ->where('warehouses_products.warehouse_id', $this->shop_settings->warehouse); } return $this->db->get('brands')->result(); } public function getAllCategories() { if ($this->shop_settings->hide0) { // Only check attachment not quantity // $pc = "(SELECT count(*) FROM {$this->db->dbprefix('products')} WHERE {$this->db->dbprefix('products')}.category_id = {$this->db->dbprefix('categories')}.id)"; // $this->db->select("{$this->db->dbprefix('categories')}.*, {$pc} AS product_count", false); // Check for all warehouses // $this->db->select("{$this->db->dbprefix('categories')}.*, SUM({$this->db->dbprefix('products')}.quantity) AS product_count", false)->join('products', 'products.category_id=categories.id', 'left')->group_by('categories.id')->order_by('name')->having('product_count >', 0); // Only check shop warehouse $this->db->select("{$this->db->dbprefix('categories')}.*, SUM({$this->db->dbprefix('warehouses_products')}.quantity) AS warehouses_products_quantity", false) ->join('products', 'products.category_id=categories.id', 'left') ->join('warehouses_products', 'warehouses_products.product_id=products.id', 'left') ->group_by('categories.id')->order_by('name') ->having('warehouses_products_quantity >', 0) ->where('warehouses_products.warehouse_id', $this->shop_settings->warehouse); } $this->db->group_start()->where('parent_id', null)->or_where('parent_id', 0)->group_end()->order_by('name'); return $this->db->get('categories')->result(); }
Thank you
- PVAnswered
Mian Saleem Thank you very much
- Login to Reply