I am currently working on an ecommerce website using opencart, trying to show the weight of each product, in product details template it works, however, when I do the same thing to the product block, it shows undefined variable. This is the site KCityMart
So what I did to show the weight in product details page is this
in file catalog/controller/product/product.php I added this
$data['weight'] = $this->weight->format($product_info['weight'],$product_info['weight_class_id']);
and in /catalog/view/theme/theme/template/product/product.tpl I added this
<ul class="volume">
<?php if ($weight > 0) { ?>
<li><?php echo $weight; ?></li>
<?php } ?>
</ul>
and it works. But, when I tried to add this to /catalog/view/theme/theme/template/common/product/default.tpl it shows "undefined variable" error.
What could be the problem? Which part did I miss?
Any input from you all will be very much appreciated. Thanks!
What is default.tpl file ? If it's new file then you need to create controller file for it and then do the same thing which you are performed in product controller.
Assigned weight varible in catalog/controller/product/default.php (Note: If you did not created default.php controller then you need to create) then add following code
> $data['weight'] = $this->weight->format($product_info['weight'],$product_info['weight_class_id']);
and in /catalog/view/theme/*/template/product/default.tpl
add following code in above file.
<ul class="volume">
<?php if ($weight > 0) { ?>
<li><?php echo $weight; ?></li>
<?php } ?>
</ul>
Related
Okay, first I want to say that I am not a geek programmer. I am intermediate to programming. I was recently learning Php through teamtreehouse, which I have not finished yet. But instead I started making an online store from OpenCart. I watched some youtube videos and added some products, categories etc. Now I am strucked and lost my sleep, because there is no proper explanation on the web. The Problem is- On the product page I have a category of Reward Points for many products. But only thing visible on the category page is image, price, short description, Add to Cart option. I am sorry, If I am not being able to explain it properly...Below is the url of the screenshot-
http://postimg.org/image/7s413wjyd/
And also see what I want to make-
http://postimg.org/image/rggxj7hq5/
Is there a way of doing it through the admin page of opencart?? If not then please guide me how it will work by code. I am new to php too, but it will make me understand. Please help me out.
Is there a way of doing it through the admin page of opencart??
No
If not then please guide me how it will work by code
It's a very simple task but you will not be able to do it if you are not aware of web development basics
First of all, you should read about the MVC design pattern, there are pretty cool MVC examples for PHP on the internet, GIYF !
Second, you should read this great article which explains basics of OC, Here
The real work:
Make sure that each product in the array of products to be displayed in the category page has the value of reward points (or what ever datum you want), you can check that by opening ControllerProductCategory class # catalog/controller/product/category.php and dumping the variable $data['products'], if it's there then step 1 in the real work is done, if not, you will need to change the model function getProducts() in ModelCatalogProduct class # catalog/model/catalog/product.php
Now in the category template file catalog/view/theme/your theme folder/template/product/category.tpl, access the value of reward points and display it the product html div, you will find it enclosed in this loopforeach ($products as $product) {
That may seem too much for you to learn (MVC and all that stuff...), but you have to climb the ladder, Good Luck !
Try something like in default OpenCart code.
Step 1
Open file: catalog\language\english\product\category.php
Find:
$_['text_price'] = 'Price:';
Add after:
$_['text_reward'] = 'Reward Points:';
Step 2
Open file: catalog\controller\product\category.php
Find:
'price' => $price,
Add after:
'points' => $result['points'],
Step 3
In the same file: catalog\controller\product\category.php
Find:
$data['text_price'] = $this->language->get('text_price');
Add after:
$data['text_reward'] = $this->language->get('text_reward');
Step 4
Open File: catalog\view\theme\default\template\product\category.tpl
Find:
<?php if ($product['price']) { ?>
<p class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-new"><?php echo $product['special']; ?></span> <span class="price-old"><?php echo $product['price']; ?></span>
<?php } ?>
<?php if ($product['tax']) { ?>
<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
<?php } ?>
</p>
<?php } ?>
Add after:
<p><?php echo $text_reward; ?> <?php echo $product['points']; ?></p>
and then check it.
So in a nutshell, you have two options for displaying Contacts in Joomla:
Show all Joomla Contact Categories.
Show all Joomla Contacts in a single Category.
I want to use the first option, but merge a list underneath each Category showing the list of contacts within that category, and a link to their profile.
The simplest way I thought of this was to edit a template override of the file com_contact/categories/default_items.php
I found a point where I want the list to appear, and then copied and pasted the code from the Category view (that generates the list of contacts).
<ul>
<?php // Add list of contacts for each category
foreach ($this->items as $i => $item) : ?>
<li>
<a href="<?php echo JRoute::_(ContactHelperRoute::getContactRoute($item->slug, $item->catid)); ?>">
<?php echo $item->name; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
But I am assuming I can't just copy and paste, as there needs to be an extra node added to $this->items.
At the moment, no list is being generated, just the <ul> outside the foreach loop.. but also interestingly, the <li> and the <a> IS being generated.. but linking to the current page I'm on (Probably because $item->slug is still being seen as the category).
So can anyone point me in the right direction as to how to reference the contacts within a category? All I'm after is the name and the slug/URL.
UPDATE:
I saw this in the same file (default_items.php) and although I realise it's referring to child categories... would this be a place to start for the actual contacts within the categories?
<?php if (count($item->getChildren()) > 0) :?>
<div class="collapse fade" id="category-<?php echo $item->id;?>">
<?php
$this->items[$item->id] = $item->getChildren();
$this->parent = $item;
$this->maxLevelcat--;
echo $this->loadTemplate('items');
$this->parent = $item->getParent();
$this->maxLevelcat++;
?>
</div>
<?php endif; ?>
BUMP - Does anyone have any experience with this? Or being able to call individual contacts when viewing a category? How are they linked?
For Category view in file default_children.php after tag <li... add code:
<?php
// Get Category Model data
$categoryModel = JModelLegacy::getInstance('Category', 'ContactModel', array('ignore_request' => true));
$categoryModel->setState('category.id', $child->id);
$categoryModel->setState('list.ordering', 'a.name');
$categoryModel->setState('list.direction', 'asc');
$categoryModel->setState('filter.published', 1);
$contacts = $categoryModel->getItems();
?>
For Custom Fields add this after previus code:
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
foreach($contacts as $contactItem) {
$currentContFields[] = FieldsHelper::getFields('com_contact.contact', $contactItem, true);
}
I need to get only the TAGS of the product that I am viewing in the product page meaning view.phtml
If I use this command
<?php echo $this->getChildHtml('product_additional_data') ?>
I get NOT only the tags but the whole information related of the product.
How can I break the product_additional_data to tags,reviews etc ???
What are the related commands for getting ONLY the tags or gettings ONLY the reviews?
Hello add below code in view.phtml
<?php
// instantiate the tags class for products
$_tags = new Mage_Tag_Block_Product_List();
?>
<ul class="product-tags">
<?php foreach($_tags->getTags() as $tag):?>
<li><?php echo $tag->getName()?></li>
<?php endforeach;?>
</ul>
The functionality I am trying to add is due to the fact that there are links floating around there that could potentially land on a page that the product is out of stock, discontinued, etc. These types products are automatically set to a "catalog" view and "Not Visible Individually." we have overcome the fact they are no longer just getting a 404 error page, but now I would like to add the option to view other products from that same category?
I have this:
<?php $count =0; ?>
<?php $categories = $_product->getCategoryIds();?>
<?php foreach($categories as $k => $_category_id): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?>
<li> <?php echo $_category->getName() ?> </li>
<?php $count++;
if($count== 10) break; ?>
<?php endforeach; ?>
It pulls back the categories correctly, but there are categories that I need to filter out and I can't figure out how to do that? Any help would be GREATLY appreciated?
One way to do this, is to filter by id's:
<?php
foreach($categories as $k => $_category_id):
if($_category_id == $idToFilter):
continue;
else:
// show the category etc.
endif;
endforeach;
?>
I'm trying to display the price of particular product (with the ID 51) on the home page. It is not a featured product, but something else entirely so I can't use the featured module.
I know the product ID is 51, so have tried to use the following:
<?php if (!$product[$product_id[51]]['special']) { ?>
<?php echo $product[$product_id[51]]['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product_id[51]['price']; ?></span> <span class="price-new"><?php echo $product_id[51]['special']; ?></span>
<?php } ?>
but this only returns "undefined variable product_id". How do I display the price of this particular product?
MTIA.
You can get the product in full using
$product = $this->model_catalog_product->getProduct(51);
Don't forget when using currency values you should format them appropriately using
$this->currency->format()
To get an idea of what code you need to be using, take a look inside the catalog/controller/product/product.php for the special and price coding