The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [class]

A template for creating new objects that describes the common state(s) and behavior(s). NOT TO BE CONFUSED WITH CSS CLASSES. Use [css] instead.

Filter by
Sorted by
Tagged with
19
votes
2answers
5k views

What is __construct and _construct in magento2?

In Magento 2, most of classes have these two constructs (__construct and _construct) methods. What is the difference between them?
15
votes
1answer
8k views

DI & Extending a Block on Magento 2

I seem to be struggling to grasp Magento 2 dependency injection with blocks, every time I try to extend a block that isn't \Magento\Framework\View\Element\Template I end up with errors. I want to ...
9
votes
3answers
549 views

What (type of) classes are generated in Magento 2?

In Magento 2 there are a set of classes that are generated automatically and stored in var/generation and they are used in the core code. While trying to create a custom module by replicating one of ...
7
votes
1answer
7k views

Usage of getsingleton() and getModel()

Is there a set of guidelines that I can go by to decide when I should use mage::getModel() and mage::getSingleton() From what I can tell it seems as though getSingleton either gets an existing ...
7
votes
2answers
565 views

Where helper aliases of some of core modules defined?

This confuses me a bit. I wonder why I didn't notice it before. When I look for helper definition of Mage_Sales core module, it surprised me that, I couldn't find helper defintion there. This confuses ...
6
votes
2answers
5k views

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

when I do compile I do get the following error which is referencing my custom module Blocks, class Incorrect dependency in class ... \Magento\Framework\Registry already exists in context ...
6
votes
2answers
155 views

Proper way to call a model constant in Magento 1

I have the class below: class Company_Module_Model_Somemodel extends Mage_Core_Model_Abstract { const SOME_CONST = 'constant_text'; } What is the proper and correct way to call the constant ...
6
votes
1answer
5k views

Magento 2: Overriding Block class – not generating output

I'm trying to override the module-catalog/Block/Product/View/Options/Type/Select.php class with a new version which includes a few other bits of custom php (adding HTML classes and IDs to the ...
4
votes
7answers
8k views

Magento 2 custom layout add body class

I create custom page layout. In admin area select this layout: Amin -> Products -> Categories -> MyCategory -> Design -> Layout Q: How add css class to body tag? My file: app/design/frontend/...
4
votes
2answers
3k views

What does Mage:: correspond to?

I just had one of those moments where I realized I don't understand something. What does the Mage part in say Mage::helper or Mage::log represent? There is no class Mage{ .. } in Magento. Thanks ...
4
votes
2answers
1k views

Rewrite single method using local class

I need to override Varien class because I need to change one method. app/code/core/Varien/Data/Collection/Db.php From what I know, the only way is to put it inside local folder. app/code/local/...
4
votes
1answer
79 views

Magento 2: Add active class on selected shipping method

I want to add active class When I select a shipping method on the checkout page. For example: If I select free shipping then active class should be added on radio button which is free shipping. ...
4
votes
0answers
163 views

Problem with block override in Magento 2

Note: Before marking the question as duplicate or off-topic, please read the question carefully. Scenario: I have to show custom column in the admin grid of a custom extension. So I used override ...
3
votes
1answer
5k views

Where are class constructor parameters defined in Magento2?

If you see AbstractExpress class for PayPal payment method, you could see: /** * @param \Magento\Framework\App\Action\Context $context * @param \Magento\Customer\Model\Session $customerSession * @...
3
votes
1answer
6k views

Want to rewrite core Helper class (Mage::helper('core'))

i want rewrite magento helper core class Mage_Core_Helper_Data. I have try below code, but it is not working <?xml version="1.0" ?> <config> <global> ... &...
3
votes
1answer
2k views

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

I am using magento 2.1.7. I want to add one class in country select box on checkout page shipping address. If anyone knows please help to add class.
3
votes
2answers
675 views

Change $this to different block in related.phtml

I am working in related.phtml in app/design/frontend/[package]/default/template/catalog/product/list/. Here there is a foreach loop: <?php foreach($this->getItems() as $_item): ?> which loops ...
3
votes
3answers
156 views

Name for Magento 'pseudo' constructor

I understand why and how Magento uses the secondary/pseudo constructor e.g. the constructor that begins with a single underscore. Is there a specific name for this method: pseudo constructor ...
3
votes
2answers
3k views

Magento collection classes confusion

I confused by following collection classes $orders = Mage::getResourceModel('sales/order_item_collection'); $orders = Mage::getResourceModel('sales/order'); $orders = Mage::getResourceModel('sales/...
3
votes
1answer
3k views

Magento 2 Class does not exist error

I am trying to create a custom grid in admin, based on customer collection using ui-component. The problem that I am facing is that I am getting Class does not exist error and magento does not tell ...
3
votes
2answers
170 views

Why separately placing methods in interface instead of abstract class?

I want to delete Interface Mage_Shipping_Model_Carrier_Interface. interface Mage_Shipping_Model_Carrier_Interface { /** * Check if carrier has shipping tracking option available * ...
3
votes
1answer
1k views

How are magento lib files loaded - Sage lib class not being accessed by model

On a mage site using sagepay, inside the Sagepaysuite model there is a call to a class file: Ebizmarts/SagePaySuite/Model/Api/Payment.php $xml = new Ebizmarts_Simplexml_Element('<customer />...
3
votes
1answer
459 views

Magento 2: How to validate the cart rules?

I need to develop a function in the cart rules. Basically it is to check the amount that is added in the cart and apply a fixed price to the product. I have in mind how to apply the logic. But I ...
3
votes
1answer
862 views

Magento2 rewrite: product resource collection class does not effect on functions

I have rewrite catalog product resource collection Magento\Catalog\Model\ResourceModel\Product\Collection. Class override successfully but functions override is not working. Suppose, i want ...
3
votes
0answers
108 views

Configurable Drop-down options in related products (related.phtml) - error Call to a member function getSortedChildren() on a non-object [duplicate]

I am trying to give the related products on each product page, the ability to show the drop-down options of configurable products; so that the user can select options and add to basket without ...
2
votes
3answers
19k views

How do you change the number of product columns?

I want to change the number of products that are shown. But I don't want to hard code this into the theme. This: <ul class=​"products-grid products-grid--max-4-col first last odd">​…​</ul&...
2
votes
2answers
2k views

Update Const template at Magento 2 Class

I need to update a template defined in a Constant at Configurable Class(Magento/Swatches/Block/Product/Renderer/Configurable.php). I tried with a Plugin, but how the function which gets the constant ...
2
votes
2answers
2k views

How to remove body class from specific page?

I'm using an extension that adds a class name vnecoms-cp to the body of adminhtml pages. This is then used to style the pages using css. My problem is, this affects 1 specific page in a negative way. ...
2
votes
2answers
2k views

Calling Grandparent Class in magento class inheritance

UPDATE: This issue was finally tracked down as a class inheritance issue. The original code in class becomes invalid, due to fact that the class inheritance has been updated, and the 'parent::parent' ...
2
votes
1answer
1k views

Dynamically instanciate class with arguments

I am actually trying to instanciate a class dynamically with these arguments. Here is the code I use in class A: /** @var string $source */ $source = '\Foo\Bar\My\Class'; // Dynamic value that I ...
2
votes
1answer
7k views

Magento 2 class does not exist error backend

I'm trying to add another field to the customer create form. The following code troughs an error in the backend. The error is: Class Magento\Customer\Model\Metadata\Form\String does not exist or ...
2
votes
1answer
736 views

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

I've created a little function for one of my template (.phtml) files which I'd like to re-use in a few other template files. All the function does is concatenate a couple of strings together and trim ...
2
votes
1answer
16 views

Conceptually speaking, management interfaces are used for what?

For example Magento\Catalog\Api\ProductManagementInterface Magento\Catalog\Api\ProductLinkManagementInterface They are used for very specific tasks?
2
votes
3answers
420 views

Class 'Ebizmarts_MailChimp_Helper_Data' not found

When I extracted the mailchimp extension in root folder. I came across this error Class 'Ebizmarts_MailChimp_Helper_Data' not found in /home/occasion/public_html/occasionwearforkids.com.au/app/...
2
votes
1answer
397 views

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

The Magento\Checkout\Model\Cart class was marked as deprecated a long time ago (since 2.1 ver.). What should I use instead of it to work with a customers cart? I know that I can work directly with a ...
2
votes
2answers
2k views

lib class not found

I am loading a custom class from the lib folder and I'm getting the following error: Fatal error: Class 'NameSpace_MyClass' not found in /dir/to/site/app/code/local/NameSpace/Module/controllers/...
2
votes
4answers
2k views

How to call Mage_Page_Block_Html_Pager class in list.phtml

I am wanting to include a larger than normal 'next page' type button in the list.phtml template whilst still having the normal pagination from pager.phtml The function I'm wanting to use is found in ...
2
votes
3answers
10k views

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

Please help me guys to fix it : Fatal error: Class 'Mage_Parcelamento_Helper_Data' not found in C:\wamp64\www\magento\app\Mage.php on line 547 Error log Warning: include(Mage\Parcelamento\...
2
votes
1answer
2k views

Magento 2: Update the CSS class name of #maincontent

Is there a way for me to remove the class name 'page-main' from the 'maincontent' div and add a new class name?
2
votes
1answer
132 views

Magento Top Links Login class disappears randomly!

So I have slightly modified the customer.xml file to add classes to the top links, so I could add font awesome icons to them. The issue I am having is for some reason the login class disappears if I ...
2
votes
1answer
223 views

Class inheritance question in magento (google analytics)

In a custom module I'm inserting universal analytics so I have to change a few functions from Ga.php file In Ga.php there is: class Mage_GoogleAnalytics_Block_Ga extends Mage_Core_Block_Template { //...
2
votes
1answer
46 views

How to pass data from UI Form to PHP Class

I have created a form using UI component, This form has a select dropdown which displays option related to current entity id if form is in edit mode and all options if a new entity is being added by ...
2
votes
1answer
883 views

500 Internal Server Error in store page

I recently updated my Magento from 1.4 to 1.9 and faced with the issue: it gives HTTP-header 500 Internal Server Error, but all the content is still loading (so just instead 200 OK I have 500 Internal ...
2
votes
1answer
179 views

Identical Code in Block Class Overload has Different Results

The following code samples are long, but here is the issue: If I create a custom file /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php and add two new columns to the product grid, it ...
2
votes
1answer
1k views

Fatal error: Class 'Altima_Lookbook_Helper_Data' not found in /home/offerbea/public_html/app/Mage.php on line 547

I have installed it from magento connect, and now in my back-end it displayed as it. Please somebody help me how to fix it. I gues it causing by i was put the compliation mode in on. Thank you
2
votes
0answers
26 views

Add css class to item on checkout xml

how can i add a css class eg.: class="myClass" to an item on checkout xml? for example <item name="after-place-agreements" xsi:type="array"> <item name="component" xsi:type="string">...
2
votes
0answers
27 views

Can Magento 2 Proxies be used to handle non existing class

I am building an extension which is dependent on multiple third party payment gateways. So I have created a special service class which gives the respective payment gateway class object depending on ...
2
votes
1answer
105 views

Difference between declare class in : “__construct” and in the top of file with “use” [duplicate]

Anyone have idea about declare class in __construct and declare class in top of file with use. Exemple: use Magento\Store\Model\StoreManagerInterface; and public function __construct( \...
2
votes
1answer
2k views

Extending an abstract block class

I'm modifying getCountryHtmlSelect() through a custom class that extends another core class that extends Mage_Checkout_Block_Onepage_Abstract. Here's the class with the customized code: local/...
2
votes
0answers
128 views

How to add a class to an attribute group? [closed]

hi this is the js code where magento generates new groups in admin: addGroup : function() { var group_name = prompt("<?php echo Mage::helper('catalog')->__('Please ...