Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

How to Display Random Product list on category/Product listing page in Magento

If you want to display or want to change your default product listing with random listing, just change following simple code.

The product listing page has already category filter applied, check the code at app/code/core/Mage/Catalog/Block/Product/List.php, you simply need to add the random filter there.

It is best practice to override your core file in your local directory instead of changing in core file. So copy file
from app/code/core/Mage/Catalog/Block/Product/List.php to app/code/local/Mage/Catalog/Block/Product/List.php

Now open this file Search _getProductCollection() function. In this function find out
$this->_productCollection = $layer->getProductCollection(); and comment this line and add following code just after this line...

$collection = $layer->getProductCollection();
$collection->getSelect()->order('rand()');
$this->_productCollection = $collection;

Now clear your cache and you are done.

How to add Magento Product Review form anywhere on product page

If you want to add magento product review form anywhere on your product page instead of review tab just add following simple code.

Step1: open: catalog.xml in your “layout” directory. Find this section:

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

Step2: Add the following after above line:

<block type="review/form" name="product.review.form" as="review_form"/>
<block type="review/product_view_list" name="product.info.product_additional_data" as="product_additional_data_review" template="review/product/view/reviews-in-tab.phtml">
<block type="review/form" name="product.review.form" as="review_form"/>
</block>

Step3: Now call following code where you want to display review form:

<?php echo $this->getChildHtml('product_additional_data_review') ?>
<?php echo $this->getChildHtml('review_form') ?>

Note: if you want to display review form in your product tab, click here

How to add Review form to Magento Product Review Tabs

If you are looking to add magento reviews form to your product page review tab, here is the step by step instructions for that.

Product Review

Step:1 open: review.xml, in your “layout” directory.

Find following section:
<block type="review/product_view_list" name="product.reviews" as="reviews" template="review/product/view/list.phtml" after="additional">

Add the following inside this block:
<block type="review/form" name="product.review.form" as="review_form"/>
<block type="review/product_view_list" name="product.info.product_additional_data" as="product_additional_data_review" template="review/product/view/reviews-in-tab.phtml">
<block type="review/form" name="product.review.form" as="review_form"/>
</block>

So your final result should be as...

<catalog_product_view>
        <reference name="product.info">
            <block type="review/product_view_list" name="product.reviews" as="reviews" template="review/product/view/list.phtml" after="additional">
                <action method="addToParentGroup"><group>detailed_info</group></action>
                <action method="setTitle" translate="value"><value>Reviews</value></action>
                <block type="review/form" name="product.review.form" as="review_form"/>
                <block type="review/product_view_list" name="product.info.product_additional_data" as="product_additional_data_review" template="review/product/view/reviews-in-tab.phtml">
                <block type="review/form" name="product.review.form" as="review_form"/>
                </block>
            </block>
        </reference>
    </catalog_product_view>

Now clear your cache and check output.

 

Copyright @ 2017 HKBlog.