Hi guys I am trying to integrate CSS3 Mashmenu onto my Magento store http://www.mybloggerlab.com/2012/07/mashable-drop-down-navigation-menu-for.html
I would like to setup the menu to show product categories which when hovered over show product thumbnails with short description for each product in that category.
The prodblem I am having is setting this up so it is dynamic as I would prefer to have the menu be controllable via admin.
If someone could tell me where I am going wrong I would be very grateful as the current code isn't working.
<div id="pageContainer">
<div class="mashmenu">
<div class="fnav"><?php echo $this->__('BROWSE PRODUCTS'); ?>+
<div class="allContent">
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<div class="snav"><a href="#" class="slink">
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)</a>
<?php $collection = $_category->getProductCollection()->addAttributeToSort('name', 'asc'); ?>
<?php foreach ($collection as $_product) : ?>
<div class="insideContent">
<a href="<?php echo $this->getProductUrl($_product) ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="product-image">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(75) ?>" width="75" height="75" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />
</a>
<span> <?php $sdesc = $_product->getShortDescription();
$sdesc = trim($sdesc);
$limit = 170;
if (strlen($sdesc) > $limit) {
$sdesc = substr($sdesc, 0, strrpos(substr($sdesc, 0, $limit), ' '));
} ?>
<?php echo $sdesc."..."; ?></span>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
<!-- end insideContent -->
</div>
</div>
</div>
</div>
<script>
$j(document).ready(function(){
$j('div.mashmenu img').css({"width":"100px","height":"60px"});
$j('div.mashmenu').find('.allContent').css({"top":"38px"});
$j('div.mashmenu').mouseleave(function(){
$j('div.mashmenu .allContent').show('50');
$j('div.mashmenu .insideContent').fadeOut('50');
});
$j('.flink').mouseenter(function(){
$j('div.mashmenu .allContent').show('50');
$j(this).parent('.fnav').children('.allContent').show(200);
});
$j('.slink').mouseenter(function(){
if($j(this).parent('.snav').children('.insideContent').find('a').size() != 0 )
$j(this).parents('.allContent').css({"width":"640px","height":"500px"});
else $j(this).parents('.allContent').css({"width":"auto","height":"auto"});
$j('div.mashmenu .insideContent').fadeOut('50');
$j(this).parent('.snav').children('.insideContent').fadeIn(200);
});
$j('.snav').mouseleave(function(){
$j(this).parents('.allContent').css({"width":"auto","height":"auto"});
});
$j('.snav').mouseenter(function(){
$j(this).children('.insideContent').css({"display":"block","position":"absolute","width":"auto","height":"450px"});
});
});
</script>
<?php endif; ?>
<div class="insideContent">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(75) ?>" width="75" height="75" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" /> <span> <?php $sdesc = $_product->getShortDescription();
$sdesc = trim($sdesc);
$limit = 170;
if (strlen($sdesc) > $limit) {
$sdesc = substr($sdesc, 0, strrpos(substr($sdesc, 0, $limit), ' '));
} ?>
<?php echo $sdesc."..."; ?></span>
</div>
Your $_product is undefined here, moreover you'll have only one product per category so which one to show ?
replace this by something like :
<?php $collection = Mage::getModel('catalog/product')->getCollection()->addCategoryFilter($_category)->setPageSize(4);
<div class="insideContent">
<?php foreach ($collection as $_product) { ?>
//Your product here, copy your code
<?php } /*end foreach*/ ?>
</div>
It should work better like this.
Related
I have a magento store it was working fine few days back, but now the category product page is displayed
twice like below image, i tried editing my theme list.phtml file.
I refered here
but it did not solved my problem.
My main problem is category product layout displayed twice in category page.
screenshot here
list.phtml code
<?php
$_productCollection=$this->getLoadedProductCollection();
$columnCount = themeOptions('column_count');
$enable_ajax = themeOptions('enable_ajax');
$this->setColumnCount($columnCount);
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php echo $this->getToolbarHtml() ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<ol class="products-list" id="products-list">
<?php foreach ($_productCollection as $_product): ?>
<li class="clearfix item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
<?php include('view/labels.phtml') ?>
<div class="image">
<div class="additional-buttons">
<a onclick="setLocation('<?php echo $this->getAddToWishlistUrl($_product) ?>')" class="buttons-wish" title="<?php echo $this->__('Add to Wishlist') ?>"></a>
<a onclick="setLocation('<?php echo $this->getAddToCompareUrl($_product) ?>')" class="buttons-compare" title="<?php echo $this->__('Add to Compare') ?>"></a>
</div>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image" id="productimgover<?php echo $_product->getId()?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(245,262) ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
</a>
</div>
<?php // Product description ?>
<div class="product-shop">
<div class="f-fix">
<?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
View.phtml code
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<?php $enable_ajax = themeOptions('enable_ajax'); ?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
jQuery(document).ready(function() {
if(jQuery( window ).width() > 1000)
{
if(jQuery('.product-view .more-views-wrapper').position().top < jQuery('.product-view .short-description').position().top)
{
jQuery('.product-view .more-views-wrapper').css("min-height",jQuery('.product-shop').height() - jQuery('.product-view .product-img-box .main-image').height() - 60);
}
else
{
jQuery('.product-view .short-description').css("min-height",jQuery('.product-view .product-img-box .zoom-container').height() - jQuery('.product-view .product-shop').height() + jQuery('.product-view .short-description').height());
}
}
});
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<div class="product-view">
<div class="product-essential">
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
</div>
<div id="addedoverlay" style='display:none'> </div>
<div id='added' style='display:none'></div>
<div id='productname' style='display:none'><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></div>
<div class="ll-col-2 product-img-box">
<?php echo $this->getChildHtml('media') ?>
</div>
<div class="ll-col-2 product-shop">
<div class="product-name">
<div class="additional-buttons">
<a onclick="setLocation('<?php echo $this->getAddToWishlistUrl($_product) ?>')" class="buttons-wish" title="<?php echo $this->__('Add to Wishlist') ?>"></a>
<a onclick="setLocation('<?php echo $this->getAddToCompareUrl($_product) ?>')" class="buttons-compare" title="<?php echo $this->__('Add to Compare') ?>"></a>
</div>
<h1 style="color: #EA8831!important; text-transform: capitalize!important;font-family: Quicksand !important;font-weight: 600!important;font-size:27px;" ><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
</div>
<div class="product-subdata clearfix">
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('extrahint') ?>
<?php if($_product->getTypeId() != 'bundle'): ?>
<?php echo $this->getPriceHtml($_product) ?>
<?php else: ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php endif;?>
<?php if($_product->getTypeId() != 'bundle'): ?>
<div class="addtocont">
<span class="product-code"><?php echo $this->__('Product code:').' <strong>'.$_product->getSku().'</strong>'; ?></span>
<?php echo $this->getChildHtml('product_type_data') ?>
</div>
<?php endif;?>
<div class="rating-wrapper"><?php echo $this->getReviewsSummaryHtml($_product, false, true)?></div>
<?php echo $this->getTierPriceHtml() ?>
</div>
<div class="cart-buttons-wrapper">
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<div id="container2"><?php echo $this->getChildChildHtml('container2', '', true, true) ?></div>
<?php endif;?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<div id="container1"><?php echo $this->getChildChildHtml('container1', '', true, true) ?><div class="clear"></div></div>
<?php endif;?>
<?php echo $this->getChildHtml('product_type_data_grouped') ?>
<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<h2><?php echo $this->__('Quick Overview:') ?></h2>
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
<?php echo $this->getChildHtml('other');?>
</div>
<div class="clearer"></div>
</form>
<?php if($enable_ajax): ?>
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
var url = jQuery('#product_addtocart_form').attr('action');
url = url.replace("checkout/cart","ajax/index");
var msgHtml;
var productImg = jQuery('.main-thumbnail').html();
var windowOver = jQuery('#addedoverlay');
var windowBox = jQuery('#added');
var titleForBox = jQuery('#productname').text();
var data = {'isAjax':1}
jQuery('#product_addtocart_form').ajaxForm({
url: url,
data: data,
dataType: 'json',
beforeSubmit: function(){
if(productAddToCartForm.validator.validate()){
windowOver.show();
windowBox.show().css({
backgroundImage: "url('<?php echo $this->getSkinUrl('images/loading.gif')?>')"
});
}else{
return false;
}
},
error: function(data){
windowBox.css({
backgroundImage: 'none'
}).html('<?php echo $this->__('Error') ?>');
windowOver.one('click',function(){
hidewindow(windowBox,windowOver);
});
jQuery('#hidewindow').click(function(){
hidewindow(windowBox,windowOver);
});
},
success : function(data,statusText,xhr ){
if(data.status == 'SUCCESS'){
if(jQuery('.block-cart')){
jQuery('.block-cart').replaceWith(data.sidebar);
}
if(jQuery('.block-cart-header')){
jQuery('.block-cart-header').replaceWith(data.topcart);
}
msgHtml = '<div class="added-content"><div style="float:left;">' + productImg + '</div><em>' + titleForBox + '</em> <?php echo $this->__('was successfully added to your shopping cart.') ?><div style="clear:both;"></div><a id="hidewindow" href="javascript:void(0);"><?php echo $this->__('Continue shopping') ?></a> <?php echo $this->__('View cart & checkout') ?></div>';
}else{
msgHtml = '<div class="added-content"><p class="error-msg" style="margin-bottom:15px;">' + data.message + '</p><a id="hidewindow" href="javascript:void(0);"><?php echo $this->__('Continue shopping') ?></a> <?php echo $this->__('View cart & checkout') ?></div>';
}
windowBox.css({
backgroundImage: 'none'
}).html(msgHtml);
windowOver.one('click',function(){
hidewindow(windowBox,windowOver);
});
jQuery('#hidewindow').click(function(){
hidewindow(windowBox,windowOver);
});
}
});
function hidewindow(windowBox,windowOver){
windowOver.fadeOut(400);
windowBox.fadeOut(400).html('');
}
//]]>
</script>
<?php else: ?>
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
</script>
<?php endif; ?>
</div>
<div class="clear"></div>
<div class="product-tabs-area clearfix">
<div class="product-collateral clearfix">
<?php echo $this->getChildHtml('info_tabs') ?>
<?php echo $this->getChildHtml('product_additional_data') ?>
</div>
<?php if(themeOptions('use_share')): ?>
<div class="social-share clearfix">
<div class="ss-facebook clearfix"><a class="image" href="http://www.facebook.com/sharer.php?u=<?php echo $_product->getProductUrl(); ?>" target="_blank"></a><a class="title" href="http://www.facebook.com/sharer.php?u=<?php echo $_product->getProductUrl(); ?>" target="_blank">Share on Facebook</a></div>
<div class="ss-twitter clearfix"><a class="image" href="https://twitter.com/share?url=<?php echo $_product->getProductUrl(); ?>" target="_blank"></a><a class="title" href="https://twitter.com/share?url=<?php echo $_product->getProductUrl(); ?>" target="_blank">Tweet this item</a></div>
<div class="ss-email clearfix"><a class="image" href="mailto:enteryour#addresshere.com?subject=<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>&body=<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?> - <?php echo $_product->getProductUrl(); ?>" target="_blank"></a><a class="title" href="mailto:enteryour#addresshere.com?subject=<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>&body=<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?> - <?php echo $_product->getProductUrl(); ?>" target="_blank">Tell your friend</a></div>
<div class="ss-pinterest clearfix"><a class="image" href="http://pinterest.com/pin/create/button/?url=<?php echo $_product->getProductUrl(); ?>&description=<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>&media=<?php echo $_product->getMediaConfig()->getMediaUrl($_product->getData('image')); ?>" target="_blank"></a><a class="title" href="http://pinterest.com/pin/create/button/?url=<?php echo $_product->getProductUrl(); ?>&description=<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>&media=<?php echo $_product->getMediaConfig()->getMediaUrl($_product->getData('image')); ?>" target="_blank">Pin this item</a></div>
</div>
<?php endif; ?>
</div>
<?php echo $this->getChildHtml('upsell_products') ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('product_promo_block')->toHtml(); ?>
<?php echo $this->getChildHtml('related_products') ?>
</div>
P.S. The code is exactly same as original code
I have a block being displayed on my homepage which shows a product, whose id we specify. The code on homepage (static block) looks like this:
{{block type="core/template" product_id="2559" template="catalog/product/one_product.phtml"}}
The one_product.phtml file contains this code:
<?php
$productId = $this->getProduct_id();
$product = Mage::getModel('catalog/product')->load($productId); //load product
?>
<div class="product">
<a href="<?php echo $product->getProductUrl() ?>" >
<img class="product-img" src="<?php echo $this->helper('catalog/image')->init($product, 'image'); ?>"alt="<?php echo $this->htmlEscape($product->getName()) ?>" />
</a>
</div>
<div class="product-detail">
<P><?php // echo $this->htmlEscape($product->getName()) ?>
<?php $prod_name = $this->htmlEscape($product->getName()); ?>
<?php
$count_str = strlen($prod_name);
if ($count_str < 40) {
echo $prod_name;
} else {
$offset = 0;
$length = 41;
$prod_name = html_entity_decode($prod_name);
echo htmlentities(mb_substr($prod_name,0,$length,'utf-8')). "...";;
}
?>
</P>
<!--?php $price = $product->getPrice() ; ?-->
<?php $_product = Mage::getModel('catalog/product')->load($product->getId());
$productBlock = $this->getLayout()->createBlock('catalog/product_price');
?>
<span>
<?php echo $productBlock->getPriceHtml($_product); ?>
<?php $tier_price = end($_product->getTierPrice());
if($tier_price !='0'){ ?>
<span>As Low As:</span>
<?php
echo " ₹ ".number_format( $tier_price['price']);
} ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart"
onclick="setLocation('<?php echo Mage::helper('checkout/cart')->getAddUrl($product); ?>')">
</span>
</div>
So basically I want to show random products out of the ones I specify separated by commas. For eg: I specify in the static block product_id="2559,2661,2857,9293" and it should show any one of those 4 products randomly.
What is the way to do that?
Also any way to make it pull products from SKU also? Since we remember all the SKUs but we have to check each product ID everytime we change the product here.
Please excuse me if the question is too basic, I'm not a developer.
You can see it in action at www.giftzila.com
Thanks!
Create a new file called random-product.phtml at app/design/frontend/default/Your_Theme/template/catalog/random-product.phtml then add the following code in that file
<?php
$chosen_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$_productCollection = $this->getLoadedProductCollection();
$number_of_products = $this->getNumProducts();
if (sizeof($_productCollection) < $number_of_products) {
$number_of_products = sizeof($_productCollection);
}
$displayed_products = array();
foreach ($_productCollection as $_product) {
$displayed_products[] = $_product;
}
$random_products = array();
if (sizeof($_productCollection) > 1) {
$random_products = array_rand($displayed_products, $number_of_products);
} else {
$random_products = array('0');
}
?>
<?php if(!$_productCollection->getSize()):?>
<div class="note-msg">
<?=$this->__('There are no products matching the selection.')?>
</div>
<?php else:?>
<div class="main-binder">
<div class="cms-box">
<div class="category-title">
<h2>Random Products</h2>
</div>
<div class="category-products">
<table id="products-grid-table" class="products-grid">
<?php
$k=0;
for ($i=0; $i < $number_of_products; $i++): ?>
<?php if ($k == 0) { ?>
<tr class="first odd">
<?php } if($k==3) { $k=0; ?>
</tr><tr class="first odd even">
<?php } ?>
<td id="td_<?php echo ($k+1); ?>" <?php if($k==3){ ?>class="last"<? } ?> >
<div class="cms-box">
<div id="cont_<?php echo ($k+1); ?>">
<div class="product-name-block">
<?php
$pname=$this->htmlEscape($displayed_products[$random_products[$i]]->getName());
?>
<h3 class="product-name">
<a href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>" title="<?php echo $pname; ?>">
<?php if(strlen($pname) > 28) {echo substr($pname,0,25)."...";}else {echo $pname;}?>
</a></h3>
</div>
<div class="image-box">
<a class="product-image" href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>"> <img src="<?php echo $this->helper('catalog/image')->init($displayed_products[$random_products[$i]], 'small_image')->resize(140);?>" alt="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>" title="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>"/> </a>
</div>
<div class="cms-price-box" style=" text-align:center;">
<span class="regular-price" id="product-price-37">
<span class="price" ><?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol().$displayed_products[$random_products[$i]]->getPrice(); ?></span>
</span>
</div>
<div class="button-row" style="text-align:center;">
<button onclick="setLocation('<?php echo $displayed_products[$random_products[$i]]->getProductUrl();?>')" class="button" type="button"><span><span><span>Details</span></span></span></button>
<button onclick="setLocation('<?php echo $this->getUrl('')."/checkout/cart/add?product=".$displayed_products[$random_products[$i]]->getId()."&qty=1" ?>')" class="button"><span><?php echo $this->__('Add to Cart') ?></span></button>
</div>
</div>
</div></td>
<?php $k++; ?>
<?php endfor;?>
</tr>
</table>
</div>
</div>
</div>
<?php endif;?>
Now call block in your cms home page by adding following code:-
{{block type="catalog/product_list" category_id="3" num_products="8" template="catalog/random-product.phtml"}}
I'm working with Magento EE v1.14 and i'm looking for a solution for when a user is viewing a product page to then drop swatches of related product colors if they are out of stock.
Screenshot: Highlighted out of stock related product color
Screenshot of HTML
PHP + HTML code:
<?php
$_base_product = $this->getProduct();
$base_product = Mage::getModel('catalog/product')->load($_base_product->getId());
$base_product_id = $base_product->getId();
$base_name = $base_product->getName();
$base_url = Mage::getBaseUrl();
$product_colors = Mage::getModel('catalog/product')->getCollection();
$product_colors->addAttributeToFilter('status',1); // 1 or 2
$product_colors->addAttributeToFilter('visibility',4); // 1.2.3.4
$product_colors->addAttributeToFilter('name', array('eq' => $base_name));
$product_colors->addAttributeToFilter('sku', array('neq' => $base_product->getSku()));
$product_colors_ids = $product_colors->getAllIds(); // get all products from the category
sort($product_colors_ids);
?>
<?php if(count($product_colors_ids) > 0) : ?>
<div id="product-color-options-wrapper">
<div id="product-color-options-container">
<label><?php echo $this->__('Color') ?> / <span style="font-weight: normal;"><?php echo $base_product->getAttributeText('color'); ?></span></label>
<div id="color-options-wrapper">
<?php $_swatch_img = $base_product->getMediaGalleryImages(false)->getItemByColumnValue('label', 'swatch') ?>
<?php if($_swatch_img) : ?>
<div class="current-product-wash-wrapper wash-wrapper">
<div class="current-product-wash-container wash-container">
<img src="<?php echo $this->helper('catalog/image')->init($base_product, 'small_image', $_swatch_img->getFile())->resize(33,30) ?>" alt="" title="<?php echo $base_product->getAttributeText('color') ?>" />
</div>
</div>
<?php else : ?>
<!-- <span><?php echo $base_product->getColor() ?></span> -->
<?php endif ?>
<?php foreach($product_colors_ids as $prod_id) : ?>
<?php $_sister_product = Mage::getModel('catalog/product')->load($prod_id) ?>
<?php
$_sister_prod_imgs = $_sister_product->getMediaGallery('images');
foreach($_sister_prod_imgs as $_sister_prod_img):
if($_sister_prod_img['label'] == 'swatch'):
$_swatch_img = $_sister_prod_img['file'];
endif;
endforeach;
?>
<?php if($_swatch_img): ?>
<div class="sister-product-wrapper wash-wrapper">
<div class="sister-product-container wash-container">
<a href="<?php echo $base_url ?><?php echo $_sister_product->getUrlKey() ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_sister_product, 'small_image', $_swatch_img)->resize(33,30); ?>" alt="" title="<?php echo $_sister_product->getAttributeText('color') ?>">
</a>
</div>
</div>
<?php endif; ?>
<?php endforeach ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php endif ?>
Any help would be appreciated! :D
**Solution:**Added an if statement to check for stock availability using the isAvailable() function, shown in screenshot.
Link to screenshot: https://gyazo.com/abf07ba0373877836571858ee129cc22
How do I sort products on a category page by subcategory as well as limit the number of products from each subcategory:
For example if the category was Food I would want to display the following:
Drinks Coke 12oz, Orange Juice 8oz, Milk Gallon,
Pasta, Spaghetti 1lb, Pesto 12 pc, Tortellini 1 PC.
And so on, displaying each subcategory name followed 3 products (images etc.)
I currently have a custom template that displays the subcategories but can't figure out the products,
<?php
$_category = $this->getCurrentCategory();
$collection = $_category->getCollection()
->addAttributeToSelect(
array('url_key','name','all_children','is_anchor','description','image')
)
->addAttributeToFilter('is_active', 1)
->addIdFilter($_category->getChildren())
->setOrder('position', 'ASC')
->joinUrlRewrite();
$helper = Mage::helper('catalog/category');
?>
<ul>
<?php foreach ($collection as $cat): ?>
<li>
<div class="level1descript">
<a href="<?php echo $helper->getCategoryUrl($cat); ?>">
<img src="<?php echo $cat->getImageUrl(); ?>" class="catlevel1image" />
<h2><?php echo $cat->getName(); ?></h2>
</a>
<p class="level1descript">
<?php
$catdesc = '';
$catdesc = strip_tags($cat->getDescription());
if (strlen($catdesc) > 300) {
$catdesc = substr($catdesc, 0, 300) . ' ...';
}
echo $catdesc;
?>
</p>
</div>
<?php
$childLevel2Category = $cat->getCollection()
->addAttributeToSelect(
array('url_key','name','all_children','is_anchor','description','image')
)
->addAttributeToFilter('is_active', 1)
->addIdFilter($cat->getChildren())
->setOrder('position', 'ASC')
->joinUrlRewrite();
?>
<ul>
<?php foreach ($childLevel2Category as $catLevel2) { ?>
<li class="level2cats">
<a href="<?php echo $helper->getCategoryUrl($catLevel2); ?>">
<img src="<?php echo $catLevel2->getImageUrl(); ?>" class="catlevel2image" />
<h4><?php echo $catLevel2->getName(); ?></h4>
</a>
<p class="level2descript">
<?php
$catdesc = '';
$catdesc = strip_tags($catLevel2->getDescription());
if (strlen($catdesc) > 60) {
$catdesc = substr($catdesc, 0, 60) . ' ...';
}
echo $catdesc;
?>
</li>
<?php } ?>
</ul>
</li>
<?php endforeach;?>
</ul>
Below I documented an Idea, I think this is an idea.. Please excuse my rough throw together style wise. As I just used a project I was working on to throw this together. Any questions please ask. The setPageSize method will pull the first 3 products that display by default in the subcategories.
<!-- Finding Current Category and Finding it's children -->
<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren())
?>
<div class="subcategories">
<p>Select a category to view products:</p>
<ul class="clearfix">
<!-- Display Each Subcategory Image and Name -->
<?php foreach ($categories as $category): ?>
<li class="grid12-3">
<a href="<?php echo $category->getUrl() ?>" class="clearfix">
<?php if($thumbFile = $category->getThumbnail()): ?>
<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $thumbFile;?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
<?php endif;?>
<span><?php echo $category->getName() ?></span></a>
</li>
<!-- Load (3) Products from within each subcategory -->
<?php
$_helper = $this->helper('catalog/output');
$products = Mage::getModel('catalog/product')
->getCollection()
->addCategoryFilter($category)
->setPageSize(3)
->addAttributeToSelect(array('name', 'product_url', 'small_image'))
->load();
?>
<!-- Display Each product's detailed info -->
<?php foreach ($products as $product): ?>
<li>
<?php // Product Image ?>
<img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>" />
<?php // Product description ?>
<?php $_productNameStripped = $this->stripTags($product->getName(), null, true); ?>
<h2 class="product-name"><?php echo $_helper->productAttribute($product, $product->getName() , 'name'); ?></h2>
</li>
<?php endforeach ; ?>
<?php endforeach; ?>
</ul>
</div>
Here is my code:
<?php
$_rtl = Mage::getStoreConfig('custom_menu/general/rtl') + 0;
$_categories = $this->getStoreCategories();
if (is_object($_categories)) $_categories = $this->getStoreCategories()->getNodes();
?>
<div class="nav-container">
<div style="z-index:999;position:relative;top:-8px;left:979px;cursor:pointer;"><img src="<?php echo $this->getSkinUrl('images/Truck-Prince-text.png'); ?>" height="91" width="123" style="position:absolute;" onclick="location.href='<?php echo Mage::getUrl('checkout/cart'); ?>'"></div>
<div id="custommenu" class="<?php echo $_rtl ? ' rtl' : ''; ?>">
<?php if ($this->showHomeLink()) : ?>
<div class="menu">
<div class="parentMenu menu0">
<a href="<?php echo $this->getUrl('') ?>">
<span><?php echo $this->__('Home'); ?></span>
</a>
</div>
</div>
<?php endif ?>
<?php foreach ($_categories as $_category): ?>
<?php echo $this->drawCustomMenuItem($_category) ?>
<?php endforeach ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('nav-links-after')->toHtml() ?>
<div class="clearBoth"></div>
</div>
</div>
What I want to do is something like this but I don't know how to insert this in without causing errors. I basically want to change the existing url with the string replaced urls..
<?php // We must replace URLs on the fly to use landing pages and not break subcat navigation
$_category = str_replace('wild-bird-feed-supplies.html', 'landing-wild-bird-feed-supplies', $_category);
$_category = str_replace('lawn-garden-supplies.html', 'landing-lawn-garden-supplies', $_category);
$_category = str_replace('pet-food-supplies.html', 'landing-pet-food-supplies', $_category);
$_category = str_replace('animal-feed-supplies.html', 'landing-animal-feed-supplies', $_category); ?>
I finally was able to get it :) Here is what I did...
<?php
$_rtl = Mage::getStoreConfig('custom_menu/general/rtl') + 0;
$_categories = $this->getStoreCategories();
if (is_object($_categories)) $_categories = $this->getStoreCategories()->getNodes();
?>
<div class="nav-container">
<div style="z-index:999;position:relative;top:-8px;left:979px;cursor:pointer;"><img src="<?php echo $this->getSkinUrl('images/Truck-Prince-text.png'); ?>" height="91" width="123" style="position:absolute;" onclick="location.href='<?php echo Mage::getUrl('checkout/cart'); ?>'"></div>
<div id="custommenu" class="<?php echo $_rtl ? ' rtl' : ''; ?>">
<?php if ($this->showHomeLink()) : ?>
<div class="menu">
<div class="parentMenu menu0">
<a href="<?php echo $this->getUrl('') ?>">
<span><?php echo $this->__('Home'); ?></span>
</a>
</div>
</div>
<?php endif ?>
<?php foreach ($_categories as $_category): ?>
<?php $_category = $this->drawCustomMenuItem($_category) ?>
<?php // We must replace URLs on the fly to use landing pages and not break subcat navigation
$_category = str_replace('wild-bird-feed-supplies.html', 'landing-wild-bird-feed-supplies', $_category);
$_category = str_replace('lawn-garden-supplies.html', 'landing-lawn-garden-supplies', $_category);
$_category = str_replace('pet-food-supplies.html', 'landing-pet-food-supplies', $_category);
$_category = str_replace('animal-feed-supplies.html', 'landing-animal-feed-supplies', $_category); ?>
<?php echo $_category; ?>
<?php endforeach ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('nav-links-after')->toHtml() ?>
<div class="clearBoth"></div>
</div>
</div>