0

so I'm having trouble to translate the order confirmation email template. the problem is with the lower part where the totals are shown see the image below: enter image description here

This is the Totals.php where it's declared, maybe this file is not right?

namespace Magento\Sales\Block\Order;

use Magento\Sales\Model\Order;

class Totals extends \Magento\Framework\View\Element\Template
{
/**
 * Associated array of totals
 * array(
 *  $totalCode => $totalObject
 * )
 *
 * @var array
 */
protected $_totals;

/**
 * @var Order|null
 */
protected $_order = null;

/**
 * Core registry
 *
 * @var \Magento\Framework\Registry
 */
protected $_coreRegistry = null;

/**
 * @param \Magento\Framework\View\Element\Template\Context $context
 * @param \Magento\Framework\Registry $registry
 * @param array $data
 */
public function __construct(
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Framework\Registry $registry,
    array $data = []
) {
    $this->_coreRegistry = $registry;
    parent::__construct($context, $data);
}

/**
 * Initialize self totals and children blocks totals before html building
 *
 * @return $this
 */
protected function _beforeToHtml()
{
    $this->_initTotals();
    foreach ($this->getLayout()->getChildBlocks($this->getNameInLayout()) as $child) {
        if (method_exists($child, 'initTotals') && is_callable([$child, 'initTotals'])) {
            $child->initTotals();
        }
    }
    return parent::_beforeToHtml();
}

/**
 * Get order object
 *
 * @return Order
 */
public function getOrder()
{
    if ($this->_order === null) {
        if ($this->hasData('order')) {
            $this->_order = $this->_getData('order');
        } elseif ($this->_coreRegistry->registry('current_order')) {
            $this->_order = $this->_coreRegistry->registry('current_order');
        } elseif ($this->getParentBlock()->getOrder()) {
            $this->_order = $this->getParentBlock()->getOrder();
        }
    }
    return $this->_order;
}

/**
 * @param Order $order
 * @return $this
 */
public function setOrder($order)
{
    $this->_order = $order;
    return $this;
}

/**
 * Get totals source object
 *
 * @return Order
 */
public function getSource()
{
    return $this->getOrder();
}

/**
 * Initialize order totals array
 *
 * @return $this
 */
protected function _initTotals()
{
    $source = $this->getSource();

    $this->_totals = [];
    $this->_totals['subtotal'] = new \Magento\Framework\DataObject(
        ['code' => 'subtotal', 'value' => $source->getSubtotal(), 'label' => __('Subtotal')]
    );

    /**
     * Add shipping
     */
    if (!$source->getIsVirtual() && ((double)$source->getShippingAmount() || $source->getShippingDescription())) {
        $this->_totals['shipping'] = new \Magento\Framework\DataObject(
            [
                'code' => 'shipping',
                'field' => 'shipping_amount',
                'value' => $this->getSource()->getShippingAmount(),
                'label' => __('Shipping & Handling'),
            ]
        );
    }

    /**
     * Add discount
     */
    if ((double)$this->getSource()->getDiscountAmount() != 0) {
        if ($this->getSource()->getDiscountDescription()) {
            $discountLabel = __('Discount (%1)', $source->getDiscountDescription());
        } else {
            $discountLabel = __('Discount');
        }
        $this->_totals['discount'] = new \Magento\Framework\DataObject(
            [
                'code' => 'discount',
                'field' => 'discount_amount',
                'value' => $source->getDiscountAmount(),
                'label' => $discountLabel,
            ]
        );
    }

    $this->_totals['grand_total'] = new \Magento\Framework\DataObject(
        [
            'code' => 'grand_total',
            'field' => 'grand_total',
            'strong' => true,
            'value' => $source->getGrandTotal(),
            'label' => __('Grand Total'),
        ]
    );

    /**
     * Base grandtotal
     */
    if ($this->getOrder()->isCurrencyDifferent()) {
        $this->_totals['base_grandtotal'] = new \Magento\Framework\DataObject(
            [
                'code' => 'base_grandtotal',
                'value' => $this->getOrder()->formatBasePrice($source->getBaseGrandTotal()),
                'label' => __('Grand Total to be Charged'),
                'is_formated' => true,
            ]
        );
    }
    return $this;
}

/**
 * Add new total to totals array after specific total or before last total by default
 *
 * @param   \Magento\Framework\DataObject $total
 * @param   null|string $after
 * @return  $this
 */
public function addTotal(\Magento\Framework\DataObject $total, $after = null)
{
    if ($after !== null && $after != 'last' && $after != 'first') {
        $totals = [];
        $added = false;
        foreach ($this->_totals as $code => $item) {
            $totals[$code] = $item;
            if ($code == $after) {
                $added = true;
                $totals[$total->getCode()] = $total;
            }
        }
        if (!$added) {
            $last = array_pop($totals);
            $totals[$total->getCode()] = $total;
            $totals[$last->getCode()] = $last;
        }
        $this->_totals = $totals;
    } elseif ($after == 'last') {
        $this->_totals[$total->getCode()] = $total;
    } elseif ($after == 'first') {
        $totals = [$total->getCode() => $total];
        $this->_totals = array_merge($totals, $this->_totals);
    } else {
        $last = array_pop($this->_totals);
        $this->_totals[$total->getCode()] = $total;
        $this->_totals[$last->getCode()] = $last;
    }
    return $this;
}

/**
 * Add new total to totals array before specific total or after first total by default
 *
 * @param   \Magento\Framework\DataObject $total
 * @param   null|string $before
 * @return  $this
 */
public function addTotalBefore(\Magento\Framework\DataObject $total, $before = null)
{
    if ($before !== null) {
        if (!is_array($before)) {
            $before = [$before];
        }
        foreach ($before as $beforeTotals) {
            if (isset($this->_totals[$beforeTotals])) {
                $totals = [];
                foreach ($this->_totals as $code => $item) {
                    if ($code == $beforeTotals) {
                        $totals[$total->getCode()] = $total;
                    }
                    $totals[$code] = $item;
                }
                $this->_totals = $totals;
                return $this;
            }
        }
    }
    $totals = [];
    $first = array_shift($this->_totals);
    $totals[$first->getCode()] = $first;
    $totals[$total->getCode()] = $total;
    foreach ($this->_totals as $code => $item) {
        $totals[$code] = $item;
    }
    $this->_totals = $totals;
    return $this;
}

/**
 * Get Total object by code
 *
 * @param string $code
 * @return mixed
 */
public function getTotal($code)
{
    if (isset($this->_totals[$code])) {
        return $this->_totals[$code];
    }
    return false;
}

/**
 * Delete total by specific
 *
 * @param   string $code
 * @return  $this
 */
public function removeTotal($code)
{
    unset($this->_totals[$code]);
    return $this;
}

/**
 * Apply sort orders to totals array.
 * Array should have next structure
 * array(
 *  $totalCode => $totalSortOrder
 * )
 *
 *
 * @param   array $order
 * @return  $this
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function applySortOrder($order)
{
    return $this;
}

/**
 * get totals array for visualization
 *
 * @param array|null $area
 * @return array
 */
public function getTotals($area = null)
{
    $totals = [];
    if ($area === null) {
        $totals = $this->_totals;
    } else {
        $area = (string)$area;
        foreach ($this->_totals as $total) {
            $totalArea = (string)$total->getArea();
            if ($totalArea == $area) {
                $totals[] = $total;
            }
        }
    }
    return $totals;
}

/**
 * Format total value based on order currency
 *
 * @param   \Magento\Framework\DataObject $total
 * @return  string
 */
public function formatValue($total)
{
    if (!$total->getIsFormated()) {
        return $this->getOrder()->formatPrice($total->getValue());
    }
    return $total->getValue();
}
}

Do someone have an idea what I can do here, to get this translated with CSV

Notice: the CSV file is working fine most of the email are translated with it. just these part at the order confirmation email is not.

2
  • This email send from backed or frontend? Because some time translation not working if email send from backed order view Send Email button
    – user52581
    Apr 22, 2017 at 1:48
  • This is send when someone buys something, to confirm that the product is bought. so basically from the frontend
    – key
    Apr 23, 2017 at 11:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.