Magento get price featured product - magento

I have a featured product selection in pHtml, which instead of creating an attribute set in Magento, all i am doing is calling on a specific category (this is then added to the front end with XML ont he home page). It seems to work just fine, which is good. However when i try to call in the price I get nothing, i know Im not doing something right, but im just not sure what? here is my code:
<?php
$categoryid = 13;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
?>
<div class="featured-products group">
<h1 class="featured-header">Featured Products</h1>
<div >
<ul class="group multiple" id="featured-set-home">
<?php foreach ($collection as $_product) { ?>
<li>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(138); ?>" width="138" height="138" alt="" />
<?php echo $this->getTierPriceHtml(); ?>
<a href="<?php echo $_product->getProductUrl(); ?>" class="button right" ><span><span>View Item</span></span></a>
</li>
<?php } ?>
</ul>
</div>
</div>
Its not overly complicated. If anyone can help that would be awesome.

<?php echo $this->getTierPriceHtml(); ?>
Will get the price block (it must be added in the XML layout of the custom page that you have created)
I would just go for if you only need to show the price:
$this->helper('core')->currency(Mage::helper('tax')->getPrice($_product, $_product->getFinalPrice()), true, false)); ?>

Related

magento 2 how to display the category product in homepage?

<p>{{block type="catalog/product_list"
column_count="4"
category_id="13"
template="catalog/product/list.phtml"}}</p>
I have used the above code in magento version 1.x to display the category products in the home page
After updating to Magento version 2.0., the above code doesn't work anymore.
How can I rectify it?
{{widget type="Magento\CatalogWidget\Block\Product\ProductsList"
products_count="4"
template="product/widget/content/grid.phtml"
conditions_encoded="a:2:[i:1;a:4:[s:4:`type`; s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`
value`;s:1:`13`;]]"}}
in the above code last line, 13 represents the category id
change the category_id as you need
Try this
{{block type="core/template" column_count="4" category_id="13" template="catalog/product/list.phtml"}}
after that go to yourtheme/catalog/product/list.phtml and then something try to print or echo at the top of this file
Hope it will work
{{widget type="Magento\CatalogWidget\Block\Product\ProductsList"
products_count="4"
template="product/widget/content/grid.phtml"
conditions_encoded="a:2:[i:1;a:4:[s:4:`type`; s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`
value`;s:1:`13`;]]"}}
try this code
<p>{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" title="CTlog" show_pager="1" products_per_page="5" products_count="10" template="product/widget/content/grid.phtml" conditions_encoded="a:1:[i:1;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]]" page_var_name="pmqabw"}}</p>
Try this
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');
$categoryHelper = $objectManager->get('\Magento\Catalog\Helper\Category');
$categoryRepository = $objectManager->get('\Magento\Catalog\Model\CategoryRepository');
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data');
$productmodel = $objectManager->create('Magento\Catalog\Block\Product\ListProduct');
?>
<div class="worldcup-deals">
<div class="deals-baaner">
<img src='<?php echo $this->getViewFileUrl('images/worldcup/2.png'); ?>' alt="deal-banner">
</div>
<div class="deals-products">
<div class="category-product-listing-world">
<?php
$bestsamrtphoneid = 6685;
$category = $categoryFactory->create()->load($bestsamrtphoneid);
$samrtphonecategoryProducts = $category->getProductCollection()
->addAttributeToSelect('*');
$samrtphonecategoryProducts->getSelect()->order('RAND()');
$samrtphonecategoryProducts->getSelect()->limit(8);
//->setPageSize(8) // only get 10 products
//->setCurPage(1);
?>
<?php foreach ($samrtphonecategoryProducts as $product) { ?>
<div class="product-listing-world-item">
<?php
$imagehelper = $objectManager->create('Magento\Catalog\Helper\Image');
$image = $imagehelper->init($product,'category_page_list')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(300, 300)->getUrl();
?>
<div class="inner-world-wrap">
<a href="<?php echo $product->getProductUrl(); ?>">
<img src="<?php echo $image; ?>">
</a>
<h3 class="product-name">
<a href="<?php echo $product->getProductUrl(); ?>">
<?php echo $product->getName() ?>
</a>
</h3>
<?php echo $productmodel->getProductPrice($product);?>
<div class="shop-new">
<a href="<?php echo $product->getProductUrl(); ?>">
<?php echo __('Shop now >'); ?>
</a>
<img src="<?php echo $this->getViewFileUrl('images/demo/demo.png'); ?>">
</div>
</div>
</div>
<?php } ?>
</div>
<a class="view" href="https://avechi.com/wakilisha-world-cup/cool-phones.html" target="_blank">view more >></a>
</div>
</div>

How do I append WordPress category ID to image URL in my code?

I am coding a page that lists all of my categories, along with an image associated with that category. So far I am using this to create my list:
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($args);
?>
<ul id="category-list-grid">
<?php
foreach($categories as $cat) {
?>
<li><?php echo "<a href='" . get_category_link($cat->cat_ID) . "'> $cat->cat_name </a>" ?></li>
<?php
}
?>
</ul>
It works like a charm and displays a list of text links to each category. I want to take it one step further though and assign an image. Each image follows this naming convention:
category-[id].jpg (minus the brackets, of course)
I know what I need to do, just not how to do it. I want to add <img src="category-[code to insert cat id].jpg" border="0">
How do I do this? I am trying to avoid using a plugin as I am trying to keep the site as streamlined as possible.
Thanks!
Is this what you are looking for?
<img src="category-<?php echo $cat->cat_ID; ?>.jpg" border="0"/>
Edit to show full requested code:
<ul id="category-list-grid">
<?php foreach($categories as $cat){ ?>
<li>
<a href="<?php echo get_category_link($cat->cat_ID); ?>">
<?php echo $cat->cat_name; ?>
</a>
<img src="category-<?php echo $cat->cat_ID; ?>.jpg" border="0"/>
</li>
<?php } ?>
</ul>

Dynamic Magento Top-Level Category Pages

I'm redesigning a client's top-level category pages and I would like to future-proof the design by making it dynamic. To further clarify, I want it so whenever the client adds, edits or removes a category below the current level, it would reflect that on the frontend without the need of editing code.
Now, I have come across some blog posts on the topic and even a Stack forum post:
http://www.templatemonster.com/help/magento-listing-sub-categories-on-a-category-page.html
how to display thumbnail from category using getThumbnailUrl() in Magento
However, these are both handling it differently. The Stack post also lead me to:
http://www.douglasradburn.co.uk/getting-category-thumbnail-images-with-magento/
Which I found out I needed to add the functionality for pulling the Thumbnail Image (way to go Magento). BUT, this is what I need! The end goal here is to use the Thumbnail Image on the backend of the Category, NOT the Image. We're using the Image elsewhere, as intended. I also would like to be able to pull in the category description from the backend to the frontend for the purpose of adding some extra information such as links, a true description, etc.
If there anyone who can help me? I went through the above examples and links and still, the Thumbnail images were not pulling to the frontend and overall, I'm just getting some weird behaviour. Any tips would be appreciated as I research this further myself.
Thank you!
Please Try below code. I have implemented the same with this
<?php $category_path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."catalog/category/"; ?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<div class="static-page-listing static-page-listing1">
<ul class="products-grid">
<?php $num = 0; ?>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()):
$num++;
$selImage = "SELECT value FROM catalog_category_entity_varchar WHERE attribute_id = '126' AND entity_id = '".$_category->getId()."'";
$catImage = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchOne($selImage);
if(!$catImage) $catImage = "no_image.jpg"; ?>
<li class="category-item <?php if($num%2==0) echo 'item-right'?>">
<a href="<?php echo $this->getCategoryUrl($_category) ?>">
<div style="float:left; width:100%;">
<img src="<?php echo $category_path.$catImage?>">
</div>
<div>
<h3><?php echo $this->htmlEscape($_category->getName()) ?></h3>
<h6 style = "color:red;">VIEW ALL</h6>
</div>
</a>
</li>
<?php endif; ?>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
NEW UPDATE:
The below code works:
<?php echo $cur_category->getDescription(); ?>
However, you need to be sure to check your Scopes! Not realizing my individual Store Scopes were not checked off to follow the "All Scopes" default, I fixed that and the above code worked for me when added to the "DESCRIPTION" area!
Thanks Stack!
PREVIOUS UPDATE:
I now have code working that I found online, it involved me adding a function to pull the category thumbnail image. It works! Here is the mark-up for the template:
<div class="category-products">
<ul class="products-grid">
<?php
$_categories=$this->getCurrentChildCategories();
if($_categories->count()):
$categorycount = 0;
foreach ($_categories as $_category):
if($_category->getIsActive()):
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
$catName = $this->getCurrentCategory()->getName();
if ($categorycount == 0){
$class = "first";
}
elseif ($categorycount == 3){
$class = "last";
}
else{
$class = "";
}
?>
<li class="item <?=$class?>">
<a href="<?php echo $cur_category->getURL() ?>" title="<?php echo $this->htmlEscape($cur_category->getName()) ?>">
<img src="<?php echo $cur_category->getThumbnailUrl() ?>" width="100" alt="<?php echo $this->htmlEscape($cur_category->getName()) ?>" />
</a>
<h2>
<a href="<?php echo $cur_category->getURL() ?>" title="<?php echo $this->htmlEscape($cur_category->getName()) ?>">
<?php echo $this->htmlEscape($cur_category->getName()) ?>
</a>
</h2>
<p>
DESCRIPTION
</p>
</li>
<?php
endif;
if($categorycount == 3){
$categorycount = 0;
echo "</ul>\n\n<ul class=\"products-grid\">";
}
else{
$categorycount++;
}
endforeach;
endif;
?>
</ul>
Now, where you see "DESCRIPTION," I would like to pull the category description data from the backend and have it output there. Basically, allowing dynamic creation/revision of top-level category pages.
How can I pull the description though? I'm not an expert in Magento, maybe I'm missing something basic but I can't get it working.
Thank you!

Magento displays subcategories description on category list.phtml

I got a category page with list of subcategories in Magento. The list has an image and name, but I also want to display those subcategories' description. I tried simply to add
<strong><?php echo $this->htmlEscape($_category->getDescription()) ?></strong>
but it's not working.
EDIT: I get subcategories in a traditional way:
<?php if (!$_categoryCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no subcategories matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php $_collectionSize = $_categoryCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_categoryCollection as $_category): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $_category->getUrl() ?>" class="product-image"><img class="photo" src="<?php echo $this->getCategoryImage($_category, 214, 184); ?>" width="214" height="184" alt="<?php echo $_category->getName() ?>" />
<strong><?php echo $this->htmlEscape($_category->getName()) ?></strong>
<strong><?php echo $_category->getDescription() ?></strong>
</a>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
</div>
I've tried to update the public function getChildrenCategories($category) in the category.php file by adding ->addAttributeToSelect(’description’), but it's not working.
I can't see what exactly it is that you're doing wrong, but perhaps I can still help. I have successfully displayed the child category descriptions in list.phtml and you may be able to adapt what's working for me to your own purposes. The following is a stripped-down version of the code which works for me:
<?php $children = explode( ",", $this->getCurrentCategory()->getChildren() ); ?>
<div class="category-products">
<ul class="products-grid">
<?php foreach( $children as $child ): ?>
<?php $_child = Mage::getModel( 'catalog/category' )->load( $child ); ?>
<li class="item"><?php echo $_child->getDescription(); ?></li>
<?php endforeach; ?>
</ul>
</div>
The big difference between what you're doing and my sample above is that the getChildren() method on the catalog model object returns an array of category Ids and I then use the category Ids to load the corresponding child category model instances. My memory may be wrong here, but I seem to remember that the items returned from a Magento collection don't contain the full data that you get when you load by id.
I'm not sure if this will affect performance significantly or not (I would assume that loading a collection is faster than loading individual models) but it works so I'm not complaining...
Hope this helps.
Cheers,
Zac
I have relatively the same idea on the website I'm working on, where I display sub-categories in a grid view. While I used to use the method of individually loading category/product information by id's, I sort of fell in love with using the "Mage::getModel('')->getCollection()" method.
This is what I've used on my sub categories, and I've been quite happy with it, as it grabs all the information at once:
<?php
if(Mage::registry( 'current_category' )->getId()) {
$_currentCategoryId = Mage::registry( 'current_category' )->getId();
} else { //Get Root Category Id if not in a category
$_currentCategoryId = Mage::app()->getStore()->getRootCategoryId();
}
$_subCategories = Mage::getModel( 'catalog/category' )->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('parent_id',array('eq' => $_currentCategoryId))
->addFieldToFilter('include_in_menu',array('eq' => '1'))
->addFieldToFilter('is_active', array('eq' => '1'))
->addAttributeToSort('position', 'asc');
?>
<?php if(count($_subCategories) > 0): ?>
<!--This is where the sub-category layout would go.-->
<?php else: ?>
<!--Do something else if there are no sub-categories.-->
<?php endif; ?>
This will grab all visible sub-categories of the current category, OR grab the base categories (from Root Category Id) of the store, if you choose to have the template show on any other page. You could go further and define specific attributes with addAttributeToSelect as well.

Show only current category’s products in Product View

I’ve been struggling with this question for a long time and it seems very easy to solve, I just can’t do it by myself.
Take a look at this page: http://adegean.dominiotemporario.com/porcelanas-brancas/artigos-de-mesa/linha-americana/saladeira-pequena-americana.html
This product is associated with 2 different categories, and I would like to show only a list of products of this current category (in this case, ID 188), not from all the cats the product is listed in. It’s just something like filtering this list by “current_cat_Id” or something.
The current code is this:
<div class="box base-mini mini-related-items">
<?php
$test = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
echo 'Current Main Category of this product this list should show:'.$test;
?>
<?php
if ($_product) {
// get collection of categories this product is associated with
$categories =$_product->getCategoryCollection()
//->setPage(1, 1) //selects only one category
->addFieldToFilter('level','4') //selects only 3rd level categories
//->addFieldToFilter('parent_id','188' ) //select only child categories of no 3
// ->setOrder("level") //combined by setPage, returns the lowest level category
->load();
// if the product is associated with any category
if ($categories->count())
foreach ($categories as $_category)
{
$cur_category = Mage::getModel('catalog/category')->load($_category->getId());
?>
<div class="head"><h4>Todos os produtos da coleção <strong><?=$cur_category->getName()?> (Id: <?=$cur_category->getId()?>)</strong></h4></div>
<div class="content">
<ol>
<? $products = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter($_category)
->addAttributeToSelect('small_image');
foreach ( $products as $productModel )
{
$_product = Mage::getModel('catalog/product')->load($productModel->getId());
$width=50; $height=50;
$_imageUrl = $this->helper('catalog/image')->init($productModel, 'small_image')->resize($width, $height);
?>
<li<?php if($_product->isComposite() || !$_product->isSaleable()): ?> class="super-products"<?php endif; ?> class="product-box">
<div class="product-images">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(50) ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" width="50" height="50" />
</div>
<div class="product-details">
<?php echo $this->htmlEscape($_product->getName()) ?>
<!-- Price -->
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
</li>
<? }
echo "</ol><div class=\"clear\"></div></div>";
}
}
?>
</div>
Could someone please help me solving that??
Thank you in advance for your help!
Cheers,
jw
Tks to http://www.magentocommerce.com/boards/viewthread/51638/ I finally came to an answer. The following code works great in he view.html page:
<div class="box base-mini mini-related-items">
<div class="head"><h4>Todos os produtos da coleção <strong><?php echo $this->getProduct()->getCategory()->getName() ?> </strong></h4></div>
<div class="content" style="float:left">
<ol>
<?php
$cat_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); // set current category id
$category = Mage::getModel('catalog/category')->load($cat_id);
$products = $category->getProductCollection()->addCategoryFilter($category)->addAttributeToSelect('*');
?>
<?php foreach ( $products as $_product ): ?>
<li<?php if($_product->isComposite() || !$_product->isSaleable()): ?> class="super-products"<?php endif; ?> class="product-box">
<div class="product-images">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(50) ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" width="50" height="50" />
</div>
<div class="product-details">
<?php echo $this->htmlEscape($_product->getName()) ?>
<!-- Price -->
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
</li>
<?php endforeach; ?>
</ol></div><div style="clear:both"><br /></div>
</div></div>

Resources