Magento add order history

There is several ways to add order history, with less or more data

Quick way :

 $message = 'Comment to add in order history';
 $order->addStatusHistoryComment($message);
 $order->save();

With all informations :

$history = Mage::getModel('sales/order_status_history')
  ->setStatus($order->getStatus())
  ->setComment('Comment to add in order history')
  ->setEntityName(Mage_Sales_Model_Order::HISTORY_ENTITY_NAME)
  ->setIsCustomerNotified(false)
  ->setCreatedAt(date('Y-m-d H:i:s', time()));

  $order->addStatusHistory($history);
  $order->save();

Magento – create new table column from installer

TO create a new table columnusing magento installer, you can use this method :

$installer = $this;
$connection = $installer->getConnection();
$installer->startSetup();
  if ($connection->tableColumnExists($this->getTable('adin/slider'), 'image_mobile') === false) {
        $installer->run("ALTER TABLE `{$installer->getTable('adin/slider')}` ADD COLUMN  `image_mobile` VARCHAR(255)  NOT NULL DEFAULT '' ;");
    }
$installer->endSetup();

Magento – Emulate store

It’s that simple :

$appEmulation = Mage::getSingleton('core/app_emulation');
 
//Start environment emulation of the specified store
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);

 
//Stop environment emulation and restore original store
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

Gmail & Our system has detected that this message does 550-5.7.1 not meet IPv6 sending guidelines regarding PTR records and 550-5.7.1 authentication.

Your webserver is sending emails but gmail refused them with this message :

Dec 23 08:44:30 extranet postfix/smtp[24387]: F3443907: to=, relay=gmail-smtp-in.l.google.com[2a00:1450:400c:c06::1b]:25, delay=0.32, delays=0.02/0.01/0.19/0.11, dsn=5.7.1, status=bounced (host gmail-smtp-in.l.google.com[2a00:1450:400c:c06::1b] said: 550-5.7.1 [2001:41d0:1008:2b5a::] Our system has detected that this message does 550-5.7.1 not meet IPv6 sending guidelines regarding PTR records and 550-5.7.1 authentication. Please review 550-5.7.1 https://support.google.com/mail/?p=IPv6AuthError for more information 550 5.7.1 . 196si30999080wmg.139 – gsmtp (in reply to end of DATA command))

To fix it add this on your main.cf postfix configuration file :
inet_protocols=ipv4

That’s all

Magento – edit breadcrumb from block

To edit a breadcrumb from the block, you can simply do that :

class Adin_Sales_Block_Invoice_View extends Mage_Core_Block_Template
{

    private $_mainOrder;

    public function _prepareLayout()
    {
        if ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) {
            $breadcrumbs->addCrumb('All orders', array('label'=>$this->__('All my invoices'), 'title'=>$this->__('All my invoices'), 'link'=>$this->getUrl('sales/invoice/history')));
            $breadcrumbs->addCrumb('My order', array('label'=>$this->__('My invoices : order %s', $this->_mainOrder->getIncrementId()), 'title'=>$this->__('My invoices : order %s',$this->_mainOrder->getIncrementId()), ));
        }
        return parent::_prepareLayout();
    }

$_mainOrder is defined in the __contruct() function

Magento – empty $_FILES while uploading files in adminhtml

You made a form in adminhtml with upload file but in the controller the $_FILES var is hopelessly empty ?
You probably forgot to add “‘enctype’ => ‘multipart/form-data’,” on your form declaration

example :
file : /app/code/local/Adin/Shipping/Block/Adminhtml/Delivery/Cost/Import/Edit/Form.php

protected function _prepareForm()
{
$form = new Varien_Data_Form(array(
            'id'        => 'edit_form',
            'action'    => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
            'method'    => 'post',
            'enctype'   => 'multipart/form-data',
        ));

 $fieldset->addField('fichier', 'file', array(
            'label'     => $helper->__('Data file'),
            'value'	=> 'upload',
            'name'  => 'fichier',
            'after_element_html'     => $helper->__('<small>File from carrier</small>'),
            'required'  => true,
        ));

Magento – The Order State “complete” must not be set manually.

If you want to update order status & state programmaticaly, you try this

$order->setStatus(Mage_Sales_Model_Order::STATE_COMPLETE);
$order->setState(Mage_Sales_Model_Order::STATE_COMPLETE);

And you get this error :

The Order state 'complete' must not be set manually.

To fix it, use this :

$order->addStatusToHistory(Mage_Sales_Model_Order::STATE_COMPLETE, "Comments");
$order->setData('state', Mage_Sales_Model_Order::STATE_COMPLETE);

FPDF error: This document (docuement.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI.

If you ever encounter this error “FPDF error: This document (docuement.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI.”, this is a version problem, FPDF library supports only PDF version 1.4 and previous.

So, what can you do ? change PDF version with ghostscript.

Download it here http://www.ghostscript.com/download/gsdnld.html

run to change :

 ./gs-919-linux_x86_64 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=file.pdf newfile.pdf 

Magento add block into cms page and add permissions

If you want to add a block into cms page, you just have to add this into its content

{{block type="adin_page/page_html_combos" name="combos" template="page/html/combos.phtml"}} 

Of course, don’t forget to create the block class app/code/local/Adin/Page/Block/Page/Html/Combos.php

class Adin_Page_Block_Page_Html_Combos extends Mage_Core_Block_Template
{
//...
}

and the .phtml file
app/design/frontend/adin/default/template/page/html/combos.phtml

But when you want to render the page, nothing.
On the logs (system.log), you have : Security problem: adin_page/page_html_combos has not been whitelisted.
It’s a new feature since securoty Patch SUPEE-7405 and Magento CE 1.9.2.2, you have to add your block into whitelist. You can do it manually, in backoffice, System > Permissions > Blocks or do it programmatically :

$blockNames = array(
    'adin_page/page_html_combos'
);
foreach ($blockNames as $blockName) {
    $whitelistBlock = Mage::getModel('admin/block')->load($blockName, 'block_name');
    $whitelistBlock->setData('block_name', $blockName);
    $whitelistBlock->setData('is_allowed', 1);
    $whitelistBlock->save();
}