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

Get all products from a particular category id in magento

My category id is
<?php $catid=10 ;?> 

I got all product by writing the below code

<?php 
$category = new Mage_Catalog_Model_Category();
$category->load($catid); //My cat id is 10
$prodCollection = $category->getProductCollection();
foreach ($prodCollection as $product) {
$prdIds[] = $product->getId(); ///Store all th eproduct id in $prdIds array
}?>

Now you have all the product ids in $prdIds variable. Just click here to get all details of the product from a particular product id.You can get individual product id by the following loop.

<?php 
foreach($prdIds as $_prdIds){
$product_id = $_prdIds;

$obj = Mage::getModel('catalog/product');
$_product = $obj->load($product_id); // Enter your Product Id in $product_id
// get Product's name
echo $_product->getName();
//get product's short description
echo $_product->getShortDescription();
//get Product's Long Description
echo $_product->getDescription();
//get Product's Regular Price
echo $_product->getPrice();
//get Product's Special price
echo $_product->getSpecialPrice();
//get Product's Url
echo $_product->getProductUrl();
//get Product's image Url
echo $_product->getImageUrl();
}
?>

Hit like or leave comment if post help!

Get controller, module, action and router name in Magento


/**
 * get Controller name
 */
$this->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
$this->getRequest()->getActionName();

/**
 * get Router name
 */
$this->getRequest()->getRouteName();

/**
 * get module name
 */
$this->getRequest()->getModuleName();

IN CLASS FILES
$this might not work in class (php) files. In this case, you need to use Mage::app().

Here is the code:

/**
 * get Controller name
 */
Mage::app()->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
Mage::app()->getRequest()->getActionName();

/**
 * get Router name
 */
Mage::app()->getRequest()->getRouteName();


/**
 * get module name
 */
Mage::app()->getRequest()->getModuleName();
The above functions (getControllerName, getActionName, getRouteName, getModuleName) are present in the class Mage_Core_Model_Url.

You can explore all requests with print_r.

echo "<pre>";
    print_r(Mage::app()->getRequest());
echo "</pre>";

Hit like or leave comment if post help!

How to send newsletter queue in Admin Magento


If newsletter queue is not going to sent by default magento cron, try to send newsletter manually as following way. In some magento version there is problem of newsletter queue. It is not going to sent by default magento cron to all your subscriber. So your newsletter will not sent to all of your customer which are subscribe to your site.

But don't worry if this is happens with you can send your newsletter to all your customer manually as described below. 


magento newsletter not sending

i have found the page of newsletter queue which is

'app\design\adminhtml\default\default\template\newsletter\queue\list.phtml'
in this page getChildHtml('grid') ?> this function call the list body

which come from

'app\code\core\Mage\Adminhtml\Block\Newsletter\Queue\Grid\Renderer\Action.php'

add following code in that page but don't make any change in core file, override that file
in your local directory as

'app\code\local\Mage\Adminhtml\Block\Newsletter\Queue\Grid\Renderer \Action.php'

just copy and paste that file in this directory.

Now add the following code in line number 77 before this code $this->getColumn()->setActions($actions);

$actions[] = array(
'url'=> $this->getUrl('*/newsletter_queue/sending'),
'caption'=>Mage::helper('newsletter')->__('Send'),
'popup' =>true
);

Update: By default magento send only 20 recipients at time. if you want to change this number and want to send more recipients at a time change in following file.

app/code/core/Mage/Adminhtml/controllers/Newsletter/QueueController.php in this file change following line

$countOfSubscritions = 20;
to
$countOfSubscritions = 100; //change 100 with what ever number you want to change.



Hit like or leave comment if post help!

Add "New" product filter option in Product listing Magento


For this open the file Mage_Catalog_Model_Config and we need to make changes to the function getAttributeUsedForSortByArray().


public function getAttributeUsedForSortByArray()
   {
       $options = array(
           'position'  => Mage::helper('catalog')->__('Position'),
           'created_at'  => Mage::helper('catalog')->__('New')
       );
       foreach ($this->getAttributesUsedForSortBy() as $attribute) {
           /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
           $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
       }

       return $options;
   }

This will sort the product by it's created date.

You need to override this class to make the changes. For that you need to do following.
In your Module etc/config.xml you need to add following code.


<models>
            <catalog>
                <rewrite>
                    <config>Company_Test_Model_Config</config>
                </rewrite>
            </catalog>
</models>

and in your Model/Config.php


<?php
class Company_Test_Model_Config extends Mage_Catalog_Model_Config
{
   public function getAttributeUsedForSortByArray()
    {
        $options = array(
           'position'  => Mage::helper('catalog')->__('Position'),
           'created_at'  => Mage::helper('catalog')->__('New')
       );
       foreach ($this->getAttributesUsedForSortBy() as $attribute) {
           /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
           $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
       }

       return $options;
    }
}

Hit like or leave comment if post help!

Add “in stock/Out Of Stock” column in Products Grid in Backend Magento


1) Copy over app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php 
to app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php

2) add the code below in app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php inside/under
_prepareCollection()
AFTER
->addAttributeToSelect('type_id');
and before
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory'))

CODE: 
$collection->joinTable( 'cataloginventory/stock_item', 'product_id=entity_id', 
array("stock_status" => "is_in_stock") )->addAttributeToSelect('stock_status');

3) add the below in in same file _prepareColumns()
    $this->addColumn('stock_status',
    array(
           'header'=> 'Stock Status',     //this is the title of the column
           'width' => '60px',                   // this is the width of the column
           'index' => 'stock_status',
           'type'  => 'options',
           'options' => array('1'=>'In Stock','0'=>'Out Of Stock'),
    ));

Hit like or leave comment if post help!

Override/Rewrite Magento core blocks and controllers to Local directory


First you will need to make a xml file for your new module at app/etc/modules directory
CompanyName_Adminhtml.xml


<?xml version="1.0"?>
<config>
    <modules>
        <CompanyName_Adminhtml>
            <active>true</active>
            <codePool>local</codePool>
        </CompanyName_Adminhtml>
    </modules>
</config>


Then, make folders in your app/code/local directory as follows:
app/code/local/CompanyName/Adminhtml/controllers/CustomerController.php
app/code/local/CompanyName/etc/config.xml


In etc/config.xml, your code should look like below:
<?xml version="1.0"?>
<config>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <CompanyName_Adminhtml before="Mage_Adminhtml">CompanyName_Adminhtml</CompanyName_Adminhtml>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>


In controllers/CustomerController.php, your code should look like below:
<?php
include_once("Mage/Adminhtml/controllers/CustomerController.php");
class CompanyName_Adminhtml_CustomerController extends Mage_Adminhtml_CustomerController
{
    public function saveAction()
    {
        //Your change goes here..
    }
}
?>

 

Copyright @ 2017 HKBlog.