$resource = Mage::getSingleton(’core/resource’); $readConnection = $resource->getConnection(’core_read’); $query = ‘SELECT COUNT(id) AS rows FROM table’; $sql = $readConnection->prepare($query); $sql->execute(); $data = $sql->fetch(); printf("Rows: %d\n", $data[’rows’]);
gteq – greater than or equal (>=) lteq – less then or equal () lt – less (
$tableDataCollection = Mage::getResourceModel(’modulename/tablename_collection’)->setPageSize(50); // Set number of pages and current page $pages = $tableDataCollection->getLastPageNumber(); $currentPage = 1; // Interate do { $tableDataCollection->setCurPage($currentPage); $tableDataCollection->load(); foreach ($tableDataCollection as $tableRow) { echo $tableRow->getId()."\n"; } $currentPage++; //Clear collection and free memory $tableDataCollection->clear(); } while ($pages => $currentPage);
Method 1 <?php require_once dirname(__DIR__) . ‘/../../../../../app/Mage.php’; $app = Mage::app(); Mage::register(’isSecureArea’, true); // your code goes here or <?php require_once dirname(__DIR__) . ‘/../../../../../app/Mage.php’; /** * Class My Shell Class */ class My_Shell_Class { /** * Constructor */ public function __construct() { Mage::app(); Mage::register(’isSecureArea’, true); } /** * Custom function */ […]
Posted on November 27, 2017, 4:48 pm, by admin, under
Magento 1.x.
1. In your Grid.php action do the following <?php … $this->addColumn(’action’, array( ‘header’ => Mage::helper(’promolink’)->__(’Action’), ‘width’ => ’50px’, ‘type’ => ‘action’, ‘getter’ => ‘getId’, ‘actions’ => array( array( ‘caption’ => Mage::helper(’promolink’)->__(’Delete’), ‘url’ => array(’base’ => ‘*/*/delete’), ‘field’ => ‘id’ ) ), ‘filter’ => false, ‘renderer’ => ‘Vendorname_Modulename_Block_Adminhtml_Template_Grid_Renderer_Youraction’, ‘sortable’ => false, ‘index’ => ‘id’, […]
Posted on November 17, 2017, 5:12 pm, by admin, under
Magento 1.x.
1. Add the following to the file: Vendorname/Modulename/controllers/Adminhtml/Modulename/IndexController.php <?php … public function saveAction() { if ( $this->getRequest()->getPost() ) { try { $postData = $this->getRequest()->getPost(); } catch (Exception $e) { Mage::getSingleton(’adminhtml/session’)->addError($e->getMessage()); Mage::getSingleton(’adminhtml/session’)->setFormData($postData); $this->_redirect(’*/*/edit’); return; } … 2. Add this parts of code to IndexController.php as well <?php … public function editAction() { […]
<?php protected function _addColumnFilterToCollection($column) { if ($column->getId() == ‘name’) { $this->getCollection()->addFieldToFilter($column->getId(), array(’like’ => $column->getFilter()->getValue() . ‘%’)); … $this->getCollection()->addFieldToFilter($column->geId(), $column->getFilter()->getCondition()); … $this->getCollection()->addFieldToFilter(’name’, array(’like’ => ‘%’ . $name . ‘%’)); else { parent::_addColumnFilterToCollection($column); } return $this; }
Posted on November 9, 2017, 4:30 pm, by admin, under
Magento 1.x.
Step 1. Create new field type. Add the file app/local/code/Vendorname/Modulename/Block/Adminhtml/Modulename/Edit/Form/Renderer/Fieldset/Productgrid.php <?php class Vendorname_Modulename_Block_Adminhtml_Modulename_Edit_Form_Renderer_Fieldset_Productgrid extends Varien_Data_Form_Element_Abstract { protected $_element; public function getElementHtml() { return Mage::helper(’core’)->getLayout()->createBlock(’modulename/adminhtml_modulename_edit_form_renderer_fieldset_product_grid’)->toHtml(); } } Step 2. Add Grid to app/local/code/Vendorname/Modulename/Block/Adminhtml/Modulename/Edit/Form/Renderer/Fieldset/Product/Grid.php <?php class Vendorname_Modulename_Block_Adminhtml_Modulename_Edit_Form_Renderer_Fieldset_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid { public function __construct() { parent::__construct(); $this->setId(’productsId’); $this->setDefaultSort(’id’); $this->setUseAjax(true); } protected […]
Posted on November 9, 2017, 3:30 pm, by admin, under
Magento 1.x.
Step 1. In your Form element add custom validate class <?php class Vendorname_Modulename_Block_Adminhtml_Modulename_Edit_Form extends Mage_Adminhtml_Block_Widget_Form { protected function _prepareForm() { … $fieldset->addField(’custom_id’, ‘text’, array( ‘label’ => Mage::helper(’modulename’)->__(’Custom ID’), ‘class’ => ‘validate-custom-id’, ‘required’ => true, ‘name’ => ‘custom_id’ )); … Step 2: Add the following to your extension’s app/code/local/Vendorname/Modulename/Block/Adminhtml/Modulename/Edit.php form block Edit file. […]
Reference means you are going to using the already defined block. By default all pages has following blocks: Header, Left, Content, Right, Footer