Magento2 move block - magento2

I tried to replace the default discount block. Unfortunately, the block is always located on the bottom of the container. I can't move it to the default block position.
my xml -
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<remove name="checkout.cart.coupon"/>
<referenceContainer name="cart.discount">
<block class="{namespace}\Coupons\Block\Coupon" name="checkout.cart.coupon2" as="sadasdasd" template="test.phtml"/>
</referenceContainer>
<move element="cart.discount" destination="checkout.cart.container" before="checkout.cart.order.actions.gift_options" />
</body>
</page>
screen of result -

I think checkout.cart.order.actions.gift_options is not an immediate child of checkout.cart.container, so the 'before' clause is not finding position you want and is defaulting to 'last child' as a default behavior.

Related

Magento 2.x: add column to sales order history page (FO)

How we can add column to Sales order history content into customer account.
What are methods for add a column to sales_order_history page without editing view/frontend/templates/order/history.phtml?
You don't need to touch view/frontend/templates/order/history.phtml template file to add aditional column into customer sales order history page.
copy layout view/frontend/layout/sales_order_history.xml to your theme and add addtional column header to sales.order.history.extra.column.header block and render column data using sales.order.history.extra.container block.
You have all set now.
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<!-- This will add additional column header to order list -->
<referenceBlock name="sales.order.history.extra.column.header">
<block class="Magento\Framework\View\Element\Template" name="your.additional.column.header" template="Namespace_Module::columnheader.phtml"/>
</referenceBlock>
<!-- You can access current order using $this->getOrder() inside the template ">
<referenceBlock name="sales.order.history.extra.container">
<block class="Magento\Framework\View\Element\Template" name="your.additional.column.data" template="Namespace_Module::columndata.phtml"/>
</referenceBlock>
</body>
</page>
I have an easier and shorter solution(date column in the example):
1- Create in your theme/extension into layout folder-> sales_order_history.xml and copy:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="sales.order.history.extra.container" template="Magento_Sales::order/date/data.phtml"/>
</body>
</page>
2- Create the template for the data in templates/date/data.phtml and copy:
<?php
/* #var $block \Magento\Sales\Block\Order\History\Container */
?>
<td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date">
<?= $block->escapeHtml($block->getOrder()->getCreatedAt()) ?></td>

Remove Block Programmatically in Magento2

We are able to remove block in Magento1 with unsetBlock() method, but in Magento2 it is not working. So, please help how can remove block in Magento2 programmatically ?
Use unsetElement() method to remove block.
as like
$layout = $this->getLayout();
$block = $layout->getBlock('catalog.topnav'); // block name
$layout->unsetElement('catalog.topnav');
You need to try this way, for example, I am removing compare from the sidebar so I override default.xml to app/design/frontend/Your_Theme/theme_name/Magento_Catalog/layout
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
</body>
To Remove particular block from page, Open your custom layout xml and place the below code under body Tag
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body><referenceBlock name="Your_Block" remove="true"/>
</body>
</page>
Change Your_Block this one to your block name need to be remove
Ideally there are different ways to do this. The best way of doing it is using a layout file.
1) If you have build a module you can create a layout which is an xml file in app/code/Namespace/Your_Module/view/frontend/layout/frontname_controllername_controlleraction.xml and add the below code
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceBlock name="block_name" remove="true" />
</page>
2) If you have not created a custom module of your's you can simply write a custom xml in app/design/frontend/Custom_Theme/Theme_name/Module_Name/layout and add the below code.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceBlock name="block_name" remove="true" />
</page>

How to move topmenu inside header wrapper in magento2?

How to move topmenu inside header wrapper reference
[magentoroot]vendor/magento/module-theme/view/frontend/layout/default.xml
I want to move catalog.topnav inside header-wrapper
<referenceContainer name="page.top">
<block class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="html/topmenu.phtml" ttl="3600"/>
</referenceContainer>
<referenceContainer name="header-wrapper">
</referenceContainer>
Thanks
Add Following code in [magentoroot]vendor/magento/module-theme/view/frontend/layout/default.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="catalog.topnav" destination="header-wrapper" after="logo"/>
</body>
</page>
To get this to work, I had to move the whole navigation.sections block. Otherwise the menu would look broken with mobile resolutions. I'm working with Magento 2.1.1 and my theme inherits from blank.
In /app/design/frontend/<Vendor>/<theme>/Magento_Theme/layout/default.xml add this:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="navigation.sections" destination="header-wrapper" after="logo"/>
</body>
</page>
I suggest you create a structure in your
app/design/frontend/yourVendor/yourTheme/Magento_Theme/page_layout
Inside create your default.xml and paste this:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="catalog.topnav" destination="header-wrapper" after="logo"/>
</body>
</page>

Remove sku number from order email - magento

I am completely new to magento & using version 1.7. I want to remove sku number from the order email when customer place an order. After lot of R&D I noticed that, the template used is from app/design/frontend/base/default/template/email/order/items.phtml and product name, sku number, quantity and price comes from echo $this->getItemHtml($_item) this line. I am not exactly figure out, how should I remove sku number column from this single line?
Or is there any other way to do so?
Any help appreciated.
Thanks.
Let me explain you all process.
you can find order email template at app/locale/en_US/template/email/sales/order_new.html.
In this file you can find this line {{layout handle="sales_email_order_items" order=$order}} at Line no. 97
In this you can see handle is "sales_email_order_items" you can find this block in app\design\frontend\base\default\layout\sales.xml line no. 268.
<sales_email_order_items>
<block type="sales/order_email_items" name="items" template="email/order/items.phtml">
<action method="addItemRender"><type>default</type><block>sales/order_email_items_order_default</block><template>email/order/items/order/default.phtml</template></action>
<action method="addItemRender"><type>grouped</type><block>sales/order_email_items_order_grouped</block><template>email/order/items/order/default.phtml</template></action>
<block type="sales/order_totals" name="order_totals" template="sales/order/totals.phtml">
<action method="setLabelProperties"><value>colspan="3" align="right" style="padding:3px 9px"</value></action>
<action method="setValueProperties"><value>align="right" style="padding:3px 9px"</value></action>
<block type="tax/sales_order_tax" name="tax" template="tax/order/tax.phtml">
<action method="setIsPlaneMode"><value>1</value></action>
</block>
</block>
</block>
<block type="core/text_list" name="additional.product.info" />
In this block you can see the file path "email/order/items.phtml (app\design\frontend\base\default\template\email\order\items.phtml)"
In this file just comment this code
<th align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $this->__('Sku') ?></th> at line no. 33
And now on above block you can see another file path 'email\order\items\order\default.phtml(app\design\frontend\base\default\template\email\order\items\order\default.phtml)'
In this file just comment this code <td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;"><?php echo $this->htmlEscape($this->getSku($_item)) ?></td> at line no. 48.
Done.
In Magento 2.3 the "sales_email_order_renderers.xml" render the phtml.file which define the content for the items in the order email.
To remove the SKU, you can do the following steps:
create module (e.g. COMPANY/SAMPLE)
copy the "sales_email_order_renders.xml" from /vendor/magento/module-sales/view/frontend/layout/ to /app/code/COMPANY/SAMPLE/view/frontend/layout/
copy the "default.phtml" from /vendor/magento/module-sales/view/frontend/templates/email/items/order/ to /app/code/COMPANY/SAMPLE/view/frontend/templates/email/items/order/
update the "sales_email_order_renders.xml" in your module to render the "default.phtml" in your module (see following example)
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom">
<body>
<referenceBlock name="sales.email.order.renderers">
<block class="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" name="sales.email.order.renderers.default" as="default"
template="COMPANY_SAMPLE::email/items/order/default.phtml"/>
</referenceBlock>
</body>
Remove the SKU from the default.phtml
clear cache (php bin/magento cache:flush)

Magento how to display block outside of body tag

My code :
<reference name="before_body_end">
<block type="test/test" template="test/test.phtml" name="test-test" />
</reference>
when i change to
<reference name="after_body_end">
<block type="test/test" template="test/test.phtml" name="test-test" />
</reference>
then it is not working. please help
It doesn't work because you are referencing ...well...nothing. The block with name after_body_end does not exist.
I will explain how to add it but first I want to make it clear that I don't approve of adding html outside the body tag. This may cause issues on some browsers.
First you need to create the block with name after_body_end.
For this edit the file app/design/frontend/{interface}/{theme}/layout/page.xml and look for this :
<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
<label>Page Bottom</label>
</block>
Right under that add the following.
<block type="core/text_list" name="after_body_end" as="after_body_end" translate="label">
<label>Page Unde the body tag</label>
</block>
Now your block exists. You just have to add it to your page. For this edit the following files all located in app/design/frontend/{interface}/{theme}/template/page/:
1column.phtml
2columns-left.phtml
2columns-right.phtml
3columns.phtml
empty.phtml
popup.phtml
print.phtml
For all these files add under the </body> line this:
<?php echo $this->getChildHtml('after_body_end') ?>
Clear the cache and enjoy.