How to add third decimal point to products, orders, tax, shipping price in both frontend and backend ?
Ex:
Product: 12.55$ ==> 12.550$
magento2.1.5
How to add third decimal point to products, orders, tax, shipping price in both frontend and backend ?
Ex:
Product: 12.55$ ==> 12.550$
We faced this issue when we were trying to import custom options.
As shared in Importing products with custom options
To solve this just add empty column store_view_code to CSV file.
The sequence of this column is also important, its usually the second column.
Okay finally I've resolved this by myself here is the full code of my module...
registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Vendor_Module',
__DIR__
);
etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0"></module>
</config>
Setup/InstallData.php
<?php
namespace Vendor\Module\Setup;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
public function __construct(
EavSetupFactory $eavSetupFactory
)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
"testone",
[
'group' => "",
'label' => "Test One",
'is_html_allowed_on_front' => true,
'default' => '1',
'note' => '',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'visible_in_advanced_search' => false,
'unique' => false,
"frontend_class" => "",
"used_in_product_listing" => true,
"input" => "select",
"type" => "varchar",
"source" => "Vendor\Module\Model\Config\Source\TimeSetup",
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend'
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
"testtwo",
[
'group' => "",
'label' => "Test Two",
'is_html_allowed_on_front' => true,
'default' => '1',
'note' => '',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'visible_in_advanced_search' => false,
'unique' => false,
"frontend_class" => "",
"used_in_product_listing" => true,
"input" => "select",
"type" => "varchar",
"source" => "Vendor\Module\Model\Config\Source\TimeSetup",
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend'
]
);
}
}
Model\Config\Source\TimeSetup.php
<?php
namespace Vendor\Module\Model\Config\Source;
class TimeSetup extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
{
protected $_optionsData;
/**
* getAllOptions
*
* @return array
*/
public function getAllOptions()
{
if ($this->_options === null) {
$this->_options = [
['value' => 'one', 'label' => __('one')],
['value' => 'two', 'label' => __('two')]
];
}
return $this->_options;
}
final public function toOptionArray()
{
return array(
array('value' => 'one', 'label' => __('one')),
array('value' => 'two', 'label' => __('two'))
);
}
}
view/adminhtml/ui_component/product_form.xml
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="testingproduct">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Testing Group</item>
<item name="provider" xsi:type="string">product</item>
<item name="dataScope" xsi:type="string">data.product</item>
<item name="sortOrder" xsi:type="number">2</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="opened" xsi:type="boolean">false</item>
<item name="ns" xsi:type="string">product_form</item>
</item>
</argument>
<container name="testing_group">
<argument name="data" xsi:type="array">
<item name="type" xsi:type="string">group</item>
<item name="config" xsi:type="array">
<item name="formElement" xsi:type="string">container</item>
<item name="component" xsi:type="string">Magento_Ui/js/form/components/group</item>
<item name="label" xsi:type="string" translate="true">Testing Group</item>
<item name="required" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="number">220</item>
<item name="breakLine" xsi:type="boolean">false</item>
<item name="scopeLabel" xsi:type="string">[STORE VIEW]</item>
</item>
</argument>
<field name="testone">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Vendor\Module\Model\Config\Source\TimeSetup</item>
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Testing Row</item>
<item name="sortOrder" xsi:type="number">230</item>
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">select</item>
</item>
</argument>
</field>
<field name="testtwo">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Vendor\Module\Model\Config\Source\TimeSetup</item>
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">240</item>
<item name="dataType" xsi:type="string">string</item>
<item name="formElement" xsi:type="string">select</item>
</item>
</argument>
</field>
</container>
</fieldset>
</form>
Using above code, Data saving properly, Only issues I'm facing now is that These attributes are appearing in General section as well in my created custom section which is "Testing Group" so as of now I've hide them from General section using CSS.
Best Answer
In Magento2, there are different ways you can get this,
by Using this code inside your view file(.phtml)
This means there can be 7 digits to the left of the decimal point (7-3) and 3 to the right of the decimal point.
OR
/vendor/magento/framework/Pricing/PriceCurrencyInterface.php
Change
const DEFAULT_PRECISION = 2;
To
const DEFAULT_PRECISION = 3;
Edit For this you could go for module like this one.
Then flush cache.
Hope this will help.