Showing posts with label Filter. Show all posts
Showing posts with label Filter. Show all posts

Tuesday 10 September 2019

How to get null attribute product value in magento 1 addAttributeToFilter Filter Query | Where condition

$collection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect(['entity_id'])
        ->addAttributeToFilter(
        array(
            array('attribute'=> 'pricegroup','null' => true),
            array('attribute'=> 'pricegroup','eq' => ''),
            array('attribute'=> 'pricegroup','eq' => 'NO FIELD')
        ),
        '',
        'left')
        ->addAttributeToFilter('status', ['eq' => 1]);
echo $collection->getSelect();
echo '<pre>';print_r($collection->getData());exit;

Saturday 8 December 2018

How to log all | full SQL | Mysql queries in Magento 2

Show ALL | Full magento 2 query with Sorting, Pagination and Filter in Magento 2

Open : /var/www/html/magento/jaydip kansagra/app/etc/di.xml


Find 

<preference for="Magento\Framework\DB\LoggerInterface" 

Replace

<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>
 <type name="Magento\Framework\DB\Logger\File">
      <arguments>
          <argument name="logAllQueries" xsi:type="boolean">true</argument>
          <argument name="debugFile" xsi:type="string">log/sql.log</argument>
      </arguments>
 </type>


Open : /var/www/html/magento/frye-magento/var/log/sql.log

Monday 26 November 2018

How to get filter data from report filter string | parameter URL in Magento 1




$filterData = Mage::helper('adminhtml')->prepareFilterString($this->getRequest()->getParam('filter', false));

print_r($filterData);exit;

Saturday 10 March 2018

How to display product associated categories & filter product grid by categories in admin panel



Step 1.

Copy file from "app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php" to "app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php"
Step 2 : Add Column for category.

protected function _prepareColumns() {
    ......
    ......
    ......
    $this->addColumn(
        'category_id',
            array(
             'header'                    => Mage::helper('jaydip_kansagra')->__('Category'),
             'width'                     => '100px',
             'index'                     => 'category_ids',
             'type'                      => 'options',
             'options'                   => $this->getCategoriesOptions(),
             'filter_condition_callback' => array($this, '_callbackCategoryFilter'),
             'renderer'                  => 'Jaydip_Kansagra_Block_Adminhtml_Renderer_Categories'
           )
    );
    ......
    ......
    ......
Step 3 : Create new functions in this grid file.

protected function getCategoriesOptions() {
   $categoriesOptions = array();
   $this->prepareCategoriesOptions($this->_getCategories()->getNodes(), $categoriesOptions);
   return $categoriesOptions;
}

protected function _getCategories() {
   $storeId = (int) $this->getRequest()->getParam('store');
   if ($storeId) {
       $store = Mage::app()->getStore($storeId);
       $parent = $store->getRootCategoryId();
   } else {
       $parent = Mage_Catalog_Model_Category::TREE_ROOT_ID;
   }
   $tree = Mage::getResourceModel('catalog/category_tree');
   /* @var $tree Mage_Catalog_Model_Resource_Category_Tree */
   $nodes = $tree->loadNode($parent)
        ->loadChildren(0)
        ->getChildren();
   $tree->addCollectionData(null, true, $parent, true, false);
   return $nodes;
}

protected function prepareCategoriesOptions($nodes, &$options) {
    /** @var $node Varien_Data_Tree_Node */
    foreach ($nodes as $node) {
        if ($node->getName()) {
            $options[$node->getId()] = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $node->getLevel() - 1) . $node->getName();
        }
        if ($node->hasChildren()) {
            $this->prepareCategoriesOptions($node->getAllChildNodes(), $options);
        }
    }
    return $options;
}

*********Or For without category tree view**********

protected function getCategoriesOptions() {
   $categoriesOptions = array();
   $this->prepareCategoriesOptions($this->_getCategories()->getNodes(), $categoriesOptions);
   return $categoriesOptions;
}
Step 4 : Create new function for filter in this file protected method _callbackCategoryFilter

protected function _callbackCategoryFilter($collection, $column)
{
    if (!$value = $column->getFilter()->getValue()) {
        return null;
    }
    $collection->joinField(
        'category_id',
        'catalog/category_product',
        'category_id',
        'product_id = entity_id',
        '{{table}}.category_id=' . $column->getFilter()->getValue(),
        'inner'
    );
Step 5 : Create renderer file in any extension

class Jaydip_Kansagra_Block_Adminhtml_Renderer_Categories extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
    public function render(Varien_Object $row) {
     
        $productCategories = array();
        $product = Mage::getModel('catalog/product')->load($row->getData('entity_id'));
        $categories = $product->getCategoryCollection()->addAttributeToSelect('name');
        foreach ($categories as $category) {
            array_push($productCategories, $category->getName());
        }
        return implode(',', $productCategories);
    } 

Thursday 5 May 2016

How to Shopify API Product / Order / Collection get sorted when passing in an created_at / updated_at filter

What would be ideal would be to be able to get results in ascending/descending order one way or another, but without having to pass in since_id, because we want to be able to pull in new data on orders on an ongoing basis as they may be updated.

Its possible to sort the Products/Orders/Collection by passing an "order" parameter. The "order" parameter should contain the field to sort by (supported fields are "created_at", "updated_at" and "processed_at"), followed by a space and then by an "asc" or "desc".

Please check following Example for solution.

https://example.myshopify.com/admin/orders.json?limit=2&fields=id,created_at&order=created_at%20asc