Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Adding Quantity Option to list.phtml? 
 
Little Creek
Jr. Member
 
Total Posts:  10
Joined:  2008-08-27
 

I’ve been hack at this one for a bit now.  Has anyone been able to add to place a quantity option i list.phtml?  Still trying to get recompile the nessacary code form view.phtml and addtocart.phtml.  I thought this would be as easy as

<?php echo $this->getChildHtml('addtocart'?>
but that doesn’t seem to be the case.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

I believe you need an extra step in there.

Inside of your list block in catalog.xml (in your design layout folder)

<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
//stuff
</block>
add this:

<block type="catalog/product_view" name="product.info.addtocart" as="addtocart" template="catalog/product/view/addtocart.phtml"/>

so you get something like this:

<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
                <
block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                <
block type="catalog/product_view" name="product.info.addtocart" as="addtocart" template="catalog/product/view/addtocart.phtml"/>
                    <
block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                        <!-- 
The following code shows how to set your own pager increments -->
                        <!--
                            <
action method="setDefaultListPerPage"><limit>4</limit></action>
                            <
action method="setDefaultGridPerPage"><limit>9</limit></action>
                            <
action method="addPagerLimit"><mode>list</mode><limit>2</limit></action>
                            <
action method="addPagerLimit"><mode>list</mode><limit>4</limit></action>
                            <
action method="addPagerLimit"><mode>list</mode><limit>6</limit></action>
                            <
action method="addPagerLimit"><mode>list</mode><limit>8</limit></action>
                            <
action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
                        -->
                    </
block>

Within list.phtml you should then be able to use the following as you are attempting to now:

<?php echo $this->getChildHtml('addtocart'?>

You can alternatively use the _prepareLayout() function in your catalog/product_list .php block file:

protected function _prepareLayout()
    
{
    
        $addToCartBlock 
$this->getLayout()->addBlock('catalog/product_view''product.info.addtocart')
                    ->
setTemplate('catalog/product/view/addtocart.phtml');
        
$this->setChild('addtocart'$addToCartBlock );
        
        return 
parent::_prepareLayout();
    
    
}
(and still use your getChildHtml() method as you have been...)

Note that I haven’t tested these two methods for you, but I believe these 2 methods are on the right track for what you are attempting to accomplish.

I’m not sure how that will work since this is calling the “product_view” block in to get that quantity field. It will hopefully work - you have to make sure the “Add to cart” button on your product_list page is submitting to the same URL as it would if you were in product_view.

Hope this makes sense!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Little Creek
Jr. Member
 
Total Posts:  10
Joined:  2008-08-27
 

I originally tried the first suggestion, as that’s what I was thinking would happen.  Just got a blank area where the addtocart should have been parsed.  This morning I thought I would try one last thing and refresh the caches.  It broke the cart by refreshing the cache!!???

Fatal error: Call to a member function getMetaTitle() on a non-object in /home/shophnm/public_html/app/code/core/Mage/Catalog/Block/Product/View.php on line 41

Let me fix this and will start with the second suggestion.

Thanks,
Aaron

 
Magento Community Magento Community
Magento Community
Magento Community
 
Little Creek
Jr. Member
 
Total Posts:  10
Joined:  2008-08-27
 

Ok, for the second option are you talking about putting this function in app/code/core/Mage/Catalog/Block/Product/List.php?  Got my previous error figured out so I ma back on track again.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Little Creek
Jr. Member
 
Total Posts:  10
Joined:  2008-08-27
 

The second one errors out..

Fatal error: Call to a member function getMetaTitle() on a non-object in /home/shophnm/public_html/app/code/core/Mage/Catalog/Block/Product/View.php on line 41

Which is

protected function _prepareLayout()
    
{
        $this
->getLayout()->createBlock('catalog/breadcrumbs');
        if (
$headBlock $this->getLayout()->getBlock('head')) {
            
if ($title $this->getProduct()->getMetaTitle()) {
                $headBlock
->setTitle($title.' '.Mage::getStoreConfig('catalog/seo/title_separator').' '.Mage::getStoreConfig('system/store/name'));
            
}

            
if ($keyword $this->getProduct()->getMetaKeyword()) {
                $headBlock
->setKeywords($keyword);
            
elseif( $currentCategory Mage::registry('current_category') ) {  // <------ LINE 41 HERE!!!
                
$headBlock->setKeywords($this->getProduct()->getName());
            
}

            
if ($description $this->getProduct()->getMetaDescription()) {
                $headBlock
->setDescription( ($description) );
            
else {
                $headBlock
->setDescription$this->getProduct()->getDescription() );
            
}
        }
        
return parent::_prepareLayout();
    
}

Wonder if I need to rename the function?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top