Adding new column in Sales Order View Items in Magento Admin - magento

In the admin interface of Magento I need to modify the tables in the Sales / Order / View order so that it shows, besides the products name, their manufacturer as well.
I'm trying to look for the file to modify to make that happen. I thought I would find a section with all the columns that are displayed in app/code/core/Mage/Sales/Block/Order/Item/Renderer/Default.php but by inspecting it there seem to be no reference to the columns/product attributes.
I also tried to modify
app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml
by changing
<?php echo $this->getColumnHtml($_item, 'name') ?>
into
<?php echo $this->getColumnHtml($_item, 'manufacturer') ?>
but it changed nothing, so I suppose that file is not involved...
Can anybody please point me to the right file to modify?
Thank you!

After quite a lot of browsing through the code and with some help from a collegue, we found out the two file to change for adding a column to such view:
app/design/adminhtml/default/default/template/sales/order/view/items.phtml
for adding the table header
app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml for filling the column with data.
I'm not really experienced with Magento but I guess that, in order to do a "clean job", one should not directly modify those files but override them instead.
EDIT
app/design/adminhtml/default/default/template/downloadable/sales/order/view/items/renderer/downloadable.phtml for filling the column with data for downloadable products.

For adding the table header and it's value add layout sales_order_view.xml in your theme or module with new argument.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="order_items">
<arguments>
<argument name="columns" xsi:type="array">
<item name="product" xsi:type="string" translate="true">Product</item>
<item name="status" xsi:type="string" translate="true">Item Status</item>
<item name="price-original" xsi:type="string" translate="true">Original Price</item>
<item name="price" xsi:type="string" translate="true">Price</item>
<item name="ordered-qty" xsi:type="string" translate="true">Qty</item>
<item name="subtotal" xsi:type="string" translate="true">Subtotal</item>
<item name="tax-amount" xsi:type="string" translate="true">Tax Amount</item>
<item name="tax-percent" xsi:type="string" translate="true">Tax Percent</item>
<item name="discont" xsi:type="string" translate="true">Discount Amount</item>
<item name="total" xsi:type="string" translate="true">Row Total</item>
<item name="repair" xsi:type="string" translate="true">Repair</item>
</argument>
</arguments>
<block class="Namespace\Module\Block\Adminhtml\DefaultRenderer" as="default" template="Magento_Sales::order/view/items/renderer/default.phtml">
<arguments>
<argument name="columns" xsi:type="array">
<item name="product" xsi:type="string" translate="false">col-product</item>
<item name="status" xsi:type="string" translate="false">col-status</item>
<item name="price-original" xsi:type="string" translate="false">col-price-original</item>
<item name="price" xsi:type="string" translate="false">col-price</item>
<item name="qty" xsi:type="string" translate="false">col-ordered-qty</item>
<item name="subtotal" xsi:type="string" translate="false">col-subtotal</item>
<item name="tax-amount" xsi:type="string" translate="false">col-tax-amount</item>
<item name="tax-percent" xsi:type="string" translate="false">col-tax-percent</item>
<item name="discont" xsi:type="string" translate="false">col-discont</item>
<item name="total" xsi:type="string" translate="false">col-total</item>
<item name="repair" xsi:type="string" translate="false">col-repair</item>
</argument>
</arguments>
</block>
</referenceBlock>
</body>
`
I have added new column with name repair.
now you have to add value for that column. so you have to override '\Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer' file in your block and in getColumnHtml() method you have to add your value for that column.

http://magentocoder.jigneshpatel.co.in/create-custom-reports-in-magento-admin/
Should get you most of the way.

For adding the table header:
app/design/adminhtml/default/default/template/sales/order/view/items.phtml
app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml
These files are useful.

Admin grids are ofter controlled by their block.
For sales it's the Mage_Adminhtml_Block_Sales_Order_Grid class
modifying/overriding method _prepareColumns() should do the trick

I've no magento installation available, but I have some ideas.
Maybe the column is not defined inside a template file (phtml), but inside a xml layout file.
Just search in the layout/sales.xml file.
And maybe you have not disabled the magento cache, that's why you don't see any changes.

Related

How to render HTML tags in admin product grid, Magento2.3?

I'm trying to make an anchor link in the product grid view.
I have tried this using UI component, below are the detailed view
xml code:
<column name="column_name" class="Vendor\Module\Ui\Component\Listing\Column\link">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Label</item>
<item name="sortOrder" xsi:type="number">50</item>
</item>
</argument>
</column>
datasource code:
$html = ''. __('Label').'';
$item[$this->getData('name')] = $html;
Getting html like this: Label
I want 'Label' with the anchor link.

Set required for Tax/VAT field for a specific store in magento 2

I have a magento store with different store view. I want to show Tax/Vat field on checkout but it will mandatory for Italy only.
What i have done:
After selection store view, from customer->customer configuration i have set Show VAT number on Storefront YES
and Show VAT Number set Required.
In checkout page VAT field is showing but required validation not working.
I have tried overwrite with jQuery but didnt succeed. I guess adding attribute in knockjs might be a option but i am really dont know. Can any one help me out. I am stuck.
magento version 2.2.5
I got an alternative solution.
update checkout_index_index.xml
Check closely this line for vat_id <item name="required-entry" xsi:type="boolean">true</item>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-address-fieldset" xsi:type="array">
<item name="children" xsi:type="array">
<item name="vat_id" xsi:type="array">
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
It works for me.
NB: But i am sure most of the cases set VAT ID required at checkout it should be done configuring from admin.

magento ui component multiselect xml

I can not understand why the error
Could not save the brand: Notice: Array to string conversion in C:\OpenServer\domains\localhost\2016\mercury_61189_222_007\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php on line 228
on the idea of all done right, here is the code of the module
<field name="website_id_2">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Magento\Store\Model\ResourceModel\Website\Collection</item>
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Website 2</item>
<item name="formElement" xsi:type="string">multiselect</item>
<item name="source" xsi:type="string">page</item>
<item name="dataScope" xsi:type="string">website_id_2</item>
<item name="validation" xsi:type="array">
<item name="required-entry" xsi:type="boolean">true</item>
</item>
</item>
</argument>
</field>
Can someone know the nuances?
I decided my question.
It was necessary for the save function to execute () to write 2 lines to preserve the array
$data['website_id_2']=implode(',',$data['website_id_2']);
$model->setData($data)->setId($this->getRequest()->getParam('id'));

magento 2.0 and 2.1 massaction compatibility issue admin back-end

We have a custom written Magento 2 module that adds an action to the order overview dropdown.
Now have we ran into an issue where it would work on 2.0.x but not 2.1.x and up.
After a bit of research it is caused by Magento changing an xml node from container to listingToolbar.
Now my question is, how do we make our module compatible with both 2.0.x and 2.1.x?
Adding both; container and listingToolbar will break the massaction dropdown.
magento 2.0.x version:
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<container name="listing_top">
<massaction name="listing_massaction">
<action name="new_action">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">action_name</item>
<item name="label" xsi:type="string" translate="true">Action Name Text Here</item>
<item name="url" xsi:type="url" path="vendor_module/action"/>
</item>
</argument>
</action>
</massaction>
</container>
magento 2.1.x version:
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<listingToolbar name="listing_top">
<massaction name="listing_massaction">
<action name="new_action">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">action_name</item>
<item name="label" xsi:type="string" translate="true">Action Name Text Here</item>
<item name="url" xsi:type="url" path="vendor_module/action"/>
</item>
</argument>
</action>
</massaction>
</listingToolbar>

Magento 2 Ui Component wysiwyg

In Magento 2 how can we add the WYSIWYG editor with the text area field with the form ui component xml file? To add the text area i am using the following code in xml file.
<field name="detail">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="visible" xsi:type="boolean">true</item>
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">textarea</item>
<item name="source" xsi:type="string">sample_shop</item>
<item name="label" xsi:type="string">Detail</item>
</item>
</argument>
</field>
In your ui component form xml file add the field like this.
<field name="detail">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">text</item>
<item name="formElement" xsi:type="string">wysiwyg</item>
<item name="source" xsi:type="string">sample_shop</item>
<item name="label" xsi:type="string">Detail</item>
<item name="template" xsi:type="string">ui/form/field</item>
<item name="wysiwyg" xsi:type="boolean">true</item>
<item name="dataScope" xsi:type="string">detail</item>
<item name="sortOrder" xsi:type="number">50</item>
<item name="rows" xsi:type="number">8</item>
</item>
</argument>
</field>
From Magento 2.2, below could work too. And it has better readability and usability.
<field name="content" formElement="wysiwyg">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">block</item>
</item>
</argument>
<settings>
<additionalClasses>
<class name="admin__field-wide">true</class>
</additionalClasses>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
</validation>
<label/>
<dataScope>content</dataScope>
</settings>
<formElements>
<wysiwyg>
<settings>
<wysiwyg>true</wysiwyg>
</settings>
</wysiwyg>
</formElements>
</field>

Resources