Add subtitle to category list magento 2 - php

For my magento2 store I want to have a subtitle right beneath the Title the product.
Right now I have it working for the "product overview" with the next code:
I added this code to: catalog_product_view.xml
<referenceBlock name="category.product.addto">
<block class="" name="category.subtitle" template="product/view/subtitle.phtml" />
</referenceBlock>
I created a new subtitle.phtml with the next code in it:
<h3><?php /* #escapeNotVerified */ echo $block->getProduct()->getResource()->getAttribute('subtitle1')->getFrontend()->getValue($block->getProduct()); ?></h3>
But i do not know how to get it working in the category list.
Is there someone who can help me with it?
UPDATE:
the attribute i created has the right settings (used in product listing is enabled)
the code i am using is:
<referenceBlock name="product-item-details"> <block class="Magento\Framework\View\Element\Template" name="category.subtitle" template="product/view/subtitle.phtml" /> </referenceBlock>
i placed this code in "catalog_product_view.xml
Im notting getting the subtitle right beneath my title in the grid view / category view.
i think there must be something wrong with the code from the reference block but i cannot figure out where the problem is .
thanks! regards Mark

How is your attribute setuped. Check the attributes settings because attributes can be hidden.
Your code should work with following:
Make sure “Visible on Product View Page on Front-end” and “Used in Product Listing” options under storefront Properties are set to Yes.
This is a quick guess because your code should work, so please check your settings of custom attribute. If it still doesn't show up can you please provide more details

Related

How do we add the 'Inclusive of all taxes' label after the original price of the product on the product page in magento2?

Please help me how I can display the label 'Inclusive of all taxes' after the original product price on the product page in the magento2 platform?
And also let me know the file structure where I can easily add the HTML code to show the same.
see the screenshot for your reference: https://prnt.sc/10hqx9e
<div class="product-info-price"><div class="price-box price-final_price" data-role="" data-product-id="" data-price-box=""><span class="label-taxes"><label>Inclusive of all taxes</label></span></div></div>
The above code is just a dummy code but I have used the default div structure of magneto2 of product pages.
Please help!
Thanks in Advance.
First If you want to display custom text only in product view page, then create catalog_product_view.xml in your custom theme on path app/design/frontend/Your-theme/theme/Magento_Catalog/layout/catalog_product_view.xml
add this Code
<referenceContainer name="product.info.main">
<block class="Magento\Framework\View\Element\Template" name="custom.text" template="Magento_Catalog::view/customtext.phtml" after="product.info.price"/>
</referenceContainer>
Now create customtext.phtml file on path app/design/frontend/Your-theme/theme/Magento_Catalog/templates/view/customtext.phtml
Add below code
<div class="product-info-price">
<div class="price-box price-final_price">
<span class="label-taxes">
<label><?php echo __("Inclusive of all taxes") ?></label>
</span>
</div>
</div>
Don't forget to clear cache:)

Magento 2.0 Custom Module - Adding custom tab with new fields in Product Form

I have successfuly made a custom tab with custom fields inside it following this tutorial: datasheat
However, I need the implementation to be on my own "module". Does any of you know how the catalog_product_new.xml and Tabs.php be implemented if ever I move them onto my own module directory? Sorry this is my first ever post and I am not sure if I should copy paste the long codes in my post but I'll do you needed.
THis is my first time to code in Magento as I do Opencart stuff, but was unfortunately tasked with porting an OC plugin to Magento.
Thanks guys!!!!
Namespace Name: Test
Module Name: ProductTabs
First go to the admin panel of your Magento store and then navigate to Stores -> Product. Click on Add New Attribute and create new Attribute. (Set Attribute label DEMO and Attribute code demo)
Now go to Stores -> Attribute Set and Add Attribute Set.
Now click on your Attribute Set and dragged unassigned Attribute (which you have created in first step) to Product Details and click Save.
Now go to your product edit page in admin panel and change the attribute name and template name which you have created in first and second step.
In app/code/Test/ProductTabs/etc/module.xml paste this code.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Test_ProductTabs" setup_version="1.0.0"></module>
</config>
In app/code/Test/ProductTabs/registration.php, paste this code.
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Test_ProductTabs',
__DIR__
);
In app/code/Test/ProductTabs/view/frontend/layout/catalog_product_view.xml, paste this code.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_config uration.xsd">
<body>
<referenceBlock name="product.info.details">
<block class="Magento\Catalog\Block\Product\View" name="demo.tab" template="Test_ProductTabs::custom_tab.phtml" group="detailed_info" >
<arguments>
<argument translate="true" name="title" xsi:type="string">Custom Tab</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Now in app/code/Test/ProductTabs/view/frontend/templates/custom_tab.phtml, paste this code.
<?php
$product = $block->getProduct();
?>
<h1 style="color: #00aeed"><?php echo $product->getData('demo'); ?></h1>
Now lauch your product page.

Show / Hide product tab using if statement in local.xml Magento 1.9 CE

I'm fairly new to magento, using CE 1.9.
I know how to remove / add tabs on the product page via local.xml
However I'm trying to hide/show a tab based on the value of an attribute of the product.
I have created a custom tab successfully. Additionally the customTab.phtml file I created I was able to get an if statement to work successfully... sort of...
Here is my code inside the phtml file:
<?php
$staticBlockId = 'block_product_tab2';
$product = Mage::registry('current_product'); ?>
<?php if($product->getRepairservice()): ?>
<div class="std"><?php echo $this->getLayout()->createBlock('cms/block')->setBlockId($staticBlockId)->toHtml(); ?></div>
<?php endif; ?>
This will successfully hide or show "content" of the tab based on the boolean value of the attribute. However it still is showing the tab, it's just empty.
So I'm thinking I need to go to where it's created in local.xml but I'm not sure how to structure the if statement or get access to the attribute. Any help would be appreciated.
I think the most clear way of doing this is by creating your own layout handle, see: http://inchoo.net/magento/custom-layout-update-handles/. There you've to check if you're on a product page and then check your getRepairservice(), for example:
// Inside the controllerActionLayoutLoadBefore() function of Inchoo's example
$layout = $observer->getEvent()->getLayout();
$product = Mage::registry('current_product');
if($product && $product->getRepairservice())
{
$layout->getUpdate()->addHandle('REPAIR_SERVICE')
}
After that you can add your tab nicely with XML.
<REPAIR_SERVICE>
<reference name="product.info">
<block type="catalog/product_view_description" name="product.new.tab" as="new.tab" template="catalog/product/view/mynewcustomtab.phtml">
<action method="addToParentGroup"><group>detailed_info</group></action>
<action method="setTitle" translate="value"><value>Custom Tab</value></action>
</block>
</reference>
</REPAIR_SERVICE>

Hide Shopping Cart on Top Menu When it is empty

Is there a way to hide the Shopping Cart on Top Menu when it's empty? I believe it is on Links.php file but I don't know what code to add. Also, "Links.php" is a Core file, I am thinking on creating a new module on Local for it. Would it work? Thanks.
Hide the shopping cart side bar when it is empty:
1. Open: app/design/frontend/default/<your template>/template/checkout/cart/sidebar.phtml
2. Go to line 32 Look for
<div class="box base-mini mini-cart">
3. Add these lines right before that opening div tag
<?php $_cartQty = $this->getSummaryCount() ?>
<?php if ($_cartQty >0): ?>
4.Add this line to the bottom of the file
The shopping cart will only show if user adds items to their shopping cart.
Or use these plugin... it's a free plugin for hiding when it is
empty..
Xogenics Hide Cart for Magneto
For hiding in header menu use this
Remove My Cart and Checkout links from the header menu.The code for
these links is located in the checkout.xml file:
In Magento, on your ecommerce site may be you do not want to show MyCart or Checkout links.Follow the steps below to remove the link.
1. Copy the file checkout.xml from app/design/frontend/base/default/layout to app/design/frontend/YOUR_PACKAGE/YOUR_THEME/layout or app/design/frontend/default/YOUR_THEME/layout
2. Edit the checkout.xml copied to the app/design/frontend/YOUR_PACKAGE/YOUR_THEME/layout folder or app/design/frontend/default/YOUR_THEME/layout folder
3. Look for the following Code snippet
<reference name="top.links">
<block type="checkout/links" name="checkout_cart_link">
<action method="addCartLink"></action>
<action method="addCheckoutLink"></action>
</block>
</reference>
4. Comment the following Lines
4.1 Comment the following Line to Remove My Cart Link from header
<!--<action method="addCartLink"></action>-->
4.2 Comment the following Line to Remove Checkout Link from header
<!--<action method="addCheckoutLink"></action>-->
5. Refresh the Magento Cache and Website Page to see the changes
$(document).ready(function(){
$(".top-car").hide();
});
First check if there's quantity in the cart ofcourse with something like:
$qty = $this->helper('checkout/cart')->getSummaryCount()
Hope this helps you

change my account menu position in magento

I have created custom module which added link in Left navigation menu of My Account Page. Every things is handle By modules Layout.xml.
But My Module link is appeared at Last in position i.e after News letter Subscription. I want to add this after "My Order" Menu.
How can I do this. Please help me.
Thanks
Pravin
In the XML file you can set your block to come before or after another block.
In the layout XML file add the following attribute to the block:
before="name_of_block"
Or:
after="name_of_block"
So your line would look something like this:
<block type="some/type" before="some_other_block_name" template="some/path/to/template.phtml" />
If you want it to come before any other block (or after every other block) use the following:
before="-"
Or:
after="-"

Categories