(Solution): MDN CrmTicket Bug when searching for a name and go back to Grid View

23. August 2016 at 18:18


In function „getCondition“ in der class

change this buggy part

        if ($customerIdsSelected && sizeof($customerIdsSelected)>0) {
            if((count($customerIdsSelected) == 1) && count($customerIdsSelected[0] > 0)) {
                return array('in' => $customerIdsSelected);
            } else {
                return null;
          return null;


        if ($customerIdsSelected && sizeof($customerIdsSelected)>0) {
            if(count($customerIdsSelected) == 1 && count($customerIdsSelected[0]) > 0) {
                return array('in' => $customerIdsSelected);
            } else {
                return null;
          return null;

BTW: The programmer from MDN-CrmTicket unfortunately disregard both Zend and Magento Coding Style Guide! 🙁


Please share this article von facebook & google plus or where you want, thank you!

Sending json data to a remote server – howto

21. April 2016 at 14:00


If you’re sending json requests there are different possible solutions on programming with php. Here some different explained:

1. Using Streams

‚method‘ => ‚POST‘,
‚content‘ => json_encode( $data ),
‚header’=> „Content-Type: application/json\r\n“ .
„Accept: application/json\r\n“

$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result);

2. Raw HTTP Post

Using Zend Framework’s HTTP client: http://framework.zend.com/manual/en/zend.http.client.advanced.html#zend.http.client.raw_post_data

$json = json_encode($data);
$client = new Zend_Http_Client($url);
$client->setRawData($json, ‚application/json‘)->request(‚POST‘);

3. Using Curl

$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
        array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //curl error SSL certificate problem, verify that the CA cert is OK
$result     = curl_exec($curl);
$response   = json_decode($result);

4. Using Ajax

var data = <?php echo json_encode($data) ?>;
var url  = '<?php echo $url ?>';
    type: "POST",
    url: url,
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data){
        var jsonObj = jQuery.parseJSON(data);
    failure: function(errorMsg) {

Please share this article von facebook & google plus or where you want, thank you!

Magento Upgrade Conflict issue / SUPEE-6788 security patch – Solution for this problem

10. November 2015 at 11:25


Magento has released a new upgrade for Magento which includes the SUPEE-6788 Patch Bundle. Note that this upgrade can break some modules which are not correctly coded.

I have tested the upgrade thru Magento Connect Manager but it failed.

I am testing in Linux Bash / Windows CLI:

chmod 755 mage
sudo -u www-data ./mage list-upgrades
sudo -u www-data ./mage upgrade-all

I have the same error in command line

upgrade-all: Failed to delete files: /home/data/www/magento_dev/./pkginfo/Mage_All_Latest.txt
Check permissions
upgrade-all: Package community/Interface_Adminhtml_Default conflicts with: community/Mage_All_Latest
upgrade-all: Package community/Interface_Frontend_Default conflicts with: community/Mage_All_Latest
upgrade-all: Package community/Interface_Install_Default conflicts with: community/Mage_All_Latest
upgrade-all: Package community/Mage_Downloader conflicts with: community/Mage_All_Latest
upgrade-all: Package community/Mage_Centinel conflicts with: community/Mage_All_Latest

On stack exchange, there are some idea how to proceed.

Solution – First Step

cd pkginfo
# rm -Rf Mage_All_Latest.txt Mage_All.txt
# cd ..
# sudo -u www-data ./mage upgrade-all
Installing package community/Mage_All_Latest
Package community/Mage_All_Latest installed successfully
Starting to download Interface_Adminhtml_Default- ...
...done: 1,014,275 bytes
Installing package community/Interface_Adminhtml_Default
Package community/Interface_Adminhtml_Default installed successfully
Starting to download Interface_Frontend_Default- ...
...done: 747,738 bytes
Installing package community/Interface_Frontend_Default

Now delete the maintenance.flag file and your shop is updated and online! 🙂

Please share this article von facebook & google plus or where you want, thank you!

Magento: Access Denied errors after installing SUPEE-6285 or since Magento – ACL Error – Solution

13. August 2015 at 15:06

If you use restricted admin accounts, some menus of third party extensions might not work anymore for them. The reason is that the default return value of Mage_Adminhtml_Controller_Action::_isAllowed() has been changed from true to Mage::getSingleton(‚admin/session‘)->isAllowed(‚admin‘). Extensions that do not override this method in their admin controllers because they don’t use the ACL, now need the „ALL“ privilege.

The only solution is to patch the extensions and add this method to all their admin controllers:

protected function _isAllowed()
  return true;

Or if they actually have an ACL resource defined in etc/adminhtml.xml:

protected function _isAllowed()
  return Mage::getSingleton('admin/session')->isAllowed('ENTER RESOURCE IDENTIFIER HERE'); //e.g. 'admin/sales/productreturn'</pre>


Please share this article von facebook & google plus or where you want, thank you!

Magento: Product options are wrong if order edit in admin and last order article is taken

15. Juli 2015 at 12:48

php code

If you edit an order and take over last article it is possible that the wrong product options are mapped.

The reason is that the wrong options are taken – not the „options“ taken – magento get the „info_buyRequest“-options from the database, but sometimes the „options“ array has the options data that you need.

You can solve this problem with overwriting the „getBuyRequest()“ function in app/code/local/Mage/Sales/Model/Order/Item.php with this php code:

 * Returns formatted buy request - object, holding request received from
 * product view page with keys and options for configured product
 * @return Varien_Object
public function getBuyRequest()
    $option = $this-&gt;getProductOptionByCode('info_buyRequest');   // this get the wrong options
    $option2 = $this-&gt;getProductOptionByCode('options');
    foreach($option2 as $option_tmp) {
        if($option_tmp['option_type'] == 'area'
            || $option_tmp['option_type'] == 'file'
            || $option_tmp['option_type'] == 'field'
            || $option_tmp['option_type'] == 'date'
            || $option_tmp['option_type'] == 'date_time'
            || $option_tmp['option_type'] == 'time'
        ) {
            $option['options'][$option_tmp['option_id']] = $option_tmp['value'];
        } elseif($option_tmp['option_type'] == 'drop_down'
            &amp;&amp; $option_tmp['label'] == 'Farbe'
            &amp;&amp; $productOptions = $this-&gt;getProduct()-&gt;getOptions()[$option_tmp['option_id']]-&gt;getValues()
        ) {
            foreach($productOptions as $productOption) {
                if($productOption-&gt;getData('title') == $option_tmp['value']) {
                    $option['options'][$option_tmp['option_id']] = $productOption-&gt;getData('option_type_id');
        } else {
            $option['options'][$option_tmp['option_id']][0] = $option_tmp['option_value'];
    unset($option2, $option_tmp, $productModel, $attr);
    if (!$option) {
        $option = array();
    $buyRequest = new Varien_Object($option);
    $buyRequest-&gt;setQty($this-&gt;getQtyOrdered() * 1);
    return $buyRequest;


Please share this article von facebook & google plus or where you want, thank you!

Magento: Save admin name to order_status change using an Observer

28. April 2015 at 15:24

php code




public function addUserNameBeforeComment($observer)
        $data = '<strong>' . Mage::getSingleton('admin/session')->getUser()->getFirstname() . ' ' . Mage::getSingleton('admin/session')->getUser()->getLastname() . ': </strong>';
        $history = Mage::app()->getRequest()->getPost('history');
        if ($history && isset($history['comment']) && $history['comment'] != '') {
            $history['comment'] = $data . $history['comment'];
            Mage::app()->getRequest()->setPost('history', $history);


Please share this article von facebook & google plus or where you want, thank you!

Magento: Cancel old orders / Alte Bestellungen stornieren

24. März 2015 at 15:18

php code

Um alte Bestellungen in Magento zu stornieren könnt ihr den folgenden php-code verwenden:

To cancel old orders in Magento, e.g. with state „pending“, „holded“ or „pending_payment“ you can use the following php-code:

    public function autocancelPendingOrders()
        $orderCollection = Mage::getResourceModel('sales/order_collection');
                    array('eq' => 'pending'),
                    array('eq' => 'holded'),
                    array('eq' => 'pending_payment')
        $orderCollection->addFieldToFilter('created_at', array(
                'lt' =>  new Zend_Db_Expr("DATE_ADD('".now()."', INTERVAL 2 HOUR)")))
//            ->limit(20)
        foreach($orderCollection->getItems() as $order)
            $orderModel = Mage::getModel('sales/order');
            if($orderModel->getState() == 'holded') {
                if(!$orderModel->canUnhold()) {
                } else {
            if(!$orderModel->canCancel()) {

Magento Warenkorb Daten im Header / Warenkorb auslesen – Magento: get cart data

6. Januar 2015 at 14:58
Den Warenkorb von Magento kann man wie folgt auslesen:
      $_countHelper = $this->helper('checkout/cart')->getSummaryCount();  //get total
      $_totalHelper = $this->helper('checkout/cart')->getQuote()->getGrandTotal(); //get total price
        echo $this->__('<a href="/checkout/cart" class="cartgo">(0 ITEMS)</a>',$count);
        echo $this->__('<a href="/checkout/cart" class="cartgo">(1 ITEM)</a>',$count);
        echo $this->__('<a href="/checkout/cart" class="cartgo">(%s ITMES)</a>',$count);
      echo $this->__('', $this->helper('core')->formatPrice($total, false));

Please share this article von facebook & google plus or where you want, thank you!

Magento: Add custom column in admin grid with own data & filter

29. August 2014 at 13:18

How to create a custom grid filter with a new column with own data (not from collection) and filter this data?

First Step

Enhance the grid, for example extends the Mage_Adminhtml_Block_Catalog_Category_Tab_Product

overwrite the  _prepareColumns() methode with new column

      $this->addColumn('price_yesno', array(
            'header'    => Mage::helper('catalog')->__('Price exist'),
            'sortable'  => true,
            'width'     => '60',
            'index'     => 'price',
            'type'      => 'options',
            'align'     => 'center',
            'renderer'  => 'Fly2mars_Catalog_Block_Adminhtml_Category_Renderer_Hasprice',
            'editable'  => 0,
            'options' => array('1' => 'Yes', '0' => 'No'),
            'filter_condition_callback' => array($this, '_filterHasPrice')
return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns();

And add in the same class the following callback methode

    protected function _filterHasPrice($collection, $column)
        $value = $column->getFilter()->getValue();
        $collection = $this->getCollection();
        if($value == 1) {
            $collection->addFieldToFilter('price', array('notnull' => true));
        } else {
            $collection->addFieldToFilter('price', array('null' => true));
        return $this;

Second Step

You need the renderer, for this example you add in the file Fly2mars_Catalog_Block_Adminhtml_Category_Renderer_Hasprice

class Fly2mars_Catalog_Block_Adminhtml_Category_Renderer_Hasprice
    extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
     * Check if product has price
     * @param   Varien_Object
     * @return  string
    protected function _getValue(Varien_Object $row)
        if($row->getData('price') != '') {
            return 'Yes';
        return 'No';

that’s it.

Please share this article von facebook & google plus or where you want, thank you!

Magento: Datum und Zeit / Date and Time

27. Mai 2014 at 14:48

Bei Operationen mit Datum und Zeit sollten die Klassen Mage_Core_Model_Date oder
Mage_Core_Model_Locale verwendet werden, um Zeitverschiebungen zu berücksichtigen.

Verwendung von now() und date() dafür nicht geeignet.

Beispiele zur Verwendung der Date Funktion in Magento

// get timestamp on server based time
$now = Mage::getModel('core/date')->timestamp(time());
// get server date and time
$now = Mage::getModel('core/date')->date('Y-m-d h:i:s');
// get UTC date and time
$now = Zend_Date::now();
$anyDate = '2011-12-11';
$currentDate = Mage::getModel('core/date')->date('d.m.Y', strtotime($anyDate));
// a more complete example with the im admin panel configured timezone
$datetime = Zend_Date::now();
// admin controls this output through configuration
echo $datetime->get(Zend_Date::DATETIME_SHORT);
// formated
$date = $datetime->toString("Y-MM-d_H:m:s");