For some reason, only on view-mode icons on the product list, the "?" of the urls are replaced to "#21". Ex.: "#%21mode=list"
Somebody can help me?
Some code:
app/design/frontend/default/themename/template/catalog/product/list/toolbar.phtml
<?php if( $this->isEnabledViewSwitcher() ): ?>
<p class="view-mode">
<?php $_modes = $this->getModes(); ?>
<?php if($_modes && count($_modes)>1): ?>
<label><?php echo $this->__('View as') ?>:</label>
<?php foreach ($this->getModes() as $_code=>$_label): ?>
<?php if($this->isModeActive($_code)): ?>
<strong title="<?php echo $_label ?>" class="<?php echo strtolower($_code); ?>"><?php echo $_label ?></strong>
<?php else: ?>
<?php echo $_label ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</p>
<?php endif; ?>
app/code//core/Mage/Catalog/Block/Product/List/Toolbar.php
public function getModeUrl($mode)
{
return $this->getPagerUrl( array($this->getModeVarName()=>$mode, $this->getPageVarName() => null) );
}
and...
public function getPagerUrl($params=array())
{
$urlParams = array();
$urlParams['_current'] = true;
$urlParams['_escape'] = true; // I already tried set false, but didn't helps
$urlParams['_use_rewrite'] = true;
$urlParams['_query'] = $params;
return $this->getUrl('*/*/*', $urlParams); // I also tried not use the getUrl and concat the querystring, strangely the replace still happends...
}
I couldn't find the problem, but I make a dirt solution:
<?php echo str_replace('#%21', '&', $this->getModeUrl($_code)); ?>
I wish somebody find a better solution :)
Related
I'm using magento and I have a new product slider on my homepage that shows the new products but it is only one row big and I want to decide if it's 2 rows or more on my homepage but i don't know what i need to change in the .phtml file so it is 2 rows instead of one.
If you go to parts2u.nl you can see what i mean underneath Nieuwe Artikelen that is the new product slider I'm talking about.
This is the code:
<?php
/**
*
*/
?>
<?php
$_productCollection = $this->getProductCollection();
?>
<?php if ($_productCollection && ($_collectionSize = $_productCollection->getSize())): ?>
<?php
$theme = $this->helper('fortis');
$helpLabels = $this->helper('fortis/labels');
$helpTemplate = $this->helper('fortis/template');
$helpImg = $this->helper('infortis/image');
$sliderClasses = '';
$gridClasses = '';
//Default image size
$imgWidth = 168;
$imgHeight = 168;
//Image aspect ratio
if ($theme->getCfg('category/aspect_ratio'))
{
$imgHeight = 0; //Height will be computed automatically (based on width) to keep the aspect ratio
}
//Basic slider block parameters
//--------------------------------------------------------------
$isResponsive = $this->getIsResponsive(); //param: is_responsive
$breakpoints = $this->getBreakpoints(); //param: breakpoints
$showItems = $this->getShowItems(); //param: show_products
if (!$showItems)
{
$showItems = 5; //IMPORTANT: set default number of visible products
}
//Slider timeout (if set: automatic slideshow)
$timeout = $this->getTimeout(); //param: timeout
if ($timeout === NULL) //Param not set
{
$timeout = intval($theme->getCfg('product_slider/timeout'));
}
else
{
$timeout = intval($timeout);
}
//Slider initial delay
$initDelay = intval($this->getInitDelay()); //param: init_delay
//Number of items that should move on animation
$move = $this->getMove(); //param: move
if ($move === NULL) //Param not set
{
$move = intval($theme->getCfg('product_slider/move_items'));
}
else
{
$move = intval($move);
}
//Additional slider classes
//--------------------------------------------------------------
if($isResponsive)
{
$sliderClasses .= ' itemslider-responsive';
}
if ($_collectionSize == 1)
{
$sliderClasses .= ' single-item';
}
//Additional grid classes
//--------------------------------------------------------------
//Size of grid elements
$size = $this->getSize(); //param: size
if ($size)
{
$gridClasses = ' ' . $size;
}
else
{
if ($showItems >= 8)
{
$gridClasses = ' size-xs';
}
elseif ($showItems >= 6)
{
$gridClasses = ' size-s';
}
}
//Align elements to the center
if ($this->getCentered()) //param: centered
{
$gridClasses .= ' centered';
}
//Set equal height for all items
if ($this->getEqualHeight()) //param: equal_height
{
$gridClasses .= ' equal-height';
}
?>
<h3 class="section-title padding-right"><?php echo $this->getBlockName(); ?></h3>
<div class="itemslider-wrapper new-itemslider-wrapper">
<div class="nav-wrapper gen-slider-arrows1 gen-slider-arrows1-pos-top-right"></div>
<div class="itemslider itemslider-horizontal<?php if($sliderClasses) echo $sliderClasses; ?>">
<ul class="slides products-grid<?php if($gridClasses) echo $gridClasses; ?>">
<?php foreach ($_productCollection->getItems() as $_product): ?>
<li class="item">
<div class="product-image-wrapper" style="max-width:<?php echo $imgWidth; ?>px;">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true); ?>" class="product-image">
<img src="<?php echo $helpImg->getImg($_product, $imgWidth, $imgHeight, 'small_image'); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true); ?>" />
<?php if ($theme->getCfg('category/alt_image')): ?>
<?php echo $theme->getAltImgHtml($_product, $imgWidth, $imgHeight); ?>
<?php endif; ?>
<?php echo $helpLabels->getLabels($_product); //Product labels ?>
</a>
<?php //Add-to links
if ($theme->getCfg('category_grid/display_addtolinks') != 0
&& $theme->getCfg('category_grid/addtolinks_simple'))
{
if ($theme->getCfg('category_grid/display_addtolinks') == 1) //Display on hover
{
echo $helpTemplate->getCategoryAddtoLinksComplex_2(
$_product, $this->getAddToCompareUrl($_product), 'addto-links-icons addto-onimage visible-onhover');
}
else //Always display
{
echo $helpTemplate->getCategoryAddtoLinksComplex_2(
$_product, $this->getAddToCompareUrl($_product), 'addto-links-icons addto-onimage');
}
}
?>
</div> <!-- end: product-image-wrapper -->
<h3 class="product-name"><?php echo $this->escapeHtml($_product->getName()) ?></h3>
<?php echo $this->htmlEscape($_product->getSku()); ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php echo $this->getPriceHtml($_product, true, '-new') ?>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<?php if ($this->getHideButton() == false): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php endif; ?>
<?php else: ?>
<?php if ($this->getHideButton() == false): ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php endif; ?>
<?php //Add-to links
if ($theme->getCfg('category_grid/display_addtolinks') != 0 && !$theme->getCfg('category_grid/addtolinks_simple'))
{
if ($theme->getCfg('category_grid/display_addtolinks') == 1) //Display on hover
echo $helpTemplate->getCategoryAddtoLinks($_product, $this->getAddToCompareUrl($_product), 'addto-gaps-right addto-texticons display-onhover');
else //Always display
echo $helpTemplate->getCategoryAddtoLinks($_product, $this->getAddToCompareUrl($_product), 'addto-gaps-right addto-texticons');
}
?>
</div>
</li>
<?php endforeach; ?>
</ul> <!-- end: slides -->
</div> <!-- end: itemslider -->
</div> <!-- end: new-itemslider-wrapper -->
<script type="text/javascript">
//<![CDATA[
jQuery(function($) {
$('.new-itemslider-wrapper .itemslider').flexslider({
namespace: "",
animation: "slide",
easing: "easeInQuart",
<?php if ($timeout): ?>
slideshowSpeed: <?php echo $timeout; ?>,
animationLoop: true,
<?php else: ?>
slideshow: false,
animationLoop: false,
<?php endif; ?>
<?php if ($initDelay): ?>
initDelay: <?php echo $initDelay; ?>,
<?php endif; ?>
<?php if ($speed = intval($theme->getCfg('product_slider/speed'))): ?>
animationSpeed: <?php echo $speed; ?>,
<?php endif; ?>
pauseOnHover: true,
controlNav: false,
controlsContainer: ".new-itemslider-wrapper .nav-wrapper",
itemWidth: 188,
<?php if ($showItems): ?>
minItems: <?php echo $showItems; ?>,
maxItems: <?php echo $showItems; ?>,
<?php endif; ?>
move: <?php echo $move; ?>
})
<?php if ($breakpoints): ?>
.data("breakpoints", [ <?php echo $breakpoints; ?> ] )
<?php elseif ($showItems): ?>
.data("showItems", <?php echo $showItems; ?> )
<?php endif; ?>
; //IMPORTANT: don't remove semicolon!
});
//]]>
</script>
<?php endif; ?>
This seems like an incredibly convoluted implementation. I recommend that you seriously invest some time building your own slider rather than attempting to hack this to work the way you desire. Super cereal.
Trying to build sidebar category structure in Magento so that all children for an active category show when clicked. Using below as sample, when you go into main catalog only Main Cats appear. Then when clicking any Sub Cat the children for that respective category appear and so on.
For example
Main Cat 1
Sub Cat 1
Sub/Sub 1
Sub/Sub 1
Sub/Sub 1
Sub Cat 1
Sub Cat 1
Main Cat 2
Main Cat 3
Here's the current code I have, but once you get to the last category, only the Main Cats show (in other words, if you click on Sub/Sub, the menu closes and shows only the Main Cats).
<aside id="sidebar">
<div class="sidebar-nav">
<h2><?php echo $this->__('Products') ?></h2>
<ul>
<?php foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li>'.$cat->getName()."<ul>";
foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li>'.$subcat->getName()."</li>";
}
echo "</ul></li>";
} else {
echo '<li>'.$cat->getName()."</li>";
}
} ?>
</ul>
</div>
<div class="sidebar-nav">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('holiday-nav-links')->toHtml() ?>
</div>
<div class="sidebar-nav">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('about-us-nav-links')->toHtml() ?>
</div>
</aside>
Any help is much appreciated. Thank you in advance for the help!
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Please check this link http://fishpig.co.uk/magento/tutorials/display-categories-and-subcategories-in-magento/
hope this help you
Had to do this very thing a few days back . get my whole function, may include some unnecessary html parts though. Shows 2nd level categories level onwards (for 3rd level category view as well)
public function getCatTree()
{
$treeHtml = '';
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
$category = Mage::registry('current_category');
$level = $category->getLevel();
switch($level)
{
case 4 :
$level3Cat = $category->getParentCategory();
$level2Cat = $level3Cat->getParentCategory();
break;
case 3 :
$level2Cat = $category->getParentCategory();
break;
case 2 :
$level2Cat = $category;
break;
default :
$level2Cat = null;
break;
}
//get the level 2 category ID
$categoryId = $level2Cat->getId();
if (count($_categories) > 0)
{
foreach ($_categories as $_category)
{
//match with the level 2 category, then list all its children
if ($_category->getId() == $categoryId)
{
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$_catChildrens = $_category->getAllChildren();
foreach(explode(',',$_catChildrens) as $index=>$child)
{
$cat = Mage::getModel('catalog/category')->load($child);
if($cat->getLevel() == 3 && $cat->getIsActive())
{
$isParent = ($cat->hasChildren()) ? 'parent' : '';
$treeHtml .= '<li class="level1 nav'.$cat->getLevel().' '.$isParent.'">'.
'<a href="'.$cat->getUrl().'">'.
$cat->getName().
'</a>';
if($cat->hasChildren())
{
$treeHtml .= '<div class="sub-menu-wrap"><ul class="level1">';
foreach($cat->getChildrenCategories() as $indx=>$_subcategory)
{
if($_subcategory->getIsActive())
{
$cat4 = Mage::getModel('catalog/category')->load($indx);
$treeHtml .= '<li class="level2 nav'.$cat4->getLevel().'">'.
'<a href="'.$cat4->getUrl().'">'.
$cat4->getName().
'</a></li>';
}
}
$treeHtml .= '</ul></div>';
}
$treeHtml .= '</li>';
}
}
return $treeHtml;
}
}
}
}
Whenever I search a product using the search box, on the left side there is a filter by category. The code that creates this filter is this one:
<dl id="narrow-by-list">
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>
<?php if($_filter->getName() != "Category"){ ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd>
<?php echo $_filter->getHtml() ?>
</dd>
<?php } endif; ?>
<?php endforeach; ?>
</dl>
This shows only the main category in the filter, and I'd like to show its subcategories. I tried to set another category programmatically with this code:
<?php
$layer = Mage::getSingleton('catalog/layer');
$_categ = Mage::getModel('catalog/category')->load(5);
$layer->setCurrentCategory($_categ);
?>
... but nothing changed. Any thoughts?
When you try to set the other category on the layer singleton from a template, it's too late as all the treatments were already applied.
What you can do is to copy the file app/code/core/Mage/CatalogSearch/Model/Layer.php into app/code/local/Mage/CatalogSearch/Model/ and to add a modified version of the base Mage_Catalog_Model_Layer::getCurrentCategory() method, looking like this :
public function getCurrentCategory()
{
$category = $this->getData('current_category');
if (is_null($category)) {
if ($category = Mage::registry('current_category')) {
$this->setData('current_category', $category);
}
else {
$category = Mage::getModel('catalog/category')->load(5); // Put here the ID of the category you want to use as basis for category filtering
$this->setData('current_category', $category);
}
}
return $category;
}
Pls help me in my trouble. I need to get bundle products from cart of magento, and than I need to get the selected items of every bundle product. How can I do this? Thanx!
In magento 1.8.1
$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $_item) :
$_product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
if($_product->getTypeId()==='bundle') :
$options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
?>
<dl class="item-options">
<?php foreach ($options['bundle_options'] as $option):?>
<dt><?php echo $option['label'] ?></dt>
<?php foreach ($option['value'] as $sub) :?>
<dd><?php echo $sub['qty'] . " x " . $sub['title'] . " " . Mage::helper('core')->currency($sub['price']) ?></dd>
<?php endforeach;
endforeach;
?>
</dl>
<?php endif;
endforeach
$optionCollection = $product->getTypeInstance()->getOptionsCollection();
$selectionCollection =$product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
$options = $optionCollection->appendSelections($selectionCollection);
foreach( $options as $option )
{
$_selections = $option->getSelections();
foreach( $_selections as $selection )
{
$product_simple = Mage::getModel('catalog/product')->load($selection->getId());
}
}
Hope this will work for you. :)
Best of luck.
$_product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
if($_product->getTypeId()==='bundle') {
$options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
?>
<dl class="item-options">
<?php
foreach ($options['bundle_options'] as $option) {?>
<dt><?php echo $option['label'] ?></dt>
<dd><?php echo $option['value'][0]['title'] ?></dd>
<?php
}
?>
</dl>
<?php }
This work for Input Type "Dropdown" for bundle items
I have 2 classes - Students and Groups with many-to-many relationship. On a student page, I want to show all his details and list all groups he belongs to, delimited by comma.
This is my Students controller:
class Students extends Controller {
function __construct() {
parent::__construct();
}
function index() {
$this->get_all_students();
}
function get_all_students() {
$s = new Student();
$data['students'] = $s->select('id, name, email')->get();
$this->load->view('students', $data);
}
function view($id) {
$s = new Student();
$s->get_by_id($id);
$s->groups->get();
$data['student'] = $s;
$this->load->view('student_view', $data);
}
}
I can get student's details like this in student_view:
Name: <?php echo $student->name; ?>
E-mail: <?php echo $student->email; ?>
Groups:
<?php foreach ($student->groups as $group) : ?>
<?php echo anchor("/groups/$group->id", $group->name) ?>
<?php endforeach; ?>
So, how can I list groups delimited by comma? I tried adding group names to an array in the controller and then just <?php echo implode(', ', $groups); ?> in the view. But this way I cannot make a link using group IDs.
<?php echo anchor("/groups/$group->id", $group->name) ?>
should become ( see the comma at the end of the line )
<?php echo anchor("/groups/$group->id", $group->name) ?> ,
or display user groups as a list :
<?php foreach ($student->groups as $group) : ?>
<?php echo anchor("/groups/$group->id", $group->name) ?>
<?php endforeach; ?>
should become
<ul>
<?php foreach ($student->groups as $group) : ?>
<li><?php echo anchor("/groups/$group->id", $group->name) ?></li>
<?php endforeach; ?>
</ul>
<?php
$first = true;
foreach ($student->groups as $group) :
if (! $first) echo ', ';
echo anchor("/groups/$group->id", $group->name);
$first = false;
endforeach;
?>