Skip to main content
17 votes
Accepted

Magento 2 : add custom class on checkout page shipping address field

You can create plugin after Attribute merge method. Then you can modify checkout fields and add class to wrapper of country select box. In your module create MODULE/NAME/etc/di.xml <?xml version=...
K. Maliszewski's user avatar
13 votes

Magento 2 custom layout add body class

Page Layout XML As far as I'm aware this isn't possible out of the box via page layout XML, the existing implementation is done via PHP (checkout the addDefaultBodyClasses() function here); /** * Add ...
Ben Crook's user avatar
  • 15.7k
10 votes
Accepted

Proper way to call a model constant in Magento 1

echo Company_Module_Model_Somemodel::SOME_CONST; This one is way to go because Magento uses an autoloader and your class will be autoloaded by name For further detail please check the reference link ...
Muhammad Hasham's user avatar
9 votes

Fatal error: Cannot declare class , because the name is already in use

Replace namespace Vendor\Modulename\ResourceModel; With namespace Vendor\Modulename\Model\ResourceModel;
Gopi Nathan's user avatar
6 votes

Update Const template at Magento 2 Class

An alternative is to override it using dependency injection. Modify di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="...
TFS's user avatar
  • 4,339
6 votes
Accepted

Magento 2: Custom function – best place to put it?

You could put it in a helper class. Here's an example {module_directory}/Helper/StringHelper.php : <?php namespace Your\Module\Helper; use Magento\Framework\App\Helper\AbstractHelper; class ...
Aaron Allen's user avatar
  • 9,009
6 votes

Magento 2: Update the CSS class name of #maincontent

If you're interested, the answer is to use a referenceContainer in the XML file and add the new Class / ID names to the DIV / XML container. For example: <referenceContainer name="main.content" ...
MikeMason's user avatar
  • 1,357
6 votes

\Magento\Framework\Registry already exists in context object on compile

Just upload your code same as below, Keep $this->_coreRegistry = $context->getRegistry(); Full code, public function __construct( \Magento\Catalog\Block\Product\Context $context, \...
Rakesh Jesadiya's user avatar
6 votes
Accepted

Magento 2: Add active class on selected shipping method

You can add below JS code in your checkout page for your requirement. <script> require([ 'jquery' ], function ($) { $(document).ready(function () { $("body")....
Sumit's user avatar
  • 4,885
5 votes
Accepted

\Magento\Framework\Registry already exists in context object on compile

It says that \Magento\Catalog\Block\Product\Context already has \Magento\Framework\Registry in it. So instead of injecting both of them, you should inject only Context and get registry from it via \...
BuskaMuza's user avatar
  • 851
5 votes
Accepted

Magento 2: Overriding Block class – not generating output

First of all, we need to add Constructor injection method to our custom select class: (Edit: we don't need to add Constructor Injection, we need to add the sequence module) <?php namespace ...
Khoa TruongDinh's user avatar
5 votes

magento 2 - class error on backend after remover facebook-for-magento

Facebook\BusinessExtension\Model\Config\Source\Product\GoogleProductCategory could be used for custom attribute option source. Please search in eav_attribute table, especially in source_model column. ...
dudzio's user avatar
  • 620
4 votes
Accepted

Dynamically instanciate class with arguments

No, it's not a good practice to use the object manager. Use a factory instead. To get an instance of \Foo\Bar\My\Class you will need to use an instance of \Foo\Bar\My\ClassFactory that will be ...
Marius's user avatar
  • 198k
4 votes
Accepted

Magento 2 class does not exist error backend

Try to change this line: "input" => "string", to the: "input" => "text", because a component with name 'string' not exist. Then reinstall your module. Note: if on uninstall process ...
Siarhey Uchukhlebau's user avatar
4 votes

Magento 2 custom layout add body class

The only solution i've found is to add a class to the root container. This element will be displayed immediately after the body tag. I've used this code: <referenceContainer name="root" htmlTag="...
AndreaRivadossi's user avatar
3 votes

Magento 2 custom layout add body class

You can do this using a Observer: => Create the file : app/code/Myvendor/Mymodule/etc/frontend/event.xml with the following content: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
Prashant Patel's user avatar
3 votes

Magento 2 Class does not exist error

To create a custom grid in the admin panel is necessary add this code in /etc/di.xml to specify the collection. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
raumatbel's user avatar
  • 1,235
3 votes

What should we use instead of the Magento\Checkout\Model\Cart model?

As far as I know, there is no replacement as of now (Magento 2.2), the class was simply deprecated as an indication that the logic it handles will be refactored in the future. Just continue to use it ...
TiEul's user avatar
  • 1,297
3 votes

Magento 2: How to validate the cart rules?

You have to check Magento\SalesRule\Model\Validator. This is the main class from where validation is checking. Rules validator classes are exits at Magento\SalesRule\Model\Rule\Condition Rules ...
Amit Bera's user avatar
  • 77.6k
3 votes
Accepted

How to disable a single 3rd party module plugin class in Magento 2?

You can easily disable plugin. Try the following way: Following code add your di.xml in global scope that means location should be YourVendor/YourModule\etc\di.xml <type name="Magento\Framework\...
Sohel Rana's user avatar
  • 35.9k
3 votes

Conceptually speaking, management interfaces are used for what?

Management interfaces provide management functions that are not related to repositories. Learn more
Sohel Rana's user avatar
  • 35.9k
2 votes

Fatal error: Class Helper_Data' not found in app\Mage.php

There are two possibilities: 1) Either you declared your helper in the config.xml and you did not create it in the module NameSpace/NameModule/Helper/Data.php 2) Either you created it in the module ...
PЯINCƎ's user avatar
  • 11.7k
2 votes
Accepted

Include custom module block within phtml file?

My best guess is that your block is extending \Magento\Framework\App\Config\ScopeConfigInterface instead of \Magento\Framework\View\Element\Template. A block should always be a child of \Magento\...
Giel Berkers's user avatar
  • 12.3k
2 votes

How to load 1587 classes from single file in magento 2?

Dont create the files. Use composer install composer require travisghansen/netsuite-php-toolkit
Krishnan Daiva's user avatar
2 votes
Accepted

How to load 1587 classes from single file in magento 2?

I just done below thing in magento 2 and got what I wanted NSconfig.php NSPHPClient.php NetSuiteService.php I just put above core PHP files in app/code/MyNamespace/MyModule/Netsuit Then I ...
Bhavin Shah's user avatar
2 votes
Accepted

After upgrading Magento2.2.3 to Magento 2.2.5 getting Error

temando_shipping module is magento module powered by Temando check here magento devdocs Possible are to resolve your area Disable your module if it is not required. Contact to temando.com to report ...
Chirag Patel's user avatar
  • 6,136
2 votes

How to pass data from UI Form to PHP Class

Yes and no. The above suggestions will certainly work for retrieving parameters sent in the request, but does nothing for those of us who are looking to pass a parameter via the form XML (as the ...
Toby Crain's user avatar
2 votes

How to add custom class in Magento 2 Category page?

Check the relevant page layout, for example: /vendor/magento/module-theme/view/frontend/page_layout/2columns-left.xml This contains the column containers like: <referenceContainer name="...
zigojacko's user avatar
  • 1,754
2 votes

magento 2 - class error on backend after remover facebook-for-magento

problem solved after delete the attribuite. thanks
murugan's user avatar
  • 31
2 votes
Accepted

Magento 2: Add class to body from PHP

You can achieve your requirement by following steps: Step 1. Create registration.php under app/code/M2Expert/Classes/registration.php with below content: <?php \Magento\Framework\Component\...
Sukumar Gorai's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible