Image source: http://www.letsdiscussonline.com/wp-content/uploads/2016/12/Zend-Framework-Lets-Discuss-Online.png
In Magento, sometimes there are cases where a lot of data processing needs to be complete and using Magento models and resources is either too slow or too intensive for your solution. When the Zend framework on which Magento is constructed upon jumps in. Normally, you can write raw php/mysql functionality for your requirements, but if you wish to keep your code clean and reusable, using Zend functionality is the way. Magento development company use the Zend framework. Solicitation like making feed generator or some other custom scripts that will be too substantial if used with initializing Magento are quite often and can be accomplished by writing a shell script (located in shell directory of Magento project root) which will be used only needed resources to complete the task. Let’s create the script backbone from Magento class Mage_Shell_Abstract that add Mage.php needed for basic initialization project classes. Set up our class and its attributes needed for this example. Create file called hello-example.php in our shell directory inside Magento project: require_once 'abstract.php'; class Hello_Custom_Script extends Mage_Shell_Abstract { public $r = null; public $c = null; public $entityTypeId = null; public $productTypeId = null; public $tables = array(); public function _construct() { /** @var Mage_Core_Model_Resource r */ /** @var Varien_Db_Adapter_Interface c */ // Init connection and tables $this->r = Mage::getSingleton('core/resource'); $this->c = $this->r->getConnection(Mage_Core_Model_Resource::DEFAULT_WRITE_RESOURCE); // Entity type for products $this->entityTypeId = Mage::getModel('eav/config') ->getEntityType(Mage_Catalog_Model_Product::ENTITY) ->getEntityTypeId(); // Product type ID $this->productTypeId = Mage_Catalog_Model_Product_Type::TYPE_SIMPLE; // Table names $this->tables['cpe'] = $this->r->getTableName('catalog_product_entity'); $this->tables['ea'] = $this->r->getTableName('eav_attribute'); $this->tables['cpev'] = $this->r->getTableName('catalog_product_entity_varchar'); $this->tables['cped'] = $this->r->getTableName('catalog_product_entity_decimal'); $this->tables['cpei'] = $this->r->getTableName('catalog_product_entity_int'); } } $script = new Hello_Custom_Script(); $script->run(); Call the function $this->c->select() initializes Varien_Db_Select.php which handles query build with the help of Zend_Db_Select. Inside app/code/core/Zend/Db/Select.php you run out of memory, also you can wrap up sql call in a while loop and call results one by one. With this result in slower execution but will not waste as much memory public function run() { $queryData = $this->c->select() ->from( array('cpe' => $this->tables['cpe']), array( 'ID' => 'cpe.entity_id', 'SKU' => 'cpe.sku' ) ) // Join Name ->joinInner( array('ea' => $this->tables['ea']), "ea.attribute_code = 'name' AND ea.entity_type_id = {$this->entityTypeId}", null ) ->joinLeft( array('cpev' => $this->tables['cpev']), 'cpev.attribute_id = ea.attribute_id AND cpev.entity_id = cpe.entity_id', array('name' => 'cpev.value') ) // Join Weight ->joinInner( array('ea1' => $this->tables['ea']), "ea1.attribute_code = 'weight' AND ea1.entity_type_id = {$this->entityTypeId}", null ) ->joinLeft( array('cped' => $this->tables['cped']), 'cped.attribute_id = ea1.attribute_id AND cped.entity_id = cpe.entity_id', array('weight' => 'cped.value') ) // Join Status ->joinInner( array('ea2' => $this->tables['ea']), "ea2.attribute_code = 'status' AND ea2.entity_type_id = {$this->entityTypeId}", null ) ->joinInner( array('cpei' => $this->tables['cpei']), 'cpei.attribute_id = ea2.attribute_id AND cpei.entity_id = cpe.entity_id', null ) ->where("cpei.value = 1 AND cpe.type_id = '{$this->productTypeId}'") ->limit(10); $values = $this->c->query($queryData); $return = array(); while($result = $values->fetch()) { // Do something with data here $return[] = $result; } return $return; } When everything is done you can call script from Magento root with php -f shell/hello-example.php. Many Magento development company’s websites follow the Zend framework. Author bio: Author -Harshal Shah Website - http://www.elsner.com/ Address-305,306 Iscon Center, Shivranjani Cross Road, Satellite, Ahmedabad, India. Phone number- +91 79 4006 2525
0 Comments
Leave a Reply. |
AuthorElsner Technology is serving the web development services for years to encourage the era of technology Archives
June 2020
|