Shopping cart v1.1 Part 12: product page


A customer can reach to a product page from the front page, ‘Most sold’ and ‘New product’ on the right column and a category page.

Download Page

We will display all the information which we entered in the back-end. A large image, name, short description, long description, price and a BUY link which add the product details in a shopping cart and display a message to notice the customer that it added the product to the shopping cart.

webshop controller

You need to add the following function product() to module/webshop/controllers/webshop.php.
I am not using colors and sizes for the webshop. However I kept these features, so if you need, you can use them for your webshop.
The details are commented in the code.

    function product($id){
		$product = $this->MProducts->getProduct($id);
		/** this returns all, i.e. id, name, shortdesc, longdesc, thumbnail,
		 * image, grouping, status, category_id, featured and price
		 * from product db.
		 */
		if (!count($product)){
			// no product so redirect
			redirect( $this->lang->line('webshop_folder').'/index','refresh');
		}
		$data['product'] = $product;
		$data['title'] = $this->lang->line('webshop_shop_name')." | ". $product['name'];

		// I am not using colors and sizes, but you can.
		$data['assigned_colors'] = $this->MProducts->getAssignedColors($id);
		$data['assigned_sizes'] = $this->MProducts->getAssignedSizes($id);

		$data['page'] = $this->config->item('backendpro_template_shop') . 'product';
		$data['module'] = $this->lang->line('webshop_folder');
		$this->load->view($this->_container,$data);
  	}

view/product.php

module/webshop/views/shop/product.php

<div id='pleft'>
<?php
if ($this->session->flashdata('conf_msg')){
	echo "<div class='status_box'>";
	echo $this->session->flashdata('conf_msg');
	echo "</div>";
}
?>
<?php
	echo "<img src='".$product['image']."' border='0' align='left'/>\n";
	echo "<div id=\"procont\"><h2>".$product['name']."</h2>\n";
	echo $product['shortdesc'] . "<br />\n";
	echo $product['longdesc'] . "\n";
	echo "<br />";
	echo "<p><b>".$this->lang->line('webshop_price')."</b>: ". $this->lang->line('webshop_currency_symbol'). $product['price']. "</p>\n";
	echo '<p><a class="cartlinkbut" href="' . site_url()."/".
	$this->lang->line('webshop_folder').'/cart/'.$product['id'].
	'"><span class="addtocart addcart">'.$this->lang->line('webshop_buy').'</span></a></p></div>';
?>

</div>

‘BUY’ has a link to a shopping cart.
I am using $this->lang->line(‘webshop_price’) for Price so that it is easy to convert to other languages. You just need to create a language folder and file. For example, module/webshop/language/norwegian/webshop_lang.php.
And you just need to load it instead of English.
If you are using more than one language, you can find a nice library or helper in Codeigniter wiki.

11 comments to Shopping cart v1.1 Part 12: product page

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>