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

23. August 2016 at 18:18

firebug

In function „getCondition“ in der class
app/code/community/MDN/CrmTicket/Block/Admin/Widget/Grid/Column/Filter/CustomerName.php

change this buggy part

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

to

        if ($customerIdsSelected && sizeof($customerIdsSelected)>0) {
            if(count($customerIdsSelected) == 1 && count($customerIdsSelected[0]) > 0) {
                return array('in' => $customerIdsSelected);
            } else {
                return null;
            }
        }
        else
          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!

GD Star Rating
loading...
GD Star Rating
loading...

Sending json data to a remote server – howto

21. April 2016 at 14:00

firebug

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);
var_dump($response);

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‘);
var_dump($client->request()->getBody());

3. Using Curl

<?php
$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);
var_dump($response);
curl_close($curl);
?>

4. Using Ajax

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

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

GD Star Rating
loading...
GD Star Rating
loading...

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

10. November 2015 at 11:25

db

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

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

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 1.9.2.2
Package community/Mage_All_Latest 1.9.2.2 installed successfully
Starting to download Interface_Adminhtml_Default-1.9.2.2.tgz ...
...done: 1,014,275 bytes
Installing package community/Interface_Adminhtml_Default 1.9.2.2
Package community/Interface_Adminhtml_Default 1.9.2.2 installed successfully
Starting to download Interface_Frontend_Default-1.9.2.2.tgz ...
...done: 747,738 bytes
Installing package community/Interface_Frontend_Default 1.9.2.2
...

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!

GD Star Rating
loading...
GD Star Rating
loading...

Magento: Access Denied errors after installing SUPEE-6285 or since Magento 1.9.2.1 – 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!

GD Star Rating
loading...
GD Star Rating
loading...

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!

GD Star Rating
loading...
GD Star Rating
loading...

Magento: Save admin name to order_status change using an Observer

28. April 2015 at 15:24

php code

config.xml:

<adminhtml>
  <events>
    <sales_order_status_history_save_before>
      <observers>
        <module_status_history_save_before>
          <class>module/observer</class>
          <method>addUserNameBeforeComment</method>
        </module_status_history_save_before>
      </observers>
    </sales_order_status_history_save_before>
  </events>
</adminhtml>

Observer.php:

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!

GD Star Rating
loading...
GD Star Rating
loading...

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');
        $orderCollection
            ->addFieldToFilter('state',
                array(
                    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)")))
            ->getSelect()
            ->order('entity_id')
//            ->limit(20)
            ;
        foreach($orderCollection->getItems() as $order)
        {
            $orderModel = Mage::getModel('sales/order');
            $orderModel->load($order['entity_id']);
            if($orderModel->getState() == 'holded') {
                if(!$orderModel->canUnhold()) {
                    continue;
                } else {
                    $orderModel->unhold();
                    $orderModel->setStatus('new');
                }
            }
            if(!$orderModel->canCancel()) {
                continue;
            }
            $orderModel->cancel();
            $orderModel->setStatus('canceled');
            $orderModel->save();
        }
    }
GD Star Rating
loading...
GD Star Rating
loading...

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:
<?php
      $_countHelper = $this->helper('checkout/cart')->getSummaryCount();  //get total items in cart
      $_totalHelper = $this->helper('checkout/cart')->getQuote()->getGrandTotal(); //get total price
      if($count==0)
      {
        echo $this->__('<a href="/checkout/cart" class="cartgo">(0 ITEMS)</a>',$count);
      }
      if($count==1)
      {
        echo $this->__('<a href="/checkout/cart" class="cartgo">(1 ITEM)</a>',$count);
      }
      if($count>1)
      {
        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!

GD Star Rating
loading...
GD Star Rating
loading...

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!

GD Star Rating
loading...
GD Star Rating
loading...

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
$datetime->setLocale(Mage::getStoreConfig(
Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE))
->setTimezone(Mage::getStoreConfig(
Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE));
echo $datetime->get(Zend_Date::DATETIME_SHORT);
// formated
$date = $datetime->toString("Y-MM-d_H:m:s");
GD Star Rating
loading...
GD Star Rating
loading...