1

I've installed the very helpful EA Design Free Invoice PDF extension and it's working a treat - except for one area.

The variables used in the editor are drawn from the backend, which means that

  1. The locale is taken from the backend setting, which means that I - working in English on a Japanese storefront - get the wrong language for country and region in addresses, and the wrong names for the payment method.
  2. The formatting set up in System>Config is ignored

I think I've tracked the fetching of the addresses down to the following bit of code deep in the Models folder

public function getTheAddresInfo()
{
    $order = $this->getOrder();
    $billingInfo = $order->getBillingAddress()->getFormated(true);
    if ($order->getShippingAddress()) {
        $shippingInfo = $order->getShippingAddress()->getFormated(true);
    } else {
        $shippingInfo = '';
    }
    $variables = array(
        'billing_address' => array(
            'value' => $billingInfo,
            'label' => Mage::helper('sales')->__('Billing Address'),
        ),
        'shipping_address' => array(
            'value' => $shippingInfo,
            'label' => Mage::helper('sales')->__('Shipping Address'),
        )
    );

The only other model I've found with similar content is in app/code/core/Mage/Customer/Model/Address/Abstract.php

/**
 * @deprecated for public function format
 */
public function getFormated($html=false)
{
    return $this->format($html ? 'html' : 'text');
    //Mage::getModel('directory/country')->load($this->getCountryId())->formatAddress($this, $html);
}

public function format($type)
{
    if(!($formatType = $this->getConfig()->getFormatByCode($type))
        || !$formatType->getRenderer()) {
        return null;
    }
    Mage::dispatchEvent('customer_address_format', array('type' => $formatType, 'address' => $this));
    return $formatType->getRenderer()->render($this);
}

/**
 * Retrive address config object
 *
 * @return Mage_Customer_Model_Address_Config
 */
public function getConfig()
{
    return Mage::getSingleton('customer/address_config');
}

This looks like the sort of thing I should introduce to the shipping/billing address variables to get them to come out in the defined HTML format, but I can't quite tie the ends together. Any pointers?

1

Order of Fields in invoice and wherever it appears can be changed from magento admin settings. Me too worked on a Japanese store front recently and their address format is a bit reversed.

So to change these order fields go to your store admin > System > Configuration and from left side navigation under Customers click Customer Configuration. Add than from the screen open Address Template block.

Here you will see various format of address and their field ordering. See in the screenshot below

enter image description here

  • So I changed the format here already, but it's not the format being read in this file. I'm interested to know where the format set in the backend configuration you mentioned is applied programmatically, and how to call it in the instance at hand – Ingrid Aug 21 '15 at 15:09
0

This question is quite old, but I got this post while searching for a similar solution for Magento2. So in case anybody else stumbles upon this post:

Magento2 is rendering the applied address format Magento\Customer\Block\Address\Renderer\DefaultRenderer which calls, at the end of method renderArray, the filterManager object with the template method.

Looking into the Magento\Framework\Filter\FilterManager class, we'll see, that the templatemethod is catched by a __call magic method.

Digging deeper we'll see that this Manager class initiates the class Magento\Framework\Filter\Template.

Now here is where the magic happens:

/**
 * Filter the string as template.
 *
 * @param string $value
 * @return string
 * @throws \Exception
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
 */
public function filter($value)
{
    // "depend", "if", and "template" directives should be first
    foreach ([
                 self::CONSTRUCTION_DEPEND_PATTERN => 'dependDirective',
                 self::CONSTRUCTION_IF_PATTERN => 'ifDirective',
                 self::CONSTRUCTION_TEMPLATE_PATTERN => 'templateDirective',
             ] as $pattern => $directive) {
        if (preg_match_all($pattern, $value, $constructions, PREG_SET_ORDER)) {
            foreach ($constructions as $construction) {
                $callback = [$this, $directive];
                if (!is_callable($callback)) {
                    continue;
                }
                try {
                    $replacedValue = call_user_func($callback, $construction);
                } catch (\Exception $e) {
                    throw $e;
                }
                $value = str_replace($construction[0], $replacedValue, $value);
            }
        }
    }

    if (preg_match_all(self::CONSTRUCTION_PATTERN, $value, $constructions, PREG_SET_ORDER)) {
        foreach ($constructions as $construction) {
            $callback = [$this, $construction[1] . 'Directive'];
            if (!is_callable($callback)) {
                continue;
            }
            try {
                $replacedValue = call_user_func($callback, $construction);
            } catch (\Exception $e) {
                throw $e;
            }
            $value = str_replace($construction[0], $replacedValue, $value);
        }
    }

    $value = $this->afterFilter($value);
    return $value;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.