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: Fixing error „[unknown object].fireEvent()“

8. Januar 2015 at 10:02

Recently I’ve encountered the following Javascript error in my Magento store:

error: error in [unknown object].fireEvent():
event name: address_country_changed
error message: zipElement.up(…).down(…) is undefined

This error pops out when creating the order from admin panel and entering customer shipping address. It pops out when editing every filed in the address, which is quite annoying.

Regarding to this forum post, this has something to do with defining the zip code as not required filed in the database. Specialists recommend to set zip code as required filed in the database and then setting it as not required on the country basis. But people report that setting so will still not make zip code as optional field.

So I decided to do my own fix. Here it is:

1. Copy the file app\design\adminhtml\default\default\template\directory\js\optional_zip_countries.phtml to your local design-folder like

app\design\adminhtml\default\fly2marsmedia\template\directory\js\optional_zip_countries.phtml

2. Navigate approximately to line 57.

3. Find the function setPostcodeOptional(zipElement, country)

4. Find the following line: zipElement.up(1).down(‚label > span.required‘).hide();

5. Change it to the following code:

var zipElementLabel = zipElement.up(1).down('label > span.required');
 if (zipElementLabel)
 zipElementLabel.hide();

6. Find the following line: zipElement.up(1).down(‚label > span.required‘).show();

7. Change it to the following code:

var zipElementLabel = zipElement.up(1).down('label > span.required');
if (zipElementLabel)
zipElementLabel.show();

Notice that this code repeats two times inside the function, but differs a little bit in „hide()“ and „show()“ calls at the end.

8. Save the file and upload to the server. Page reload might be required.

This helped me fighting the mentioned error in Magento version 1.9.0.1 and other versions.

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

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

Magento: Session Variable – Set Unset Session Variable

20. August 2010 at 15:48

Es wird eine individuelle Variable mit den Namen „magentoTest“ angelegt. Der Wert für diese ist in diesem Fall „hello magento“.

$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$session->setMagentoTest('hello magento');

Abfragen der Werte:

$test = Mage::getSingleton('core/session')->getMagentoTest();

Session Variable löschen / unset

Mage::getSingleton('core/session')->setMagentoTest();

Nur eine bestimmte Session-Variable löschen:

Mage::getSingleton('core/session')->unsMagentoTest();

(Im Frontend die Customer oder Core Session benutzen. Im Backend die Adminhtml Session benutzen.)
Core Session:- Mage::getSingleton(‘core/session’)
Customer Session:- Mage::getSingleton(‘customer/session’)
Admin Session:- Mage::getSingleton(‘adminhtml/session’)

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