Questions tagged [model]

Models contain most of the business logic in Magento modules

Filter by
Sorted by
Tagged with
0
votes
1answer
1k views

Magento 2: Override product image JPG quality

Magento 2.2.1 with custom theme which inherits from Magento/blank. Attempting to fix the JPG compression for product images. I know, based on this solution, that I must extend the Image class found ...
0
votes
3answers
2k views

Correct way to save entries to database

I want to know, what is the correct way to implement CRUD operations in Magento 2? because I found a lot of examples but they use deprecated methods. I created a table ('quote reserved item') with ...
0
votes
0answers
24 views

Magento2 model save() method connected to db table structure in the install schema

I have a basic model - MyModel. The install schema for the table that the model is working with is $setup ->getConnection() ->newTable('my_table') ->addColumn( 'id', Table::...
0
votes
0answers
175 views

Magento 2 Cloning an order and modifying few things

All I'm asking here is the right direction on how to accomplish this, I'm basically trying to clone an order and modify the following: increment_id remove some line items on any line item: modify ...
2
votes
1answer
377 views

Magento 2 model error after updating on 2.2 verison

I have a CRUD module created on magento 2.1.6 version which was working ok untill i updated magento to version 2.2.1 Now when i compile my code i receive the following err: namespace\module\Model\...
0
votes
1answer
34 views

Two models cant find one of them

I have two models. The one is intializing the database, the other one i use to run a crontab. But i keep getting this error. Been playing around with it for a long time.. 2017-11-29T08:56:03+00:00 ...
1
vote
1answer
2k views

Magento 2.2 : getcollection is not working in the Block

My custom collection is not working in block file Helloworld.php <?php namespace New\MyModule\Block; use Magento\Framework\View\Element\Template\Context; use Magento\Framework\View\Element\...
2
votes
6answers
2k views

Magento 2: How to override the model?

How to override the model: vendor/magento/module-Customer/Model/Address/AbstractAddress.php For removing the validation of the last name. What can I do? I have already overriden this file using the ...
1
vote
1answer
48 views

Why are my Magento Model and Helper overrides not being run?

I'm trying to override the core Magento class Mage_Payment_Model_Info in order to solve an error. To be clear, the override I am talking about has been entirely written by me, and is extending a ...
4
votes
0answers
423 views

Override core model not working

I tried to override Magento core model which located in vendor/magento/module-catalog/Model/Layer.php, but it doesn't work at all, here's my code: app/code/Vendor/Module/etc/di.xml <preference ...
0
votes
2answers
1k views

Magento 2: quote_address moved to sales_order_address automatically?

I created two new columns in quote_address and sales_order_address as shown below. When I first land on checkout, I manually (in the database using Sequel Pro) added '999' into the quote_address ...
1
vote
2answers
538 views

How can I add a model to a custom module?

I'm extending custom module. One of the functions using dynamic models load, based on input param $reportProcessor = Mage::getSingleton( 'amreports_reports/' . $data['report_type'] ); If I ...
0
votes
0answers
16 views

Cannot display db table content in magento 2

This is my Controller/index.php <?php namespace Wallet\Payment\Controller\Index; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Wallet\Payment\Model\...
1
vote
2answers
307 views

Injecting model in controller not working

I have created a custom module and I want to inject my model in a constructor , but when I inject the model class then my controller stops working. namespace DD\Reservations\Controller\Url; use ...
1
vote
2answers
145 views

Fatal error: Class Abhi_Test_Model_Mysql4_Test contains 1 abstract method and must therefore be declared abstract or implement the remaining methods

I am getting Error in my model Fatal error: Class Abhi_Test_Model_Mysql4_Test contains 1 abstract method and must therefore be declared abstract or implement the remaining methods I have ...
-1
votes
2answers
127 views

Strange behaviour, loadByAttribute() works in local but not on production server [closed]

I have been pulling my hair on this for a couple of hours now. I have a local development server that is quite the copy of my Magento production store. I have been working locally for the past few ...
3
votes
1answer
128 views

Filter collection value from another value from another index

I create a custom attribute last_sync for customer custom attribute, i need to filter it if this attribute is null OR greater than created_at, right now i'm using code like this: $collections = Mage::...
0
votes
1answer
442 views

Unable to create Model tables on Magento2

I'm having a hard time making Magento2 create my model tables. This is my code so far: app\code\Werules\Chatbot\Model\IncomingMessages.php <?php namespace Werules\Chatbot\Model; use Magento\...
2
votes
1answer
888 views

Magento2. More information about the Entity Manager?

A part from this question Magento 2.1: using the entity manager that was asked and answered a year ago, a lot can change in an year, I can't seem to find anything about the Entity Manager. Should I ...
1
vote
1answer
59 views

Adding comments on request

I have two fields that I want to save as a comment in the request: the first one would be a reference point and the second would be the client's address type (residential or commercial), but the code ...
2
votes
1answer
2k views

How to set custom value to identity column of a table in Magento 2

I have a custom table with identity column id and text column otherColumn and I'm trying to add a row into the table with my custom value. $model->setOtherColumn($otherColumnValue)->save(); ...
12
votes
2answers
3k views

What and why is the proper way to load a model

I have quite a lot of experience with Magento but I realized that I don't understand which way of loading a model is the correct one and why. I've read everything that I could, about the topic but ...
3
votes
1answer
2k views

How to redirect from model

I want to do redirect after do function from model. I already tried both code below, both works redirect, but both return error too. Redirect 1 : $this->_redirect('*/*/addresses'); Redirect 2 : ...
1
vote
1answer
1k views

Magento 2: how to save a new instance of a custom model to the database (INSERT INTO instead of UPDATE)

I have created a model and a repository to save the model, the only functions I can find in the model->getResource() are save, load and delete. The save function always uses an UPDATE statement, so ...
3
votes
1answer
165 views

How to Override custom module Model in custom module Magento 2?

I have two Modules in app/code. Xyz_Xyz - Module that already exists. I can't change its file. Abc_Abc - Module that I creating to override Xyz_Xyz Model. The code I try is here. app/code/Abc/Abc/...
0
votes
1answer
138 views

How to properly extend Model in Magento 2?

Can someone show me how to properly extend this core Magento 2 model? vendor/magento/module-eav/Model/Entity/Attribute/AbstractAttribute.php
0
votes
1answer
317 views

Send the form fields data from payment method step in the checkout Page to a model without saving data in the database

I am a beginner to Magento, I want to send the form fields data from payment method step in the onepage checkout Page to a model without saving data in the database. Please find the below screenshot ...
0
votes
1answer
27 views

Magento check configurable item quntity using custom script

I have created soap api file.When user will update the quntity in cart then it will send request to myfile. In myfile i have set the code to check the requested quntity by user is available or not. ...
3
votes
1answer
820 views

Does arguments order in constructor matters?

I've noticed strange situation while creating class contructor (__construct). Here is my code: public function __construct( \Magento\Framework\Model\Context $context, \Magento\...
1
vote
0answers
60 views

Area Code not set when Model is used while using Upgrade Data Script

I have following code in UpgradeData.php protected $test; public function __construct( \Vendor\ModuleName\Model\Test $test ) { $this->test = $test; } public function ...
0
votes
1answer
687 views

Factory create model is not empty Magento 2

I use a custom model with it's own Factory. In my helper in the construct public function __construct( \Company\Module\Model\ResourceModel\Communication\CollectionFactory $communicationFactory ){ $...
1
vote
3answers
810 views

Foreach saving only the first item data

I have an array with a list of products, and I wanna save each of its attributes in a table. Its a list of 25 products, but it saves the first product's attributes 25 times. Here is my code: $promo = ...
1
vote
2answers
1k views

Get product by name in magento 1.9

How to get product by name? I have the name of the product in my code and iIwant to get product so I use this code : $model = Mage::getModel('catalog/product'); $product = $model->load('name-of-...
4
votes
2answers
10k views

Magento 2: What is a Resource Model and how can I use it?

In Magento 1, using a resource model we are getting collections of data: $products = Mage::getResourceModel('catalog/product_collection'); $category = Mage::getResourceModel('catalog/...
0
votes
1answer
68 views

Rewrite Model and Interface not working for newly added methods

I want to add country name in the address list of customers/me rest api. I have tried adding my changes in core files and I got the desired result. But when I try to rewrite, it doesn't work. Can ...
4
votes
1answer
224 views

Missing core resource models?

If you have a model, normally there should be a resource model and a resource collection too, but there are some core models where this is not the case. Example: Mage_Log_Model_Customer I tried to ...
0
votes
1answer
40 views

How to merge two getmodels

I want to merge two Model results in a variable to use it in the register. There's a way to do this? $commercial = Mage::getModel('thorleif/commercial')->load(1); $lcat = Mage::getModel('...
0
votes
1answer
2k views

How to call resource model function in controller in Mangeto 2

I have this resource model: <?php namespace namespace\module\Model\ResourceModel; class Post extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb { /** * Date model * *...
1
vote
2answers
5k views

How to submit a form from custom phtml in Magento 2

I have created a custom module and I have a custom phtml file with a form. I have also created a new table for this module. What I want to do is to insert the value of form in the DB But I actually ...
5
votes
1answer
286 views

Having some type of cron issue which is giving loads of the same report

It's very generic and I'm not really sure how to go about debugging this one. I probably get about 50 reports per day and it's all the same thing. a:3:{i:0;s:0:"";i:1;s:1210:"#0 /var/www/new/releases/...
3
votes
0answers
148 views

How to save/select a custom phml form in DB on Magento 2

I have created a custom module, and i have this phtml: <div class="container-club"> <h2>test<h2> <div class="club-img"> </div> <div class="club-...
0
votes
1answer
24 views

Add to cart only works after item second item and then both items show

I am trying to add a product to the cart through a controller, one the first attempt the basket is loaded, and says there is nothing in it. Once I reload the controller for a second time the item is ...
9
votes
2answers
11k views

Magento2 How to get region name by id?

Like in magento1 is is there any method to retrive region name by id. $regionModel = Mage::getModel('directory/region')->load('region_id'); $region = $regionModel->getName(); I checked ...
0
votes
1answer
812 views

Magento 2: Which are the conditions to use with addFieldToFilter? [closed]

What are the conditions that I can use with the addFieldToFilter? Thanks
0
votes
1answer
629 views

How do I display data from my table in the magento frontend?

I'd like to display data from the database table on my frontend screen, I'm trying this way: Teste/Cadastro/Block/Tabela.php <?php class Teste_Cadastro_Block extends Mage_Core_Block_Template { ...
0
votes
1answer
669 views

Which data to fill to show order in grid order row

I get some data and save it to the sales_flat_order and sales_flat_order_address . My issue is that I can't see my order created on the Magento grid order. Which data I have to fill or add to see my ...
0
votes
1answer
195 views

Can't using plugin for checkQty in StockStateProvider Magento 2

I am trying to using plugin to return checkQty() to true to skip validate this but I can't. I don't know why? public function aroundCheckQty($subject, callable $proceed, StockItemInterface $stockItem,...
0
votes
1answer
408 views

Struggling to rewrite SalesRule Model

I am trying to rewrite Mage_SalesRule_Model_Rule_Condition_Product_Subselect but it seems like my changes are not being picked. Below is what i've done trying to rewrite the Model. app/code/local/...
0
votes
1answer
604 views

Magento override the collect function of "Mage_Sales_Model_Quote_Address_Total_Tax" not working

Please look at the module files, which I have created in order to override the Mage_Sales_Model_Quote_Address_Total_Tax class's collect method. app\code\local\Vs\CustomTax\etc\config.xml: <?xml ...
2
votes
2answers
619 views

Magento 2 - Override Model Failed

I try to override the Customer model. I created code/Tc/Name/etc/di.xml, code/Tc/Name/Model/Customer/Customer.php . In di.xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...

1
3 4
5
6 7
16