Questions tagged [model]

Models contain most of the business logic in Magento modules

Filter by
Sorted by
Tagged with
1
vote
1answer
849 views

Magento 2 - Not able to override CouponManagement Model

I am trying to override Magento\Quote\Model\CouponManagement core vendor file. What I am trying to achieve is change the default error message when the wrong coupon code is added. My di.xml <?...
0
votes
0answers
224 views

How to override ProductRepository model file in Magento2?

I need to override processMediaGallery method from \vendor\magento\module-catalog\Model\ProductRepository.php I used below code in my custom module etc/di.xml. < preference for="\Magento\...
4
votes
1answer
820 views

One to many relationship in M2

I am working on a module where I have to implement one to many relationship. I have one table for series with id and name field and one table series_product where I have id, series_id, product_id and ...
5
votes
5answers
17k views

Get quote item collection by using quote item id in Magento 2

I get the quote_item_id like this: $orderItems = $order->getAllItems(); foreach($orderItems as $orderItem){ $qouteItemId = $orderItem->getQuoteItemId(); } I need to load quote item ...
4
votes
3answers
4k views

Magento 2 addFieldToFilter equal today for datetime field

I have a model with field in datetime format, i want to filter the field with equal today date like this: $collections = $this->customFactory->create()->getCollection() ->...
1
vote
1answer
509 views

Magento 2 : injecting models, interfaces in constructor magento

I'm new to magento 2 and I'm trying to understand how exactly injections work in magento. I understand that injecting a model and interfaces is the right approach in magento 2. But for some reason ...
3
votes
1answer
1k views

Column value display wrong when export CSV in magento 2 admin UI component grid in magento 2

In my custom module admin UI component data grid there is a one column is named "Status" all data display perfectly. But my problem is when i export data then "Status" column value display 0 OR 1 ...
7
votes
1answer
4k views

I want to add my custom entity for export Magento 2

I want to export my custom entity from the admin like products, customers, etc... I have already created the code for the import for my custom entity and it is working fine. But now I want to add the ...
1
vote
1answer
363 views

Change to Production mode the Theme something error

Change to Production mode the Theme something error but developer mode is working , how can i do? please help! thank you! my command: php bin/magento deploy:mode:set production -s --skip-compilation ...
2
votes
1answer
969 views

I want to override model in the Magento 2

I want to override the Magento\Catalog\Model\Layer\Category\FilterableAttributeList model file. I have created the module. This is my di.xml file. <config xmlns:xsi="http://www.w3.org/2001/...
2
votes
0answers
189 views

Magento 2 plugin not working for CommonTaxCollector model

I want to overwrite mapItem function which is under the CommonTaxCollector class. So, I have done this but getting undefined error. Uncaught Error: Call to undefined method Magento\Tax\Api\Data\...
0
votes
2answers
108 views

Run magento extension model inside php script

I have a custom extension model like this: app/code/Namespace/Module/Model/Core.php <?php namespace Namespace\Module\Model; class Core { public function save($data){ .... } } I want to ...
3
votes
1answer
510 views

How to use _redirect() method in Magento 2 model file

Magento\Framework\App\Action Redirect method is defined in Magento controller interface /** * @var \Magento\Framework\App\Response\RedirectInterface */ protected $_redirect; So i am aware about ...
0
votes
1answer
738 views

Get Category with a custom attribute programmatically [closed]

How can I load a category with only the value of a custom attribute in a controller?
1
vote
2answers
5k views

how to get post data in Magento Model File - Magento 2x

I want to get POST data in Model file, Which is my custom file of AccountManagement /app/code/[Vendor]/[Module]/Model/AccountManagement.php Note: I can access it through $_POST, 'superglobal' ...
0
votes
1answer
81 views

Magento 2 - How to use the sales model in custom module

I've created a new module and I need the functionality from the Magento\Sales\Model\Order model to fetch a list of all orders. How can I use this model within my own module?
0
votes
1answer
126 views

Magento 1.9: Clear Magento Order Model

I'm trying to loop through a lot of order ids and fetching the order data but performing a clearInstance() on an order model variable doesn't seem to clear the data and I keep getting the same data. ...
1
vote
1answer
2k views

Magento 2 UI Component Image upload form in admin

controller Upload.php file. namespace Dac\Recipes\Controller\Adminhtml\Test; use Magento\Framework\Controller\ResultFactory; /** * Class Upload */ class Upload extends \Magento\Backend\App\Action ...
0
votes
2answers
47 views

To retrieve image from Module

$image="<img src="echo $this->getViewFileUrl('Inchoo_Helloworld::images/Phone.jpg' To know whether this code is correct to retrieve image from Module
4
votes
1answer
1k views

How to use collection factory model in Unit Test magento 2

I have a custom extension with model with structure like this in database: +----------------------------------+ |entity_id | customer_id | balance | +----------------------------------+ | 1 | ...
1
vote
0answers
52 views

Proper way of adding custom code to vendor module?

Is there a guide somewhere to overriding, extending or otherwise adding to the composer module sets that show up in /vendor/? I've run into a couple of scenarios where I just have to make a few small ...
0
votes
2answers
36 views

Magento updating database manually not working

I'm trying to manually update a column "term" in a table named "adyen_subscription" via a primary key "entity_id". I followed this in calling the table: Mage::getModel('namespace_modulename/tablename'...
1
vote
1answer
416 views

getModel return false after rewrite model

I was trying to rewrite product model. It's my config.xml <global> <models> <catalog> <rewrite> <product> ...
1
vote
2answers
3k views

Magento2 interface not found in Model class

I am new to Magento2. I am developing a payment method and I am getting the message: Fatal error: Interface 'Test\TestThesis\Model\Test\TestThesis\Api\Data\CryptocurrencyInterface' not found in C:...
1
vote
5answers
1k views

When to use Mage::getSingleton() in my custom module/Ext

theoretically i know about Mage::getSingleton() & differences b/w Mage::getSingleton() and Mage::getModel() but my question is that in my custom module when to use Mage::getSingleton(){Normally ...
0
votes
2answers
203 views

Magento2 : Can't Override Model File

I'm trying to override Magento\Bundle\Model\Product\Type for that i have add code indi.xml <preference for="Magento\Bundle\Model\Product\Type" type="Tecksky\Catalog\Model\Product\Type" /> ...
4
votes
1answer
6k views

Insert multiple rows without calling model save inside loop

Following code is working fine. $data = $this->_customDataSave->create(); $data->setUsername($this->getUsername()); $data->setFullname($this->getFullname()); $data->setEmail($...
3
votes
0answers
296 views

Add dynamic discount value in custom discount section html file Magento 2

I have created the module for the custom discount from https://www.mageplaza.com/how-add-custom-discount-magento-2.html. But there is a static value '$10'in customdiscount.html file.I want to add the ...
2
votes
1answer
101 views

Order collection not showing the order that have been invoiced

I try to retrieve all the order collections, but when I observe by looping the collections and print the order id, I notice the order that has been invoiced is not inside the collection. $collections ...
0
votes
0answers
211 views

Magento 2 rewrite not working

I need to override this class Magento\CatalogSearch\Model\ResourceModel\Fulltext Collection in my custom module. I have created di.xml in etc/frontend folder. and created the class and overridden ...
0
votes
1answer
699 views

Magento 2 Custom Module Insert Data Issue not working

I want to save custom data from Ajax Request in my database but it's not working and not saving any data. namespace/Getquote/controller/index <?php namespace namespace\Getquote\Controller\...
0
votes
1answer
120 views

Search by model to display categories

I'm trying to figure out the workflow for my redesign on Magento2. I would like a search by model feature ( year, make, model). But instead of having a disorganized list of products, I would like it ...
0
votes
1answer
18 views

Search catalog and list products from a single store

I am trying to filter the products of a category, I talk about the catalog search, I'm working in a multi-store and I need to filter only the products in the catalog of a store. I filter this in the ...
1
vote
1answer
41 views

Overwrite community model method issue in Magento 1

This is my config xml from my custom module: <models> <emailtester> <rewrite> <variable>Mynamespace_Mymodule_Model_Mailer_Variable</variable> ...
0
votes
1answer
40 views

How to write two model rewrites

Is this a valid rewrite? I can't seem to find the answer to: How to rewrite to models from the same Module? Do I need to separate the classes or can I put both under rewrites? This is not working so ...
1
vote
2answers
465 views

How write a Magento 2 standard Model class

I have create database table and want to create model,resource,Collection class and know that how to create. Have follow the blog https://www.softprodigy.com/store/article/create-model-and-...
2
votes
1answer
137 views

What is mage in magento ,,explain following and also list all these kind of function or model used in magento

And also explain following function: Mage::getModel('catalog/product'); load(); $category = Mage::getModel('catalog/category'); $category->load($categoryid); $collection = $category->...
0
votes
1answer
167 views

Including static blocks in a product description

I'm trying to follow this article by Marius so that I can use {{block}} calls in a product description, as many of our products have the same detailed product description, with some minor capacity ...
1
vote
1answer
4k views

Magento 2.2 <preference> not working to override a model class

I want to override a model call (Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector). We used preference to override a model call inside di.XML like magento 2.1.x But it is not working on Magento ...
1
vote
0answers
2k views

How to remove all associated quote objects of a customer completely

I found out I have some quote objects* that have some invalid data or item data that cause a huge lag every time a customer tries to add items to cart or view cart. *quote object: database records ...
1
vote
0answers
36 views

Associating two related models

So I'm creating a plugin wherein a customer can have grocery lists. I have two created models - GroceryList and GroceryListItem. A grocery list contains one or many grocery list items. I can fetch ...
0
votes
1answer
5k views

Convert model collection to json_encode

Currently I'm converting my collection data to json_encode like this: $collections = $this->modelFactory->create()->getCollection() ->addFieldToFilter('status','1'); $...
2
votes
0answers
55 views

Magento 2: Best practice create model class

First thing, I have a question on this topic Optimize load model memory Then I have some questions for the best way to create a Model to load or save data to Database? Could you please explain which ...
0
votes
1answer
887 views

Saved custom model doesn't returns it's id

I have a table with only 2 fields: id (primary key) and name. I've created a model for it, repository model. In my repository model, there is a method save. I'm trying to create a new record in my ...
10
votes
1answer
5k views

What are the differences between a Model and a Resource model?

What are the differences between a Model and a Resource model? Also what is a model and a resource model?
2
votes
1answer
82 views

Chain rewriting model in magento

I have installed a module in Magento 1.9 that rewrites a newsletter model from Magento Core. The config.xml file looks like this: <models> <onestepcheckout> <class>...
1
vote
1answer
579 views

Override Order PDF Abstract Model From Custom Module

I want to override magento function model which located at app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php Mage_Sales_Model_Order_Pdf_Abstract, how to override the insertOrder function at this ...
3
votes
0answers
90 views

Magento 2 : How to get top 10 repeated values in a column using CRUD instead of sql?

I want to get top 10 most repeated values in a column of my table, I can do so using sql but I need to do it using CRUD i.e using collections or model as magento coding standard doesn't allow naked ...
2
votes
1answer
570 views

Overriding model class causes constructor err in magento 2

I' tired to override \magento\module-configurable-product\Model\ConfigurableAttributeData.php with plugin. For this in my di.xml i have this code: <?xml version="1.0"?> <config xmlns:xsi="...
0
votes
2answers
2k views

Get customer address id from order

I have an observer after placed an order, and in that observer, I need to get the customer address id that customer used for shipment and load the customer Address Model that can save and update data. ...

1 2 3
4
5
16