Questions tagged [model]

Models contain most of the business logic in Magento modules

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

How to delete the content of a table

I'm able to fetch the single items, or the whole tables via the $modelFactory->create()->load(ID) or $modelFactory->create()->getCollection() Using the $modelFactory, how can I delete all ...
2
votes
0answers
168 views

Magento2: How can I set to a model in “specificcountry” on config.xml file?

I want to set default values with a model from declared class in system.xml. The result of the model is extracted from the database, from a custom table and the result looks like this: AF,AL,DE,BE,FR ...
0
votes
2answers
94 views

How can I call logger on model

I want to call logger by objectManager on Model But I don't know how to call logger object. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $logger = $objectManager->get('...
0
votes
2answers
353 views

Magento2 Model not loading complete data using Factory

Below is my construct function of controller - public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Vendor\...
2
votes
1answer
82 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 ...
3
votes
1answer
94 views

How to connect Model / Data Model

Vendor/ModuleName/Model/TestModel.php Vendor/ModuleName/Model/Data/TestModel.php Vendor/ModuleName/Model/TestModelRepository.php Interfaces are already created. The Data Model contains for eg. these ...
2
votes
3answers
268 views

magento 2 : model in custom module

i already have a table in database also created model files and all works fine so now added another table successfully so what changes i need to do with model files i mean in model resourcemodel and ...
12
votes
3answers
47k views

Get Option Value by Id of Attribute in Magento

How can Magento find an attribute value by a given attribute label or a given attribute id?
2
votes
0answers
105 views

Check if 2 dates already exist in collection filtering

i have a custom collection which has database column start_at and end_at in Y-m-d format , i try to do some validation before inserting to database, one of them is make sure the period between ...
0
votes
2answers
151 views

Create simple hello world model

I developed a extension. Now I try to add a model which has a function that returns "hello world". I tried it like seen here. app/code/local/Fekete/Newsletter2Go/etc/config.xml ... <global> ...
2
votes
1answer
438 views

My first Hello World from a module and model and I can't load the model

This is my first module. The module loads and the index controller executes. I am failing loading my first "hello world" model. I cleared the cache and turned off caching. I included all the code ...
1
vote
1answer
31 views

GridFactory getting generated into wrong location

I have a custom module with backend management. I have an observer on config save that uses the file upload to read submitted file to update the collection however this fails due to below; class \My\...
3
votes
4answers
573 views

Can not override Magento/Checkout/Model/DefaultConfigProvider.php file

I want to change a file in Magento\Checkout\Model\DefaultConfigProvider file I am trying to change data in function but I can not override funciton Where I am going to Wrong. I have Created a File ...
1
vote
0answers
59 views

Magento 2: Migration using models

I would like to migrate products from magento 1 to magento 2 using core models instead of the migration toolkit provided by magento. The reason is that the products need A LOT of modification in the ...
4
votes
3answers
656 views

How to get config data from model in magento 2?

I have code file in model.How to get config data ? I have error with AbstractMethod and getConfigData() in PHP storm .ERROR Class AbstractMethod is deprecated Method getConfigData is ...
0
votes
1answer
163 views

SKU Report for null attribute values

I am getting all product sku's that does not have a attribute value 'image_link'. I have written this code in magento : $products = Mage::getModel('catalog/product') ->getCollection() ->...
2
votes
1answer
783 views

Custom Module data save gives array to string exception in Magento 2

I've made a custom module with a ui component in the admin. It's a grid that is filled with block data. When adding a block, and saving it in Controller/Adminhtml/Content/Save.php, exception "Array ...
0
votes
1answer
159 views

Magento 1.9 add attribute to Credit memo item

I am trying to add a quantity to return to stock data to the credit memo item. I have made 2 install scripts. One adds a column to the database <?php $installer = $this; $installer->...
5
votes
2answers
1k views

Why Magento addAttributeToSelect Never Works

Ok I have faced this issue in magento 1 too and I am not able to understand why addAttributeToSelect(*) never works. When I call my product collection I want the collection will all the possible ...
0
votes
3answers
2k views

Creating a module with custom database table, cannot save

I have developed a custom module that also has a custom database table. However, I cannot insert records since I am presented with the following error: Fatal error: Call to a member function ...
0
votes
1answer
126 views

Magento 2 model for adding images to media folder (not for products)?

When not working with products, is there a magento2 model/function that can be used for reading/writing images to the media folder? (like addImageToMediaGallery / getMediaGalleryProcessor()->...
0
votes
1answer
38 views

After Changing primary key of custom modules' model , does not saves data in db

I have made custom module for that I have to change tables primary key due to some reasons.I have updated it in Model\Resource\Modelclass.php file , flush cache including "Flush Cache Storage" of ...
1
vote
1answer
63 views

Module with cron job to fetch all products where custom attribute is true

I am brand new to Magento module development, and I need some help getting started. My goal is relatively simple: I'd like to create a module which fetches all products with a custom attribute '...
0
votes
0answers
18 views

Create a detail listing page of a record on admin side

I want to create a page like an edit page of an model where user cannot change any content. He can only see the content. How can i achieve it?
3
votes
2answers
439 views

load customer object update issue in magento 2?

I have used below code in my controller use Magento\Customer\Api\Data\CustomerInterfaceFactory; class editPost extends \Magento\Framework\App\Action\Action { protected $_customer; protected $...
2
votes
2answers
1k views

addAttributeToSelect Call to undefined method M2

I have two custom modules and am calling one collectionfactory in other module and getting ` Call to undefined method addAttributeToSelect Collection file look like class Collection extends \...
1
vote
3answers
5k views

Magento 2 How to get only one field data in collection

I want to get only one field data in my custom module collection. For ex: getting following data in collection: Array ( [0] => Array ( [banner_id] => 1 [banner_title] =...
2
votes
1answer
325 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 ...
3
votes
2answers
445 views

Root Catalog has a negative children count, how it is possible?

I've been playing with the Catalog classes for a while, deleting and importing root categories, subcategories, stores and store groups, and I just discovered that every time I delete a root category ...
0
votes
1answer
657 views

Magetno 2 custom module how to Update DB Table row with model

How do I update instead of inserting new row on save using model My code: $question = $this->_objectManager->create('Vendor\HelloWorld\Model\Question'); $question->setTitle('Simple Question'...
1
vote
1answer
544 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
128 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
651 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 ...
1
vote
4answers
19k views

Magento Call a function of Model in Controller

I have a function abc in model . i want to call that function abc in controller. i am new to magento and dnt have any idea regarding this. Can any body tell me how to do this
1
vote
1answer
824 views

Magento 2: How to get shipment collection on phtml?

I'm trying to get the shippment collection on popup.pthml, but not able to get. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $shipmentCollection = $objectManager->get('...
3
votes
3answers
2k 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
283 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
896 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
2k 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
256 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 ...
0
votes
1answer
388 views

Extends another model from another module issue in Magento 1

This is the model which I want to overwrite: class Dotdigitalgroup_Email_Model_Newsletter_Sub extends Mage_Newsletter_Model_Subscriber { public function sendConfirmationSuccessEmail() { ...
2
votes
0answers
107 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
92 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 ...
0
votes
1answer
667 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?
0
votes
1answer
3k views

how to call resource model methods in Block.php files or phtml files

I could not call resource model function display records in block/dotnet.php
1
vote
2answers
2k 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
76 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?
3
votes
1answer
3k views

Product grid says “The resource isn't set” when adding __construct to model class

I have a model class that I'm trying to inject a ScopeConfigInterface into, and after compiling di, the product grid says "The resource isn't set." My class extends \Magento\Framework\Model\...
0
votes
1answer
87 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. ...
4
votes
1answer
675 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 2 3
4
5
15