Setting variables in Magento blocks - magento

I have the following code in my template file:
<?php foreach($collection as $product): ?>
<?php Mage::unregister('product'); ?>
<?php Mage::register('product', $product); ?>
<?php $_product = $this->getProduct(); ?>
<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 class="product-shop">
<div class="product-name">
<h1><?php echo $_product->getName(); ?></h1>
</div>
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getTierPriceHtml() ?>
<?php echo $this->getChildHtml('extrahint') ?>
<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<span class="or"><?php echo $this->__('OR') ?></span>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
</div>
<?php echo $this->getChildHtml('extra_buttons') ?>
<?php endif; ?>
<?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');?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
<?php endif;?>
</div>
<div class="product-img-box">
<?php echo $this->getChildHtml('media') ?>
</div>
<div class="clearer"></div>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
</form>
</div>
</div>
<?php endforeach; ?>
In my layout XML I have:
<reference name="root">
<block type="catalog/product_view" name="test" template="path/to/products.phtml"/>
</reference>
I know it is called successfully as I've output static content from it. However, it appears as if
$product
isn't being recognised by the block, even though it is a valid product instance.
The code is lifted straight from default/template/catalog/product/view.phtml where it works fine. All my code does/tries to do is change the product. This is the first time I've worked with blocks and would be grateful for any help/tips/pointers as to where I've gone wrong.
Thanks in advance :-).
EDIT
It turns out my understanding of blocks/Magento was incorrect. The answer lies in reading the AlanStorm tutorials.

I had similar problems, first try replacing all double with single quotes in layout xml.
I hope you just dummy-quoted template="path/to/products.phtml" for presentation here and used real Magento path in your code.
Can't tell you more cause i'm also beginner in Magento. Just few useful links:
http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-1-introduction-to-magento
http://inchoo.net/category/ecommerce/magento/

Related

Joomla loginform gives 500 error on bad attempt

At http://falkotl76.seventysix.axc.nl/youcollect/nl/inloggen I have a joomla loginform as a menu-item and it shows well.
When I make an attempt to login without any details it gives me a 500error and I cant figure out how to solve that.
Does anybody know how I can solve this ?
Thanks in regards,
Falko
Once I had the same issue and I fixed it by giving write permission to error.php file.
Path is - your joomla folder/log/error.php
Also make sure log and tmp path is correct in configuration.php
You need to load the client side validation javascript library. Create a template override for the com_users login view file default_login.php. At the top, add the JHtml::_('behavior.formvalidation'); line to load the library. And then add the class 'form-validate' to the form element. Below is an example:
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
JHtml::_('behavior.formvalidation');
?>
<div class="login<?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<h1>
<?php echo $this->escape($this->params->get('page_heading')); ?>
</h1>
<?php endif; ?>
<?php if (($this->params->get('logindescription_show') == 1 && str_replace(' ', '', $this->params->get('login_description')) != '') || $this->params->get('login_image') != '') : ?>
<div class="login-description">
<?php endif ; ?>
<?php if($this->params->get('logindescription_show') == 1) : ?>
<?php echo $this->params->get('login_description'); ?>
<?php endif; ?>
<?php if (($this->params->get('login_image')!='')) :?>
<img src="<?php echo $this->escape($this->params->get('login_image')); ?>" class="login-image" alt="<?php echo JTEXT::_('COM_USER_LOGIN_IMAGE_ALT')?>"/>
<?php endif; ?>
<?php if (($this->params->get('logindescription_show') == 1 && str_replace(' ', '', $this->params->get('login_description')) != '') || $this->params->get('login_image') != '') : ?>
</div>
<?php endif ; ?>
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post" class="form-validate">
<fieldset>
<?php foreach ($this->form->getFieldset('credentials') as $field): ?>
<?php if (!$field->hidden): ?>
<div class="login-fields"><?php echo $field->label; ?>
<?php echo $field->input; ?></div>
<?php endif; ?>
<?php endforeach; ?>
<?php if (JPluginHelper::isEnabled('system', 'remember')) : ?>
<div class="login-fields">
<label id="remember-lbl" for="remember"><?php echo JText::_('JGLOBAL_REMEMBER_ME') ?></label>
<input id="remember" type="checkbox" name="remember" class="inputbox" value="yes" alt="<?php echo JText::_('JGLOBAL_REMEMBER_ME') ?>" />
</div>
<?php endif; ?>
<button type="submit" class="button"><?php echo JText::_('JLOGIN'); ?></button>
<input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url', $this->form->getValue('return'))); ?>" />
<?php echo JHtml::_('form.token'); ?>
</fieldset>
</form>
</div>
<div>
<ul>
<li>
<a href="<?php echo JRoute::_('index.php?option=com_users&view=reset'); ?>">
<?php echo JText::_('COM_USERS_LOGIN_RESET'); ?></a>
</li>
<li>
<a href="<?php echo JRoute::_('index.php?option=com_users&view=remind'); ?>">
<?php echo JText::_('COM_USERS_LOGIN_REMIND'); ?></a>
</li>
<?php
$usersConfig = JComponentHelper::getParams('com_users');
if ($usersConfig->get('allowUserRegistration')) : ?>
<li>
<a href="<?php echo JRoute::_('index.php?option=com_users&view=registration'); ?>">
<?php echo JText::_('COM_USERS_LOGIN_REGISTER'); ?></a>
</li>
<?php endif; ?>
</ul>
</div>
I added a couple of links of template overrides for reference. This should solve your issue.
http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core
http://docs.joomla.org/Understanding_Output_Overrides

How to display Option List in wishlist sidebar magento

How to display Option List in wishlist sidebar magento?
I use this code!
However, it is not working. Thanks in advance.
<?php if ($_options = $this->getOptionList()):?>
<div class="truncated">
<div class="truncated_full_value">
<dl class="item-options">
<?php foreach ($_options as $_option) : ?>
<dt><?php echo $this->escapeHtml($_option['label']) ?></dt>
<dd>
<?php if (is_array($_option['value'])): ?>
<?php echo nl2br(implode("\n", $_option['value'])) ?>
<?php else: ?>
<?php echo $_option['value'] ?>
<?php endif; ?>
</dd>
<?php endforeach; ?>
</dl>
</div>
<?php echo $this->__('Details') ?>
</div>
<?php endif; ?>
try this:
<?php $options = $this->getOptionList(); ?>
<?php if ($options): ?>
<div class="truncated">
<div class="truncated_full_value">
<div class="item-options">
<p><?php echo $this->__('Options Details'); ?></p>
<dl>
<?php foreach ($options as $option): ?>
<dt><?php echo $this->escapeHtml($option['label']) ?></dt>
<dd>
<?php if (is_array($option['value'])): ?>
<?php echo nl2br(implode("\n", $option['value'])) ?>
<?php else: ?>
<?php echo $option['value'] ?>
<?php endif; ?>
</dd>
<?php endforeach; ?>
</dl>
</div>
</div>
<?php echo $this->__('View Details') ?>
</div>
<?php endif ?>

magento mobileshoppe theme - Fatal error: Call to a member function getSize() on a non-object in

I am using mobileshoppe magento theme for our store, when i installed magento it was showing latest products on home page using the code below.
{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}
Then we customized the theme and it stopped to display latest products on home page even the code above is as it is in admin.
It shows the error -
Fatal error: Call to a member function getSize() on a non-object in D:\wamp\www\magento\app\design\frontend\default\mobileshoppe\template\catalog\product\list\toolbar_top.phtml on line 34
toolbar_top.phtml
<?php if($this->getCollection()->getSize()): ?>
<div class="toolbar">
<?php if( $this->isExpanded() ): ?>
<div class="sorter">
<?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; ?>
<div class="limiter">
<label><?php echo $this->__('Show') ?></label>
<select onchange="setLocation(this.value)">
<?php foreach ($this->getAvailableLimit() as $_key=>$_limit): ?>
<option value="<?php echo $this->getLimitUrl($_key) ?>"<?php if($this->isLimitCurrent($_key)): ?> selected="selected"<?php endif ?>>
<?php echo $_limit ?>
</option>
<?php endforeach; ?>
</select> <?php echo $this->__('per page') ?>
</div>
<div class="sort-by">
<label><?php echo $this->__('Sort By') ?></label>
<select onchange="setLocation(this.value)">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
<?php echo $this->__($_order) ?>
</option>
<?php endforeach; ?>
</select>
<?php if($this->getCurrentDirection() == 'desc'): ?>
<img src="<?php echo $this->getSkinUrl('images/i_desc_arrow.gif') ?>" alt="<?php echo $this->__('Set Ascending Direction') ?>" class="v-middle" />
<?php else: ?>
<img src="<?php echo $this->getSkinUrl('images/i_asc_arrow.gif') ?>" alt="<?php echo $this->__('Set Descending Direction') ?>" class="v-middle" />
<?php endif; ?>
</div>
</div>
<?php endif; ?>
can anyone please help me on this? Thanks...
Hello Guys I had the same issue on my Mobileshoppe Template. I tried to add products of a category and it didn't work for me.
In the end the solution was to use as mentioned on the official Mobileshoppe page "readme" file: http://magresponsive.devdemoz.com/readme.html
I used the code where it says: 2) Create cms page (home page) step bellow.
Hope it helps somebody.

Magento displays incorrect products in category view

When I load a productcollection in list.phtml for the first time (or when I turn of caching completely) the products that are returned are the products which reside in the category which was created last (i.e. the category with the highest id). When cache is turned on, on page-refresh the correct products are shown. After the cache is deleted, the same situation occurs (for the correct products to show I need to refresh the page once when the productlisting is shown).
One extra strange thing; If I call
$_product->getCategory()->getName()
the correct categoryname is returned, but when
$_product->getName()
is called, the wrong productname returns... Im at a complete loss here. I have read a similar post elsewhere which stated that when cache is turned on, this problem goes away, but only after the first page-refresh which is highly undesirable.
<?php $_coreHelper = $this->helper('core'); ?>
<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getName(); ?>
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); ?>
<?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 $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = 4; ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php echo var_dump($_product->getCategory()->getName()); ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid" style="padding-left:0px;">
<?php endif ?>
<li style="height:230px;" class="hreview-aggregate hproduct item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<h2 class="item fn product-name">
<?php echo substr($this->htmlEscape($_product->getName()), 0, 22).'...' ?>
</h2>
<div>
<div>
<img class="photo fn" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(100); ?>" width="100" height="100" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
</div>
<div style="clear:both"></div>
</div>
<div>
<div>
<div>
<div>
<div><span style="font-size:13px;font-weight:bold;"><?php echo $_coreHelper->currency($newprice,true,false) ?> <?php echo $this->helper('tax')->__('Ex. BTW') ?></span></div><br />
<div><?php echo $_coreHelper->currency($newtaxprice,true,false) ?> <?php echo $this->helper('tax')->__('Inc. BTW') ?></div>
</div>
</div>
<div style="clear:both;"></div>
<br />
<form action="<?=$this->getAddToCartUrl($_product);?>" method="post" id="product_addtocart_form_<?=$_product->getId();?>" <?if($_product->getOptions()){?> enctype="multipart/form-data"<?}?>>
<?if(!$_product->isGrouped()){?>
<input type="text" name="qty" id="qty" maxlength="12" value="<?echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1);?>" style="width:30px;" /> x
<?}?>
<button type="button" class="button-order" onclick="this.form.submit()"><span><span><?=$this->__('Bestellen');?></span></span></button>
<br /><br />
<span>Zet in verlanglijst</span>
</form>
</div>
</div>
<div style="clear:both"></div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
<div class="toolbar-bottom">
<?php echo $this->getToolbarHtml() ?>
</div>
</div>
Re-Index all your products in re-indexing page.
Clear your cache.
Reload your products page.

Magento pagination - Page numbers not displaying correctly when records per page is 45

I am dealing with a strange problem. In my product listing page, the pagination is not working properly.
I have a total of 187 items. In the pagination, the number of pages displayed is three. ie; 1,2,3
When I select 45 number of records per page, and selecting the 4 th page , the items are loaded correctly, but the pagination links are still displayed as 1, 2, 3 instead of 2,3,4 .
the template i am using is the frontend\mycompany\default\template\page/html/pager.phtml
and the block is MageWorx_SeoSuite_Block_Page_Html_Pager .
The pagination works without any problem for the number of records 15 and 30, the issue only appears when selecting 45 records per page.
The content of pager.phtml is,
<?php if($this->getCollection()->getSize()): ?>
<?php if($this->getUseContainer()): ?>
<div class="pager">
<?php endif ?>
<?php if($this->getShowAmounts()): ?>
<p class="amount">
<?php if($this->getLastPageNum()>1): ?>
<?php echo $this->__('Items %s to %s of %s total', $this->getFirstNum(), $this->getLastNum(), $this->getTotalNum()) ?>
<?php else: ?>
<strong><?php echo $this->__('%s Item(s)', $this->getTotalNum()) ?></strong>
<?php endif; ?>
</p>
<?php endif ?>
<?php if($this->getShowPerPage()): ?>
<div class="limiter">
<label><?php echo $this->__('Show') ?></label>
<select onchange="setLocation(this.value)">
<?php foreach ($this->getAvailableLimit() as $_key=>$_limit): ?>
<option value="<?php echo $this->getLimitUrl($_key) ?>"<?php if($this->isLimitCurrent($_key)): ?> selected="selected"<?php endif ?>>
<?php echo $_limit ?>
</option>
<?php endforeach; ?>
</select> <?php echo $this->__('per page') ?>
</div>
<?php endif ?>
<?php if($this->getLastPageNum()>1): ?>
<div class="pages">
<!-- <strong><?php echo $this->__('Page:') ?></strong>-->
<ol>
<?php if (!$this->isFirstPage()): ?>
<li>
<a class="previous<?php if(!$this->getAnchorTextForPrevious()): ?> i-previous<?php endif;?>" href="<?php echo $this->getPreviousPageUrl() ?>" title="<?php echo $this->__('Previous') ?>">
<?php if(!$this->getAnchorTextForPrevious()): ?>
<img src="<?php echo $this->getSkinUrl('images/pager_arrow_left.gif') ?>" alt="<?php echo $this->__('Previous') ?>" class="v-middle" />
<?php else: ?>
<?php echo $this->getAnchorTextForPrevious() ?>
<?php endif;?>
</a>
</li>
<?php endif;?>
<?php if ($this->canShowFirst()): ?>
<li><a class="first" href="<?php echo $this->getFirstPageUrl() ?>">1</a></li>
<?php endif;?>
<?php if ($this->canShowPreviousJump()): ?>
<li><a class="previous_jump" title="" href="<?php echo $this->getPreviousJumpUrl() ?>">...</a></li>
<?php endif;?>
<?php $i=0;foreach ($this->getFramePages() as $_page):if($i<3): ?>
<?php if ($this->isPageCurrent($_page)): ?>
<li class="current"><?php echo $_page ?></li>
<?php else: ?>
<li><?php echo $_page ?></li>
<?php endif;?>
<?php $i++;endif; endforeach;?>
<?php if ($this->canShowNextJump()): ?>
<li><a class="next_jump" title="" href="<?php echo $this->getNextJumpUrl() ?>">...</a></li>
<?php endif;?>
<?php if ($this->canShowLast()): ?>
<li><a class="last" href="<?php echo $this->getLastPageUrl() ?>"><?php echo $this->getLastPageNum() ?></a></li>
<?php endif;?>
<?php if (!$this->isLastPage()): ?>
<li>
<a class="next<?php if(!$this->getAnchorTextForNext()): ?> i-next<?php endif; ?>" href="<?php echo $this->getNextPageUrl() ?>" title="<?php echo $this->__('Next') ?>">
<?php if(!$this->getAnchorTextForNext()): ?>
<img src="<?php echo $this->getSkinUrl('images/pager_arrow_right.gif') ?>" alt="<?php echo $this->__('Next') ?>" class="v-middle" />
<?php else: ?>
<?php echo $this->getAnchorTextForNext() ?>
<?php endif;?>
</a>
</li>
<?php endif;?>
</ol>
</div>
<?php endif; ?>
<?php if($this->getUseContainer()): ?>
</div>
<?php endif ?>
I am a beginner to magento .
I fixed the problem.
In the Mage_Page_Block_Html_Pager class there is a protected variable $_displayPages and it is set as
protected $_displayPages = 5; // Page length for the navigation
So in my pager.html (frontend\mycompany\default\template\page\html\pager.phtml ) I made a small change as follows
<?php $i=0;foreach ($this->getFramePages() as $_page):if($i<5): ?>
We can simply change the page length according to our requirement. To do this, just override the Mage_Page_Block_Html_Pager class and change the protected $_displayPages variable.
We can also set the page length from adminside

Resources