I created custom fee based on following link.
(Please look at my module at : https://github.com/sivajik34/Delivery-Signature-Magento2)
how to add fee to order totals in magento2
Everything is working fine.but in order view page I'm getting following issue.
i think issue with following function
/**
* Initialize all order totals relates with tax
*
* @return \Magento\Tax\Block\Sales\Order\Tax
*/
public function initTotals()
{
$parent = $this->getParentBlock();
$this->_order = $parent->getOrder();
$this->_source = $parent->getSource();
$store = $this->getStore();
$fee = new \Magento\Framework\DataObject(
[
'code' => 'fee',
'strong' => false,
//'value' => 1090,
'value' => $this->_source->getFee(),
'label' => __('Fee'),
]
);
$parent->addTotal($fee, 'fee');
// $this->_addTax('grand_total');
$parent->addTotal($fee, 'fee');
return $this;
}
update: InstallData.php
<?php
namespace Kensium\DeliverySign\Setup;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Sales\Setup\SalesSetupFactory;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* Sales setup factory
*
* @var SalesSetupFactory
*/
protected $salesSetupFactory;
public function __construct(
SalesSetupFactory $salesSetupFactory
) {
$this->salesSetupFactory = $salesSetupFactory;
}
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var \Magento\Sales\Setup\SalesSetup $salesSetup */
$salesSetup = $this->salesSetupFactory->create(['setup' => $setup]);
$options = ['type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, 'required' => false];
$salesSetup->addAttribute('order', 'fee', $options);
$salesSetup->addAttribute('order', 'base_fee', $options);
}
}
fieldset.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
<scope id="global">
<fieldset id="sales_convert_quote_address">
<field name="fee">
<aspect name="to_order" />
</field>
<field name="base_fee">
<aspect name="to_order" />
</field>
</fieldset>
</scope>
</config>
Order fields added in sales_order table.but still values are not saved.
