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
Related
good afternoon,
How can I recover the value in phtml from the weight of the product? this product is configurable, so it has variations, it needed to recover the weight of the variation
i use this for Default products:
$_product->getWeight()
Lets assume that the product model is loaded.
You need to load the model of the configurable in order to access its child products (variations).
Here is an example
<?php $configurable= Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simpleCollection = $configurable->getUsedProductCollection()->addAttributeToSelect('*'); // selecting all attributes?>
<?php foreach($simpleCollection as $simple): ?>
<?php echo $simple->getWeight(); ?>
<?php // or?>
<?php echo $simple->getAttributeText('weight'); ?>
<?php endforeach; ?>
Hope this helps
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.
I have displayed attribute filters in my catalog page. My client Requirement is, In some categories, attribute filter has no products that time i need to hide the empty attribute label. How can i achieve this Please help me.
"I need Product count for particular attribute that is shape,color and watts like that how can i get all products count by attribute, if i get count i will control the attribute label using that."
My code in catalog/layer/view.phtml:
<?php if($this->canShowBlock()): ?>
<?php // echo $this->getStateHtml() ?>
<?php if($this->canShowOptions()): ?>
<?php $_filters = $this->getFilters() ?>
<?php if($_filter->getItemsCount()):
<?php echo $this->__($_filter->getName()) ?>
<?php echo $_filter->getCount();?>
<?php echo $_filter->getHtml(); ?>
<?php endif;?>
<?php endif;?>
<?php endforeach; ?>
//Get product collection from "catalog/product" model
$collection = Mage::getModel('catalog/product')->getCollection();
//Fetch Most popular Featured products
$collection->addAttributeToSelect('most_popular');
$collection->addAttributeToSelect('featured_prod');
//You can check your query by:
$collection->getSelect();
Hope this may help you.... :)
I'm currently building out a site using Magento 1.7 where the total number of products displayed in a category is displayed in the sidebar (template/category/layer/view.phtml in the theme directory). The code I have to display this value at the moment is as follows:
<div class="products-total">
<?php if (Mage::registry('current_category')) { ?>
<?php $_category_detail->getName();?>
<?php $_category_detail->getId(); ?>
<?php $products_count = Mage::getModel('catalog/category')->load($_category_detail->getId())
->getProductCount();
?>
<?php echo $products_count,' products' ?>
<?php } ?>
</div>
However, as it simply pulls the current category total products value, it doesn't account for filters. How would it be possible to show the filtered products total?
I've tried several different things, but with no good results. I'm attempting to add an elseif which will allow me to echo "Enquire for Price" instead of a price if left blank on a wordpress.org site that uses Woocommerce. Instead, the price is being shown as 0 or EnquireforPrice£0. Our custom theme doesn't have a price.html or loop.html file, so I can't edit those. The price.html file in single-product (woocommerce folder) shows EnquireforPrice£(whatever the original price was) when I tried to edit it with the elseif I found on this wordpress woocommerce support thread
This is my current code that doesn't allow for enquire for price and for some reason I'm drawing a blank on how to get it to work.
<?php echo ($product->get_stock_quantity() < 1) ? '<span class="sold">Sold</span>' : null; ?><?php if ($product->get_stock_quantity() != 0) : ?><p class="price"><?php echo woocommerce_price(get_post_meta(get_the_ID(), '_price', true)); ?></p><?php endif; ?>
Basically, I need it to say Enquire for price if the price is left blank in the individual product price, but if there is a price to list the price. It should be straight forward, yet for some reason it simply isn't.
Thanks for any help that can be offered!
PS I've also tried the wordpress plugins that are supposed to do this, but they only work on the product page and leave £0 on the home and search pages.
I have downloaded woocommerce and have it working for me. Open
plugins/woocommerce/templates/single-product/price.php
Find this line
<p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p>
Replace it with the code below
<p itemprop="price" class="price">
<?php
$price = $product->get_price_html();
if(empty($price))
{
echo 'Anchor Text';
}
else
{
echo $price;
};
?>
</p>