php - Magento Product Custom Ordering -


i have magento based website (http://www.apoyowellness.com/index.php/).

here can see best seller section , have added custom field "featured" products tagged featured shown in best sellers.

my problem want re-arrange products per sort weight custom field have defined in product catalog.

i have attached custom field sort_order product catalog , every product has sort weight/number 1,2,3,4 etc. want show product according numbering in ascending order.

i have each loop gives me attributes of products want how can loop products inside each in ascending order of given numbers (1,2,3 etc). below each code:

             <?php foreach ($_productcollection $_product): //print_r($_product); ?>           <?php if($_product->featured == 1): ?>                <div class="reco-sgl">                <div class="product-image-wrapper borderlnright">                <div class="single-products">                 <div class="productinfo text-center">                  <a href="<?php echo $_product->getproducturl() ?>">                   <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(); ?>"  alt="<?php echo $this->striptags($this->getimagelabel($_product, 'small_image'), null, true) ?>" />                  </a>                     <p><?php echo $_helper->productattribute($_product, $_product->getname(), 'name') ?></p>                  <?php echo $this->getfeaturedproducthtml() ?>                   <h4><?php echo $this->getpricehtml($_product, true) ?></h4>                  <a href="<?php echo $_product->getproducturl() ?>" class="btn btn-default add-to-cart">add cart</a> </div>                </div>               </div>               </div>               <?php endif; ?>          <?php endforeach ?> 

please .

you have create 2 product attributes 1 yes/no type.

  1. "featured_product" featured products
  2. "sort_order" custom sorting number 1,2,3,4 etc

    $limitnumber = 10;  $products = mage::getresourcemodel('catalog/product_collection')->addattributetoselect('*')->addattributetofilter('featured_product', array('eq' => '1'))->addattributetosort('sort_order', 'asc');  mage::getsingleton('catalog/product_status')->addvisiblefiltertocollection($products); // version magento cm 1.9.0.1 //mage::getsingleton('catalog/product_visibility')->addvisibleinsearchfiltertocollection($products); $products->setpagesize($limitnumber)->setcurpage(1)->load(); foreach ($products->getitems() $product){     echo $product->getname();     // code } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -