2014-08-30

Sending POST/GET request with Zend Framework 1

For POST request:
$data = [
 'login' => 'admin',
 'password' => 'pass',
];
$client = new Zend_Http_Client('https://your.URL');
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterPost($data);
$json = $client->request()->getBody();
For GET request:
$client = new Zend_Http_Client('https://blahblahblah.blah');
$client->setMethod(Zend_Http_Client::GET);
$client->request();

Get config in zf 1

From controller:
$config = $this->getInvokeArg('bootstrap')->getOptions();
then $config is associative array
From other places:
$config = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions();

2014-08-22

How to add own class to library in ZF1

You have to add to your application.ini:
autoloadernamespaces.broker = "Broker_"
where Broker is your directory into library folder. As a result you can create class Broker_Object in /library/Broker/Object.php and it will be loaded by autoloader.

2014-08-14

How to add compare link to top links

First of all you have to create helper in your own module with two methods:
/**
 * Return label for comparing products list
 *
 * @return int
 */
public function getCompareLabel()
{
    $count = Mage::helper('catalog/product_compare')->getItemCollection()->getSize();
    return $this->__('Compare (%s)', $count);
}

/**
 * Return whether visible compare link
 *
 * @return bool
 */
public function getCompareLinkIsVisibleClass()
{
    $count = Mage::helper('catalog/product_compare')->getItemCollection()->getSize();

    if ($count > 0) {
        return '';
    }

    return 'class="no-display"';
}
Then add to layout xml (in block where you want to add link):

 
Where helper="slirx_ajaxpanel - your helper, module="slirx_ajaxpanel" - your module.

And in app.js (for rwd theme, for another you have to add this code to any js file that will be loaded on pages with your compare link)
$j('body').delegate('#header-account .compare', 'click', function(event) {
 var _url = $j(this).attr('href');
 popWin(_url, 'compare', 'top:0,left:0,width=820,height=600,resizable=yes,scrollbars=yes');

 event.preventDefault();
});

2014-08-07

Filter categories by store

Getting categories from specific store:
$storeId = 5;
$categoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCollection()
->addFieldToFilter('path', array('like'=> "1/$categoryId/%"))

2014-08-01

Magento: get product qty/count/quantity

$qtyStock = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty();
where $product - loaded magento product (Mage_Catalog_Model_Product);