Magento toolbar not rendering pager - magento

I'm new to Magento and I'm having a hard time trying to figure out how to display the pager inside the toolbar when it is called from the catalog/category/view.phtml file. Here's the code I'm using :
$layout = Mage::getSingleton('core/layout');
$toolbar = $layout->createBlock('catalog/product_list_toolbar');
$pager = $layout->createBlock('catalog/html_pager');
$block = $layout->createBlock('catalog/product_list');
$block->setCategoryId($_category->getId());
$block->setChild('toolbar', $toolbar);
$collection = $block->getLoadedProductCollection();
$toolbar->setCollection($collection);
echo $toolbar->renderView();
The Sort By, Show items per page and items total show approprietly, but the pager is just not rendering.. Anyone know what I'm doing wrong? Any help would be greatly appreciated.

You've got two problems I can immediately spot
There's no such block type as catalog/html_pager (did you mean page/html_pager)
The toolbar block's getPagerHtml method looks for a child block named product_list_toolbar_pager. You've not inserted, appended, or set this child.
Instantiate pager block with something like this
$pager = $layout->createBlock('page/html_pager');
and insert it into the toolbar with
$toolbar->setChild('product_list_toolbar_pager', $pager);
and you may have better results.
Also, the pager template itself (frontend/base/default/template/page/html/pager.phtml) contains code that will surpress the page if there's only one page of results . Drop in some debugging around this if clause.
<!-- File: app/design/frontend/base/default/template/page/html/pager.phtml -->
<?php if($this->getLastPageNum()>1): ?>
to make sure you're not falling afoul of small category listings.

Related

I can not retrieve all post / request variable when press add to cart button. I can only retrieve product id variable

on Mage/Checkout/Helper/Cart
i put this code
Mage::app()->getRequest()->getParam('qty')
but the result is empty
if I get it right, you want to track the parameters passed to the cart from some page.
Clicking on the "add to cart" button, 2 parameters will be passed, the Product and the Qty.
You can do it with:
$product = Mage::getModel('catalog/product')
->load(Mage::app()->getRequest()->getParam('product', 0));
doing so you will have a object product that is the one who you have passed as a param.
So, now you can have all the products infos you need just doing:
$name = $product->getName();
$price = $product->getPrice();
$qty = Mage::app()->getRequest()->getParam('qty', 1),
EDIT:
if you want to change buttons instructions you should check the template file in question:
app/design/frontend/TEMPLATE_PKG/TEMPLATE/template/catalog/product/view/addtocart.phtml
But for best practice you should never modify the magento's files, so i suggest to override the template file and make your own changes.
Here is a simple guide where you can get these infos: https://www.scommerce-mage.com/blog/override-phtml-or-layout-core-files-in-magento.html
in your specific case you would like to change the "onclick" function on the button, to point it whereever you want. And you can for sure add new custom buttons and so on.
hope to solve your dubts.

How to change Laravel crudbooster datamodal to a select2

The below code works and I can create a measurement modal that displays the kgs, grams etc but was wondering if there is a way to do it as a dropdown select2 instead as the list is quite short. the two I've tried below show just the label but no select2 box. Any ideas? regards
$columns = [];
$columns[] = ['label'=>'Quantity','name'=>'quantity','type'=>'number','required'=>true];
$columns[] = ['label'=>'Measure','name'=>'measures_id','type'=>'select2','datatable'=>'measures,measure'];
$columns[] = ['label'=>'Measure2','name'=>'measures_id','type'=>'select2','validation'=>'required|integer|min:0','width'=>'col-sm-5','datatable'=>'measures,measure'];
// $columns[] = ['label'=>'Measure','name'=>'measures_id','type'=>'datamodal','datamodal_table'=>'measures','datamodal_columns'=>'measure','datamodal_select_to'=>'measure:measure','required'=>true];
Found how to do it by changing select2 to select.Not sure what the difference is.
From:
$columns[] = ['label'=>'Measure','name'=>'measures_id','type'=>'select2','datatable'=>'measures,measure'];
to:
$columns[] = ['label'=>'Measure','name'=>'measures_id','type'=>'select','datatable'=>'measures,measure'];
That's correct. Since I cannot comment I'll suggest you the difference by adding an aswer.
The difference is:
Select : Standard HTML element, rendered by the browser and working according to its own code.
Select2: Select2 is a jQuery library that "improves" your select elements by adding HTML code to render options and adding functions. For example, you may add a search box to filter your options, or you can style the dropdown better.
Library url : select2.org

Limit Product Title Characters before cut-off in Magento

I'm having trouble with my magento store's layout. Some products with long titles would get cut off with a '...' but sometimes the title won't get cut off the title and instead throw out my layout's positioning. I have attached a photo
Photo of issue
I have tried the substr function in app/design/frontend/interface/theme/template/catalog/product/view.phtml
but it just ended up cutting the product's name in the actual page of the product, not the full view like the image above shows. I just need the '...' to happen without as many characters to prevent it going to a new line and ruining the layout.
Use this trick in PHP, use substr function :
Go to template > catalog > products > list.phtml file and update product name code with this code
<?php
// define the maximum length of the product name here
$maxLength = 10;
$productName = $_helper->productAttribute($_product, $_product->getName(), 'name');
echo substr($productName, 0, $maxLength).'...';
?>

why don’t my (Configurable Product) options/attributes show on product page?

Magento ver. 1.5.1.0
I have an attribute set “clothing”
There are two attributes in the set: “size” and “colour”
Size is required, colour is optional (i.e. not all products have any colour options).
I have created some Simple Products where the Size is set but Colour just has the empty value.
On the product page for the relevant Configurable Product no option inputs are shown! And in the product view.phtml if I echo $this->hasOptions() it prints an empty string, ie False.
If I set the Colour to a non-empty value then both select boxes are shown on the product page and echo $this->hasOptions() prints 1, ie True.
This doesn’t make sense to me, not sure what is failing?
Im struggling with something similar and have noticed similar behavior to what you have described.
Check first if the product is actually properly configurable. this is taken from another post in SO and was meant to part of a controller. Drop this on the front end ../template/catalog/product/view.phtml just to check.
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();
?>
<?php
if ($_product->isConfigurable()) {
$configurable = $_product->getTypeInstance();
$attributes = $configurable->getConfigurableAttributes($_product);
foreach ($attributes as $attribute) {
print $attribute->getLabel();
print "<br />";
}
}
?>
so as an answer i think you are becoming confused between custom options and configurable products.

Magento: how do you change the number of product columns based upon page layout?

I know that in catalog.xml this line effects all layouts:
<action method="setColumnCount"><columns>5</columns></action>
But I want to change the number of columns based upon specific page layouts, i.e.: 2columns with left bar, 3 columns, etc.
This is what someone said to do but I am not sure I was adding the update tag in the right spot because it didn't seem to work. Also if you read the comments they say once you turn caching back on it breaks it:
http://www.lotusseedsdesign.com/blog/change-grid-view-column-4-product-listing
So does anyone know how to use the addColumnCountLayoutDepend method or any other way to change the number of columns on the product grid specific to the page layout?
For sub category page, in app/design/frontend/Your Interface/layout/catalog.xml change columns value the following line :
<action method="setColumnCount"><columns>4</columns></action>
For root category page, in app/design/frontend/Your Interface/template/catalog/product/list.phtml find the following code in "Grid Mode" section and change with appropiate value :
<?php $_columnCount = $this->getColumnCount(); ?>
like
<?php $_columnCount = 4; ?>
A bit old question (almost 3 years :D) but I found an interesting solution to this on Kathir 'Sid' Vel's site
For this you will edit catalog/product/list.phtml template.
Find the row:
<?php $_columnCount = $this->getColumnCount(); ?>
and replace with the code bellow or comment the line and add after it the code.
<?php
/* Get the layout's page template */
$pageLayoutRootTemplate = $this->getLayout()->getBlock('root')->getTemplate();
/* Set the column count based on the layout template used */
switch ($pageLayoutRootTemplate) {
case 'page/1column.phtml':
$_columnCount = 4;
break;
case 'page/2columns-left.phtml':
$_columnCount = 3;
break;
case 'page/2columns-right.phtml':
$_columnCount = 3;
break;
case 'page/3columns.phtml':
$_columnCount = 2;
break;
default:
$_columnCount = 3;
break;
}
?>
There are a few ways to change the column counts. You can try each method to see what suits you.
1) Watch this tutorial: http://www.youtube.com/watch?v=wNbV34v72a0
Here's the code you need to make it work.
<reference name="product_list">
<action method="setColumnCount"><count>4</count></action>
</reference>
2) If the above fails, use this in whatever CMS page you want to change the columns. So for example: if you have a CMS page for displaying a specific category, use this. This is especially great for displaying a specific category products and setting the number of items per row at the same time. Past the following code in your CMS page:
{{block type="catalog/product_list" category_id="42" template="catalog/product/showroom.phtml" columnCount="4"}} 
You can change the columnCount number from 4 to whatever you want. You can get the category id by clicking on a category under your magento admin/category/manage category/
This is very important! Sometimes, when you do everything right in either of the two steps above, the items per row still does not change. The reason can easily be a CSS issue. So that leads to step 3:
3) Open your template's CSS and search for .products-grid
Make sure the width is set to a number high enough to be able to display the number of items per row you want, without having to push down overflowing items. In my case, I tried all I could to have a 4 items per row but failed, until I noticed in the CSS that my .col1-layout .products-grid had a width of 750px. I changed the width to 995px and voila, step 2 worked flawlessly.
This is late but I hope it helps someone out there.
Go to app\design\frontend\base\default\layout\catalog.xml
then go to Go to line 85 and fine the code. and find "catalog/product_list_toolbar" then customize the products according to your need.
Simplest way to change it is from the configuration tab
System->Configuration-> catalog tab-catalog->frontend you can change it easily from your magento backend.

Resources