Post by yarac » Mon Apr 30, 2012 12:23 pm

Instead of showing ***, I would like to display the actual availability status e.g. Pre-order or In-stock.

I figured should be using php echo $stock somehow, but I got undefined variable: stock error.
Any help appreciated.
Last edited by yarac on Wed May 09, 2012 11:08 am, edited 2 times in total.

New member

Posts

Joined
Thu Apr 12, 2012 12:24 pm

Post by Avvici » Mon Apr 30, 2012 8:32 pm

In order to show something different than the *** do the following:
Open : catalog/controller/checkout/cart.php and find this code:

Code: Select all

$this->data['products'][] = array(
          			'key'      => $product['key'],
          			'thumb'    => $image,
					'name'     => $product['name'],
          			'model'    => $product['model'],
          			'option'   => $option_data,
          			'quantity' => $product['quantity'],
          			'stock'    => $product['stock'],
					'reward'   => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
					'price'    => $price,
					'total'    => $total,
					'href'     => $this->url->link('product/product', 'product_id=' . $product['product_id']),
					'remove'   => $this->url->link('checkout/cart', 'remove=' . $product['key'])
				);
REPLACE it with this:

Code: Select all

$this->language->load('product/product');
            $this->load->model('catalog/product');
              $product_info = $this->model_catalog_product->getProduct($product['product_id']);
            if ($product['stock'] == false) {
            $stock = $product_info['stock_status'];
                  } else {
            $stock = $this->language->get('text_instock');
         }
        		$this->data['products'][] = array(
          			'key'      => $product['key'],
          			'thumb'    => $image,
					'name'     => $product['name'],
          			'model'    => $product['model'],
          			'option'   => $option_data,
          			'quantity' => $product['quantity'],
          			'stock'    => $stock,
					'reward'   => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''),
					'price'    => $price,
					'total'    => $total,
					'href'     => $this->url->link('product/product', 'product_id=' . $product['product_id']),
					'remove'   => $this->url->link('checkout/cart', 'remove=' . $product['key'])
				);
Now open up: catalog/view/theme/default/template/checkout/cart.php and find the following:

Code: Select all

 <?php if (!$product['stock']) { ?>
                <span class="stock">***</span>
                <?php } ?>
Replace that with this:

Code: Select all

 <span class="stock"><?php echo $product['stock']; ?></span>
That will work just fine.
Now that you have your fix you may be interested in how the *** actually comes about.
This is taken care of by as simple Boolean TRUE or FALSE from the getProducts() core function.

Code: Select all

$stock = true;
// Stock
					if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $quantity)) {
						$stock = false;
					}
getProducts() is called from the cart.php control file and the Boolean is placed in this array:

Code: Select all

$this->data['products'][] = array('stock'    => $product['stock'],
The red *** shows up if it returns FALSE, and disappears if returns TRUE here:

Code: Select all

 <?php if (!$product['stock']) { ?>
              <span class="stock">***</span>
              <?php } ?>

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC
Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 112 guests