Skip to content

Commit

Permalink
Out of stock message in product listing and details page
Browse files Browse the repository at this point in the history
  • Loading branch information
abantecart committed Oct 15, 2014
1 parent 1279e00 commit 5ad2173
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 29 deletions.
30 changes: 23 additions & 7 deletions public_html/storefront/controller/pages/product/category.php
Expand Up @@ -120,8 +120,7 @@ public function main() {
}

$this->loadModel('catalog/product');



$category_total = $this->model_catalog_category->getTotalCategoriesByCategoryId($category_id);
$product_total = $this->model_catalog_product->getTotalProductsByCategoryId($category_id);

Expand Down Expand Up @@ -150,17 +149,17 @@ public function main() {

$products = array();

$results = $this->model_catalog_product->getProductsByCategoryId($category_id,
$products_result = $this->model_catalog_product->getProductsByCategoryId($category_id,
$sort,
$order,
($page - 1) * $limit,
$limit);
foreach($results as $result){
$product_ids[] = (int)$result['product_id'];
foreach($products_result as $p){
$product_ids[] = (int)$p['product_id'];
}
$products_info = $this->model_catalog_product->getProductsAllInfo($product_ids);

foreach ($results as $result) {
foreach ($products_result as $result) {

$thumbnail = $resource->getMainThumb('products',
$result['product_id'],
Expand Down Expand Up @@ -196,6 +195,20 @@ public function main() {
}
}

//check for stock status, availability and config
$track_stock = false;
$in_stock = false;
$no_stock_text = $result['stock'];
$total_quantity = 0;
if ( $this->model_catalog_product->isStockTrackable($result['product_id']) ) {
$track_stock = true;
$total_quantity = $this->model_catalog_product->hasAnyStock($result['product_id']);
//we have stock or out of stock checkout is allowed
if ($total_quantity > 0 || $this->config->get('config_stock_checkout')) {
$in_stock = true;
}
}

$products[] = array(
'product_id' => $result['product_id'],
'name' => $result['name'],
Expand All @@ -210,6 +223,10 @@ public function main() {
'href' => $this->html->getSEOURL('product/product','&path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'], '&encode'),
'add' => $add,
'description' => html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'),
'track_stock' => $track_stock,
'in_stock' => $in_stock,
'no_stock_text' => $no_stock_text,
'total_quantity'=> $total_quantity,
);
}
$this->data['products'] = $products;
Expand All @@ -233,7 +250,6 @@ public function main() {
}

$sorts = array();

$sorts[] = array(
'text' => $this->language->get('text_default'),
'value' => 'p.sort_order-ASC',
Expand Down
24 changes: 21 additions & 3 deletions public_html/storefront/controller/pages/product/manufacturer.php
Expand Up @@ -103,17 +103,17 @@ public function main() {

$products = array();

$results = $this->model_catalog_product->getProductsByManufacturerId($this->request->get['manufacturer_id'],
$products_result = $this->model_catalog_product->getProductsByManufacturerId($this->request->get['manufacturer_id'],
$sort,
$order,
($page - 1) * $limit,
$limit);
foreach($results as $result){
foreach($products_result as $result){
$product_ids[] = (int)$result['product_id'];
}
$products_info = $this->model_catalog_product->getProductsAllInfo($product_ids);

foreach ($results as $result) {
foreach ($products_result as $result) {
$thumbnail = $resource->getMainThumb('products',
$result['product_id'],
(int)$this->config->get('config_image_product_width'),
Expand Down Expand Up @@ -150,6 +150,20 @@ public function main() {
$add = $this->html->getSecureURL('checkout/cart', '&product_id=' . $result['product_id'], '&encode');
}
}

//check for stock status, availability and config
$track_stock = false;
$in_stock = false;
$no_stock_text = $result['stock'];
$total_quantity = 0;
if ( $this->model_catalog_product->isStockTrackable($result['product_id']) ) {
$track_stock = true;
$total_quantity = $this->model_catalog_product->hasAnyStock($result['product_id']);
//we have stock or out of stock checkout is allowed
if ($total_quantity > 0 || $this->config->get('config_stock_checkout')) {
$in_stock = true;
}
}

$products[] = array(
'product_id' => $result['product_id'],
Expand All @@ -165,6 +179,10 @@ public function main() {
'href' => $this->html->getSEOURL('product/product','&manufacturer_id=' . $this->request->get['manufacturer_id'] . '&product_id=' . $result['product_id'], '&encode'),
'add' => $add,
'description' => html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'),
'track_stock' => $track_stock,
'in_stock' => $in_stock,
'no_stock_text' => $no_stock_text,
'total_quantity'=> $total_quantity,
);
}
$this->data['products'] = $products;
Expand Down
9 changes: 6 additions & 3 deletions public_html/storefront/controller/pages/product/product.php
Expand Up @@ -391,11 +391,14 @@ public function main() {
// if track stock is off. no messages needed.
if ( $this->model_catalog_product->isStockTrackable($product_id) ) {
$total_quantity = $this->model_catalog_product->hasAnyStock($product_id);

if ( $total_quantity <= 0) {
$this->data['track_stock'] = true;
//out of stock if no quantity and no stick checkout is disabled
if ( $total_quantity <= 0 && !$this->config->get('config_stock_checkout')) {
$this->data['in_stock'] = false;
//show out of stock message
$this->data['stock'] = $product_info['stock_status'];
} else {
$this->data['in_stock'] = true;
if ($this->config->get('config_stock_display')) {
$this->data['stock'] = $product_info['quantity'];
} else {
Expand All @@ -415,7 +418,7 @@ public function main() {
$msg = new AMessage();
$msg->saveNotice( $message_ttl, $message_txt);
$this->model_catalog_product->updateStatus($product_id, 0);
$this->redirect($this->html->getSEOURL('product/product','&product_id=' . $product_info['product_id'], '&encode'));
$this->redirect($this->html->getSEOURL('product/product','&product_id=' . $product_info['product_id'], '&encode'));
}
}

Expand Down
28 changes: 23 additions & 5 deletions public_html/storefront/controller/pages/product/search.php
Expand Up @@ -183,7 +183,7 @@ public function main() {

$products = array();

$results = $this->model_catalog_product->getProductsByKeyword( $this->request->get['keyword'],
$products_result = $this->model_catalog_product->getProductsByKeyword( $this->request->get['keyword'],
$category_id,
isset($this->request->get['description']) ? $this->request->get['description'] : '',
isset($this->request->get['model']) ? $this->request->get['model'] : '',
Expand All @@ -194,14 +194,14 @@ public function main() {
);

//if single result, redirect to the product
if (count($results) == 1) {
$this->redirect($this->html->getSEOURL('product/product','&product_id=' . key($results), '&encode'));
if (count($products_result) == 1) {
$this->redirect($this->html->getSEOURL('product/product','&product_id=' . key($products_result), '&encode'));
}

$resource = new AResource('image');

if (is_array($results) && $results) {
foreach ($results as $result) {
if (is_array($products_result) && $products_result) {
foreach ($products_result as $result) {
$thumbnail = $resource->getMainThumb('products',
$result['product_id'],
$this->config->get('config_image_product_width'),
Expand Down Expand Up @@ -237,6 +237,20 @@ public function main() {
$add = $this->html->getSecureURL('checkout/cart', '&product_id=' . $result['product_id'], '&encode');
}
}

//check for stock status, availability and config
$track_stock = false;
$in_stock = false;
$no_stock_text = $result['stock'];
$total_quantity = 0;
if ( $this->model_catalog_product->isStockTrackable($result['product_id']) ) {
$track_stock = true;
$total_quantity = $this->model_catalog_product->hasAnyStock($result['product_id']);
//we have stock or out of stock checkout is allowed
if ($total_quantity > 0 || $this->config->get('config_stock_checkout')) {
$in_stock = true;
}
}

$products[] = array(
'product_id' => $result['product_id'],
Expand All @@ -252,6 +266,10 @@ public function main() {
'href' => $this->html->getSEOURL('product/product','&keyword=' . $this->request->get['keyword'] . $url . '&product_id=' . $result['product_id'], '&encode'),
'add' => $add,
'description' => html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'),
'track_stock' => $track_stock,
'in_stock' => $in_stock,
'no_stock_text' => $no_stock_text,
'total_quantity'=> $total_quantity,
);
}
}
Expand Down
19 changes: 13 additions & 6 deletions public_html/storefront/model/catalog/product.php
Expand Up @@ -60,7 +60,10 @@ public function isStockTrackable ($product_id) {
$query = $this->db->query( "SELECT pov.subtract AS subtract FROM " . $this->db->table("product_options") . " po
left join " . $this->db->table("product_option_values") . " pov ON (po.product_option_id = pov.product_option_id)
WHERE po.product_id = '" . (int)$product_id . "'");
$track_status += $query->row['subtract'];

foreach ($query->rows as $row) {
$track_status += $row['subtract'];
}
return $track_status;
}

Expand All @@ -84,7 +87,9 @@ public function hasAnyStock ($product_id) {
left join " . $this->db->table("product_option_values") . " pov ON (po.product_option_id = pov.product_option_id)
WHERE po.product_id = '" . (int)$product_id . "'");

$total_quantity += $query->row['quantity'];
foreach ($query->rows as $row) {
$total_quantity += $row['quantity'];
}

return $total_quantity;
}
Expand Down Expand Up @@ -1142,8 +1147,10 @@ public function getProductsAllInfo($products=array()){
} else {
$customer_group_id = (int)$this->config->get('config_customer_group_id');
}
$language_id = (int)$this->config->get('storefront_language_id');
$store_id = (int)$this->config->get('config_store_id');

$output = $this->cache->get('product.all_info.' . md5(implode('',$products)) . '.'.$customer_group_id, $this->config->get('storefront_language_id'), (int)$this->config->get('config_store_id') );
$output = $this->cache->get('product.all_info.'.md5(implode('',$products)).'.'.$customer_group_id,$language_id,$store_id );
if(is_null($output)){ // if no cache

$sql = "SELECT product_id, price
Expand Down Expand Up @@ -1212,10 +1219,10 @@ public function getProductsAllInfo($products=array()){
ON pov.product_option_id = po.product_option_id
LEFT JOIN " . $this->db->table("product_option_value_descriptions") . " povd
ON (povd.product_option_value_id = pov.product_option_value_id
AND povd.language_id='" . (int)$this->config->get('storefront_language_id') . "')
AND povd.language_id='" . $language_id . "')
LEFT JOIN " . $this->db->table("product_option_descriptions") . " pod
ON (pod.product_option_id = po.product_option_id
AND pod.language_id='" . (int)$this->config->get('storefront_language_id') . "')
AND pod.language_id='" . $language_id . "')
WHERE po.product_id in (" . implode(', ',$products) . ")
ORDER BY pov.product_option_id, pov.product_id, po.sort_order, pov.sort_order";
$result = $this->db->query($sql);
Expand Down Expand Up @@ -1249,7 +1256,7 @@ public function getProductsAllInfo($products=array()){
$output[$product]['options'] = $options[$product];
$output[$product]['rating'] = $rating!==false ? (int)$rating[$product] : false;
}
$this->cache->set('product.all_info.' . md5(implode('',$products)) . '.'.$customer_group_id, $output, $this->config->get('storefront_language_id'), (int)$this->config->get('config_store_id') );
$this->cache->set('product.all_info.'.md5(implode('',$products)).'.'.$customer_group_id,$output,$language_id,$store_id );
}
return $output;
}
Expand Down
16 changes: 15 additions & 1 deletion public_html/storefront/view/default/stylesheet/style.css
Expand Up @@ -994,6 +994,15 @@ ul.categorymenu > li ul > li img {
text-transform: uppercase;
}

.thumbnail .nostock {
background: #ccc;
color: #fff;
float: right;
padding: 8px;
font-size: 13px;
text-transform: uppercase;
}

.thumbnail a.productcart:hover {
background: #0e5f86 url(../image/prodcutcart.png) right 7px no-repeat;
}
Expand Down Expand Up @@ -1029,7 +1038,12 @@ ul.productpagecart a.call_to_order{
ul.productpagecart a.call_to_order > i{
font-size: 26px;
}

ul.productpagecart .nostock {
background: #ccc;
color: #fff;
padding: 8px;
font-size: 16px;
}

.thumbnails>li.span3 {
min-width: 270px;
Expand Down
Expand Up @@ -170,10 +170,16 @@

<div class="mt20 ">
<?php if(!$product_info['call_to_order']){ ?>
<?php if ($track_stock && !$in_stock) { ?>
<ul class="productpagecart">
<li><span class="nostock"><?php echo $stock; ?></span></li>
</ul>
<?php } else { ?>
<ul class="productpagecart">
<li><a href="#" onclick="$(this).closest('form').submit(); return false;"
class="cart"><?php echo $button_add_to_cart; ?></a></li>
</ul>
<?php } ?>
<a class="productprint btn btn-large" href="javascript:window.print();"><i
class="fa fa-print"></i> <?php echo $button_print; ?></a>
<?php }else{?>
Expand Down
Expand Up @@ -18,9 +18,7 @@
if ($item['rating']) {
$review = $item['rating'];
}

?>

?>
<li class="col-md-3 col-sm-6 col-xs-12">
<div class="fixed_wrapper">
<div class="fixed">
Expand Down Expand Up @@ -50,7 +48,9 @@
<?php if($product['call_to_order']){ ?>
<a data-id="<?php echo $product['product_id'] ?>" href="#"
class="btn call_to_order"><?php echo $text_call_to_order?>&nbsp;&nbsp;<i class="fa fa-phone"></i></a>
<?php }else{ ?>
<?php } else if ($product['track_stock'] && !$product['in_stock']) { ?>
<span class="nostock"><?php echo $product['no_stock_text']; ?></span>
<?php } else { ?>
<a data-id="<?php echo $product['product_id'] ?>"
href="<?php echo $item['buy_url'] ?>"
class="productcart"><?php echo $button_add_to_cart ?></a>
Expand Down

0 comments on commit 5ad2173

Please sign in to comment.