A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.
7

public function __construct( .. \Magento\Framework\ObjectManagerInterface $objectManager, .. ) { $this->_objectManager = $objectManager; } and then $this->_objectManager->create('Magento\Sales\Model\Resource\Order\Invoice\Collection') ->addAttributeToFilter('order_id', array('eq'=>$order->getId())) OR public function __construct( \...


6

Tipo,as you want using getFirstItem(),it only given 1 item,you need to remove this function and add getAllIds() function on this collection. Full code: $pageIds = Mage::getModel('cms/page')->getCollection() ->addFieldToFilter('identifier', 'your name in the pages') //->getFirstItem() ->getAllIds();) getAllIds()...


6

There are issue in Issue 1: <model> should be <models> .It magento logic .please check at config.xml So <model> <exportdb> <class>Attin_Exportdb_Model</class> </exportdb> </model> Should be <models> <exportdb> <...


5

Thanks for the help, I had to loop over the collection like below: $date = Mage::getModel('namespace_modulename/tablename'); $collection = $date->getCollection(); foreach($collection as $date_to){ print_r($date_to->getData()); print_r($date_to->getDateTo()); }


4

As per the your configuration , your model class name is wrong. It should be Attin_Exportdb_Model_Attrdb instead of Attin_Export_Model_Attrdb More Details Your configuration is looks like this <models> <exportdb> <class>Attin_Exportdb_Model</class> </exportdb> </models> So when you ...


4

There are small differences in parsing the config between the 2 but those should not affect performance. Both of the methods just go through a big array to retrieve data. getConfig actually does some simple calculations and then calls getNode. The only big difference I see is that $this->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE) calls this: $...


4

I was able to get this working by implementing a ConfigProvider via implementing ConfigProviderInterface. <?php namespace My\Plugin\Model; class MyPluginConfigProvider implements ConfigProviderInterface { protected $scopeConfig; public function __construct( ScopeConfigInterface $scopeConfig ) { $this->scopeConfig = $...


3

You can also instantiate an object inline (without declaring it in a constructor) with the code: /** @var \Magento\Framework\ObjectManagerInterface $om */ $om = \Magento\Framework\App\ObjectManager::getInstance(); /** @var \Magento\Sales\Model\Resource\Order\Invoice\Collection $invoices */ $invoices = $om->get('Magento\Sales\Model\Resource\Order\Invoice\...


3

Try this one: $categories = Mage::getModel('catalog/category')->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('level', 2) ->addAttributeToSelect('is_active', 1) ->setLoadProductCount(true); foreach ($categories as $category) { echo $category->getProductCount(); }


3

When you call $this->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE) It will call public function getConfig($path) { if (isset($this->_configCache[$path])) { return $this->_configCache[$path]; } $config = Mage::getConfig(); $fullPath = 'stores/' . $this->getCode() . '/' . $path; ...


3

There are a couple of different ways this can happen. I got stuck at the same place while working on the book. If you take a look at the Alan Storm tutorials on Magento Development there is a part in the models section where he directs you to get this very same error. After creating the controller page and setting up $blogpost = Mage::getModel('weblog/...


2

It should be Mage::getModel('Disc‌​_Prova/roba'); Explanation: the first part (Disc_Prova) is the alias you defined in config.xml: <models> <Disc_Prova> <---- HERE <class>Disc_Prova_Model</class> </Disc_Prova> </models> the second part (roba) is what follows after the prefix ...


2

There is no need to use the load() method in the loop. Magento provides a getChildrenCategories() method in Mage_Catalog_Model_Category class which in turn calls Mage_Catalog_Model_Resource_Category::getChildrenCategories(). So your file2 becomes something like: $CatCustomFilter = array(); foreach ($category->getChildrenCategories() as $subcategory) { ...


2

In the phtml file where you get the Value from db write below code: .phtml file code: <script> window.myData = "<?php echo $datafromdb ?>"; </script> in Knockout js you can access this data like: define( [ //your model ], function (url) { 'use strict'; return { mydata: window.myData, ...


1

You can remove empty categories from category collection foreach($allCats as $key => $category) { if ($category->getProductCount() === 0) { $allCats->removeItemByKey($category->getId()); } } I hope this will help


1

It looks like you might have a problem in your module's config.xml file. It should look something like this: <global> <models> <landing> <class>LP_Landing_Model</class> <resourceModel>landing_resource</resourceModel> </landing> <landing_resource> ...


1

The proper method to get single record : Mage::getModel('module_name/model)->load($id); If you use getCollection() then it will load all the record of that particular table and then it will filter the record from all collection. While load() will fetch only single record from that table.


1

your module configuration <?xml version="1.0" encoding="UTF-8"?> <!-- app/etc/modules/Disc_Prova.xml --> <config> <modules> <Disc_Prova> <active>true</active> <codePool>local</codePool> </Disc_Prova> </modules> </config> your config....


1

You are completely right. There are better ways to do this more efficiently. Models interact with the resourcemodel, that interact with the database. It is right to use the model for such goal, however Magento provides us with a couple of functions that make this a little more efficient. Refer to these functions: getChildren() returns a comma separated ...


1

What do you need the ID for? Are you writing code for a specific store? If so you can do <?php if (Mage::app()->getStore()->getCode() == 'default'){ ?> Default being the store name.


1

the problem with missing the collection file Module\Name\Model\Resource\Event\Collection.php you need to create the collection file. because when you call module/event this will get collection from this file Spacename/module/Model/Resource/Event/Collection.php


1

Pretty sure it's caused by the fact that no resource models are declared nor database table in your module config. You need to add the following in the <models> tag: <resourceModel>mdg_giftregistry_mysql4</resourceModel> Then in your <global> tag you can add: <mdg_giftregistry_mysql4> <entities> ...


1

come first parent::_construct(); <?php class Mdg_Giftregistry_Model_Entity extends Mage_Core_Model_Abstract { public function __construct() { parent::_construct(); $this->_init('mdg_giftregistry/entity'); } }


1

Try using this approach $result = Mage::getModel('customer/customer') ->getCollection() ->addAttributeToSelect('vat_‌​id') ->addAttributeToFilter('vat_id',$ss_5_last)->load()->getFirstItem(); if (is_object($result)) { /* Logic */ } Keep in mind vat_id is not unique and the code below can load ...


1

Try doing $date = Mage::getModel('namespace_modulename/tablename')->load($id); print_r($date->getData('date_to')); where $id is the primary key.


1

depends on how u use it... PHP creates references to objects. $cat1 = $cat2 = Mage::getModel('catalog/category'); $cat3 = Mage::getModel('catalog/category') $cat1->setId(1); $cat2->setId(2); // $cat1 also gets overwritten $cat3->setId(3); echo $cat1->getId(); // 2 echo $cat2->getId(); // 2 echo $cat3->getId(); // 3 So you could get ...


1

Try getAllIds($limit = null, $offset = null) That is a method for a collection object. So, once you get your collection, you would do something like this: $collection->getAllIds(); The $limit and $offset arguments are optional provide you with "paging" capabilities. E.g. $collection->getAllIds(100,2500); // gets you 100 ids, starting from the ...


Only top voted, non community-wiki answers of a minimum length are eligible