public function collectionsAction() { $thing_1 = new Varien_Object(); $thing_1->setName('david'); $thing_1->setAge('27'); $thing_1->setLastName('Smith'); $thing_2 = new Varien_Object(); $thing_2->setName('Jane'); $thing_2->setAge(12); $thing_3 = new Varien_Object(); $thing_3->setName('Spot'); $thing_3->setLastName('The Dog'); $thing_3->setAge(7); //var_dump($thing_3->getData()); //var_dump($thing_3["last_name"]); /*Definiremos ahora una serie de collections*/ $collection_of_things = new Varien_Data_Collection(); $collection_of_things->addItem($thing_1)->addItem($thing_2)->addItem($thing_3); foreach ($collection_of_things as $thing) { var_dump($thing->getData()); } echo "<br><br>"; echo "obteniendo el primer y último elemento"; echo "<br><br>"; var_dump($collection_of_things->getFirstItem()); var_dump($collection_of_things->getLastItem()->getData()); echo "<br><br>"; echo "Ahora como xml"; var_dump($collection_of_things->toXml()); echo '<br><br>'; echo 'ahora obtenemos solo las columnas identificadas como name'; echo '<br><br>'; var_dump($collection_of_things->getColumnValues('name')); echo '<br><br>'; echo 'El equipo de Magento nos permite realizar filtrados, ejemplo para el nombre david'; echo '<br/><br>'; var_dump($collection_of_things->getItemsByColumnValue('name', 'Spot')); }
/** * Get the last item in the collection. As the inherited behavior of creating * a new empty item when the collection is empty cannot be achieved here, * (@see self::getNewEmptyItem) this method will throw an exception if called * on an empty collection. * @return EbayEnterprise_Catalog_Model_Pim_Product * @throws EbayEnterprise_Catalog_Model_Pim_Product_Collection_Exception If collection is empty */ public function getLastItem() { if (empty($this->_items)) { throw new EbayEnterprise_Catalog_Model_Pim_Product_Collection_Exception(sprintf('%s cannot get item from an empty collection', __METHOD__)); } return parent::getLastItem(); }