Magento: how to display products on owl-carousel - magento

I'm using magento 1.9.3 and I want to display featured products in home page in an owl carousel.
I have a method in the block of my module that returns me the collection I want to show in the carousel. I call it from my template like this:
$_productCollection=$this->getFeaturedProducts();
I found a previous question in stack overflow about this: Owl Carousel - Magento Products
and following this previous question I arrived to this in my template:
<div class="owl-carousel">
<?
$products = $this->getFeaturedProducts();
foreach ($products as $_product) { // iterate through the entire collection
echo '<div class="item"><img src='.$this->helper('catalog/image')->init($_product, 'small_image')->keepFrame(false)->resize($_imgSize).'></div>'; // print the image url inside of the required Owl markup
}
?>
</div>
But the div of owl-carousel is not displayed. If I inspect the page, the div is there, and the images inside too, but nothing is displayed. If I delete the owl-carousel class I see all the images displayed in list.
I installed the extension "Responsive Owl Slider" from magento connect, and I have another owl carousel on top of page made with the admin cms that shows image slides (not products) and it's working fine. The only one that fails is the one that I'm trying to do by code.
I see that the owl-carousel class has a display: none so obviously is not displaying anything, but if I delete the display: none it shows all the images at the same time, not a carousel.
How do I display my selected products in an owl carousel?

Please try this extension
https://www.magentocommerce.com/magento-connect/new-products-2.html
Hope it's helpful for you.

First go to the link >> https://magento.stackexchange.com/questions/83912/featured-products-on-homepage
Create all files to following answers.
Then open featured.phtml
copy and paste below code
<?php
$_helper = $this->helper('catalog/output');
$_productCollection = $this->getProductCollection();
?>
<div class="featured-products">
<ol class="featured-products-list owl-carousel" id="featured-products-list">
<?php foreach ($_productCollection as $_product): ?>
<li><img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(200) ?>" alt="<?php echo $this->escapeHtml($_product->getName()) ?>" /></li>
<?php endforeach; ?>
</ol>
</div>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".owl-carousel").owlCarousel();
});
</script>
Please don't forget create attribute and assign for products.

Related

Display a specific subcategory product using PHTML

what should be the code in phtml file to show one specific subcategory product on home page ?
I have created a file in catalog/product/topSection.phtml with following code-
<?php
$cat_id = 42;
$category = Mage::getModel('catalog/category')->load($cat_id);
$products = $category->getProductCollection();
echo 'total- '.$products->count();
foreach($products as $product){ ?>
<h3>
<img src="<?php echo $product->getImageUrl() ?>" alt="">
<p><?php echo $product->getName() ?></p>
</h3>
<?php }?>
and used
{{block type="core/template" name="top.section.home" template="catalog/product/topSection.phtml"}}
in home page content. but nothing is displaying. what is wrong in my code.
I checked your code it is working and also display product. First please check category id and sure category is enable ?

How do I add pages to menu?

I am new to Magento; now I am trying to develop a simple example site.
My question is this: how can we add pages to main menu?
create one static block with "Your page name"
Create new category with display mode "Static block only" and "include in navigation menu = YES" and select your cms block and save category. And see in front-end side this will be added in navigation item.
Here is the official Magento recommendation on how to do this: http://www.magentocommerce.com/knowledge-base/entry/adding-page-links-in-the-navigation-bar
To add a CMS page link to top navigation the hard way, you should override /mnt/www/x1886/app/design/frontend/default/default/template/catalog/navigation/top.phtml.
There are plenty tutorials out there about how to override files in Magento.
Change a change where I placed a comment:
<div class="header-nav-container">
<div class="header-nav">
<h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
<ul id="nav">
<!-- ADD ADDITIONAL LINKS HERE -->
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
</ul>
</div>
<?php echo $this->getChildHtml('topLeftLinks') ?>
</div>

Product category name on product viewing page

I'm working on a website. Upon clicking the product it shows all the details of it. But my client want me to show parent category of categroy of the product at top, above the image. Please help me about it. I'm a budding developer.
Try this may be help someone else.
<?php $_helper = $this->helper('catalog/output');?>
<?php $_category_detail=Mage::registry('current_category');?>
<?php $_category_detail->getName();?>
<?php $_category_detail->getId(); ?>
You can get the category data from your product object: $_product->getCategory()->getName();. You will have to edit the template at template/catalog/product/view.phtml. In the template file look for <div class="product-img-box"> and add:
<div class="product-img-box">
<h4><?php echo $_product->getCategory()->getName(); ?></h4>
<?php echo $this->getChildHtml('media') ?>
</div>

Custom top level category landing page in magento

Within our magento site we have the root category for the shop (this is just "default category"). Under this we have set-up some top-level categories (let's for example call these "electronics" and "furniture"), with a bunch of sub categories.
So as an example our category structure might be
Electronics
DVD players
MP3 Players
Computers
Furniture
3 Piece's
Armchairs
Tables
Sofabeds
I have managed to edit the layout/template for the "sub categories" such as "dvd players" so that we display a custom product list view.
Now what we want to do, is for the top level categories (the very first categories under the root category), is display a custom grid of all the subcategories and their associated thumbnail images, not the product list!
How do i assign a completely different template just for those top level categories?
If someone could provide an insight on how to do this and the step's we need to take (i should be ok with the code itself, its just how to implement it such as custom modules and templates)
Thanks
Sounds like you want a custom page layout that you can apply to your top level categories. A page layout is essentially a named page template that you can select in a dropdown to apply to products or categories.
To define a layout, add it in the global/page/layouts node of a module's config.xml, like so:
<global>
<page>
<layouts>
<my_custom_layout_name translate="label">
<label>My Custom Layout</label>
<template>page/my-custom-layout.phtml</template>
<layout_handle>my_custom_layout</layout_handle>
</my_custom_layout_name>
<layouts>
<page>
<global>
Then you just need to create the page/my-custom-layout.phtml template file somewhere in the app/design template fallback chain.
The layout_handle node specifies the name of a new layout handle that will be added to any page that uses this layout, allowing you to target it in layout XML files with a <my_custom_layout> node.
The .phtml file you're referencing will be the template for the entire HTML page, so it should include <html>, <head>, <body> tags and anything else you'd find in one of the default page/*.phtml templates (1column, empty, 2columns-left, etc). Between this and targeted layout XML, you can completely customize this page from scratch.
The final step is just to select this new layout under the "Custom Design" tab when editing each of your parent categories in Catalog->Manage Categories. If you don't see your layout in the dropdown, make sure your XML is configured properly (see app/code/core/Mage/Page/etc/config.xml for reference) and refresh your cache.
One way to do this would be to create a new template which which will be your category grid, then call that template as a static block on your selected categories, which you will select via the CMS. See below.
Create the category grid template
Navigate to “app/design/frontend/default/TEMPLATE/catalog/navigation”
In this path, we will create a file call category_listing.phtml
This file will have the following code:
<?php $_maincategorylisting=$this->getCurrentCategory()?>
<?php $_categories=$this->getCurrentChildCategories()?>
<h2><?php echo $this->__('Browse Products') ?> </h2>
<div class="subcat-listing">
<ul class="subcat-products">
<? foreach ($_categories as $_category):?>
<? if($_category->getIsActive()): ?>
<?php $cur_category=Mage::getModel('catalog/category')->load($_category->getId()); ?>
<?php $layer = Mage::getSingleton('catalog/layer'); ?>
<?php $layer->setCurrentCategory($cur_category); ?>
<? if($_imageUrl=$this->getCurrentCategory()->getImageUrl()):?>
<li> <a href="<?php echo $this->getCategoryUrl($_category) ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
<img src="<?php echo $_imageUrl ?>" width="auto" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
</a>
<h3><?php echo $this->htmlEscape($_category->getName()) ?></h3>
<? if($_description=$this->getCurrentCategory()->getDescription()):?>
<p class="category-description">
<?php echo $_description ?></</p>
<?php endif; ?>
<? endif; ?>
<? endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php $layer->setCurrentCategory($_maincategorylisting); ?>
Call this template in a static block
Go to the menu “CMS/Static block” and create new block.
Add this to the content section of the CMS block:
{{block type="catalog/navigation" name="catalog.categories" template="catalog/navigation/category_listing.phtml"}} . Then save the block.
Use this static block on category pages.
Go to the menu Catalog/Manage Categories
Now we need find the category that we want to show the new grid on
Select the categorie that you want, and in the tab“DISPLAY SETTINGS we set the following information:
DISPLAY MODE: STATIC BLOCK
CMS Block: Category Listing (the block that we create before)
Is Anchor: NO
Click SAVE. Remember that in the tab “Custom Design” you may need select your template. Remember also that the category much have an image assigned to it.

Show a single image based on product Id

I've created a module to show YouTube videos on a CMS page in Magento by pasting the videoId into a text field for each product, the video then shows on each custom CMS product page. The problem I have now is I need to pull a single image for the 'Play' button which is the logo for each product but I am not sure how to this.
I've tried creating another attribute called videothumbnail and selecting media image bot I can't see the field in the manage products section so I am a bit stuck.
This is the code that shows the YouTube video for each page. You will se that the image I currently have will show on all CMS page even if they are different products I need to assign an image to each page if possible.
<?php $_product = Mage::getModel('catalog/product')->load($this->getProductId()); ?>
<?php if ($_product->getId() && $_product->getVideoid()): ?>
<ul class="list">
<h3 class="product-name">Video</h3>
<li> <a class="fancybox-video" href="http://www.youtube.com/embed/<?php echo $_product->getVideoid(); ?>">
<img src="<?php echo $this->getSkinUrl('images/x5-play.png');?>" /></a> </li>
</ul>
<?php endif;?>
Assuming that you create a new media image called videothumbnail
By going to Admin -> Catalog -> Attribute -> Manage Attribute
Then create a new attribute of 'Media Image' for 'Catalog Input Type for Store Owner'
Then add it to a 'Manage Attribute Sets' in Admin -> Catalog -> Attribute
(you may need to do a reindex to catalog flat table)
<?php $_product = Mage::getModel('catalog/product')->load($this->getProductId()); ?>
<?php if ($_product->getId() && $_product->getVideoid()): ?>
<ul class="list">
<h3 class="product-name">X5 Mop Video</h3>
<li>
<a class="fancybox-video" href="http://www.youtube.com/embed/<?php echo $_product->getVideoid(); ?>">
$_helper = Mage::helper('catalog/output');
$_img = '<img id="image" src="' . Mage::helper('catalog/image')->init($_product, 'videothumbnail')->resize(410,420) . '" width="410" height="420" />';
echo $_helper->productAttribute($_product, $_img, 'image');
</li>
</ul>
<?php endif;?>
For less faff, but less control, you can pull a live thumbnail from YouTube very easily if you have the video ID:
How do I get a YouTube video thumbnail from the YouTube API?
You should consider using this as a fallback for if the product has no Magento video thumbnail specified.

Resources