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

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


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

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

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, you have to add your block into whitelist. You can do it manually, in backoffice, System > Permissions > Blocks or do it programmatically :

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

Magento – Adding additional store addresses

Magento allows you to define 5 email addresses in backoffice, to add some, create (or use an existing) system.xml in a new (or existing) module like this

                <ident_relance translate="label">
                        <email translate="label">
                            <label>Sender Email</label>
                        <name translate="label">
                            <label>Sender Name</label>

In this case, this will create 2 entries in the core_config_data table : trans_email/ident_relance/email and trans_email/ident_relance/name.

To retrieve values, use this :


Magento – add something in the header section

If you need to add something in the header section of all your pages, you can go on your template and add it to the files 1column.phtml, 2columns-left.phtml, 2columns-right.phtml… You can, but you shouldn’t, it’s not a good practice.

Let’s see the content of one of this file

<?php echo $this->getChildHtml('head') ?>

You can see the section will be filled with all “head” child block, so let’s create one.

On your layout file (design/frontend/adin/default/layout/adin_page.xml), add the declaration of your new block

<layout version="0.1.0">
        <reference name="head" before="-">
            <block type="adin_page/headerstuff" name="headerstuff" as="headerstuff" template="page/html/headerstuff.phtml" />

Create the block class in app/code/local/Adin/Page/Block/Headerstuff.php

class Adin_Page_Block_Headerstuff extends Mage_Core_Block_Template
    public function _construct()

And create you template file app/design/frontend/adin/default/template/page/html/headerstuff.phtml

<!-- header my stuff to put in the header -->

Magento – all you need about website / store / view

// Gets the current store's details
$store = Mage::app()->getStore();
// Gets the current store's id
$storeId = Mage::app()->getStore()->getStoreId();
// Gets the current store's code
$storeCode = Mage::app()->getStore()->getCode();
// Gets the current website's id
$websiteId = Mage::app()->getStore()->getWebsiteId();
// Gets the current store's group id
$storeGroupId = Mage::app()->getStore()->getGroupId();
// Gets the current store's name
$storeName = Mage::app()->getStore()->getName();
// Gets the current store's sort order
$storeSortOrder = Mage::app()->getStore()->getSortOrder();
// Gets the current store's status
$storeIsActive = Mage::app()->getStore()->getIsActive();
// Gets the current store's locale
$storeLocaleCode = Mage::app()->getStore()->getLocaleCode();
// Gets the current store's home url
$storeHomeUrl = Mage::app()->getStore()->getHomeUrl();

//load store by code or id
$store = Mage::getModel('core/store')->load($code); //you can use code or id

magento create tier prices programmatically

Here a simple script to create tier prices programmatically

$product = Mage::getModel('catalog/product')->load(904);
$tier_price = array();
foreach($tarif->getQtyDetails() as $detail)
   $tier_price[] = array(
     'cust_group'    => 32000,
     'website_id'    => 0,
     'all_groups'    => 1,
     'price_qty'     => $detail->getMin(),
     'price'         => $detail->getPrix(),
     'website_price' => $detail->getPrix(),