Questions tagged [model]

Models contain most of the business logic in Magento modules

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

Magento 2 - how to get custom model from custom module

In Magento 2, how can I get a custom model that is created in a custom module (not a Magento 2 native module)? I know I can use object manager for getting and creating, and I know how do this for ...
0
votes
2answers
1k views

Call to undefined method addFieldToFilter() in magento 2

I have a model,resource model,collection file shown below. app/code/Magge/Custom/Model/Categrory.php namespace Magge\Custom\Model; use Magento\Framework\Model\AbstractModel; class Categrory ...
0
votes
1answer
28 views

Magento 2 how to insert data in custom table?

I'm getting an error everytime I send my form in order to store data in a custom table I created. This is the error: {"0":"M\u00e9todo no v\u00e1lido Transom\\Emall\\Model\\StoreOwner::...
0
votes
3answers
41 views

Magento 2 - Check if record with certain value already exist in table before creating it

I created a new table company_shipping_quote. I am writing data into it like this: $quoteId = $quote->getId(); $html = $this->_generateNote($expressRule); $quoteModel = $this->...
0
votes
2answers
26 views

Magento 2 - Created new table and model - but model does not save!

I created a new table company_shipping_quote and new models by using https://mage2gen.com/. But how can I create a new object and save it so that it appears in the database? Models: Company/Shipping/...
0
votes
1answer
772 views

Error: Call to a member function beginTransaction()

I have created a custom module "adminform" with some custom fields when i try to save my form data it gives the error "Call to a member function beginTransaction()" I have the following form ...
0
votes
0answers
9 views

Magento 2 Async WebAPI: Data in topic must be of type mixed. array given

I'm using magento v2.3.4 and created a Magento 2 rest webapi function like this: /** * POST for create brands api * @param mixed $data * @return array */ public function create($data); I usually ...
0
votes
0answers
37 views

What is load method in magento 2 model how it's works with magento 2 model

i have doubt in Magento 2 Model when i use this in some places not getting brand value (Graphql Resolver) like cart details $product=$value['model']; $brand=$product->getAttributeText(self::...
4
votes
3answers
5k views

Truncate table using resource model in Magento 2

I have a custom module and i want to add remove every data including the increment id, using resource model in magento 2, i've read the solution in here but this is for magento 1, i'm not sure how to ...
0
votes
1answer
14 views

Magento 2 - How to find out which data is available for an object?

I have a quote item: /** * @var \Magento\Quote\Model\QuoteFactory */ protected $_cartFactory; public function __construct( ... \Magento\Checkout\Model\CartFactory $cartFactory, ... ) { ...
6
votes
2answers
3k views

How can Set filter collection in custom model by product id magento 2

I want to filter collection in my custom model by product id to load the filter data value in admin grid. My Model:- Vender\Modulename\Model\Outofstock namespace Vender\Modulename\Model; class ...
7
votes
5answers
39k views

How to get Category Collection per Store in Magento 2?

I want to get all categories names from a specific store. I'm trying: $categoryFactory = $objectManager->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory'); $categories = $...
0
votes
1answer
19 views

in magento controller file there is one get function is there “$mobile -> $model ->getphone();” where is that get phone method defined

in magento custom module controller file there is one get function is there for getting a phone number "$mobile -> $model ->getphone();" where is that get phone method defined.
5
votes
5answers
10k 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 ...
1
vote
1answer
772 views

Magento 2.2 - Fatal error: Uncaught Error: Call to undefined method Magento\Framework\App\ResourceConnection::load()

Fatal error: Uncaught Error: Call to undefined method Magento\Framework\App\ResourceConnection::load() in /var/www/html/magento2_dev/vendor/magento/framework/Model/AbstractModel.php:536 Just adding ...
1
vote
1answer
29 views

What is the fastest way to get 'is_active' column value from 'customer_entity" table?

I'd like to ask for the fastest way to get the column value of 'is_active' from 'customer_entity' table. It could be using object_manager or something. Thank you in advance
4
votes
1answer
2k views

'Option values are not specified' when saving configurable

I have a product import routine which calls $this->productRepository->save($product); but it's failing with the following error: [Magento\Framework\Exception\InputException] Option values are ...
8
votes
3answers
7k views

Disabling a UI component field upon condition in Magento 2

I have a UI component defining some fields. How do I disable the field upon a certain condition? In other words, use <item name="disabled" xsi:type="boolean">true</item> only when a ...
0
votes
2answers
155 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" /> ...
2
votes
1answer
3k views

How to get Extension Attribute in a model in Magento 2?

I have added an extension attribute by creating extension_attributes.xml file in etc. Its content is: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="...
0
votes
1answer
47 views

How to save custom table data in Magento 2?

I have created a table using a Controller and Model and in that file show some data. But i don't know how to save that data in database i have created a table in Magento 2 db. But don't understand how ...
0
votes
2answers
34 views

Issue in extending a model magento 2

I want to extend the Magento\ConfigurableProduct\Helper\Product\Options\Loader as per this github issue https://github.com/magento/magento2/issues/21663#issuecomment-477966963 My di.xml file is <?...
0
votes
2answers
2k views

Magento 2 Override Model using Plugin

I have to override magento 2 code model file in the custom module. I have to override below method from Magento\Quote\Model\Quote\Address to my custom module and I have to change value of $amount. ...
4
votes
1answer
829 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 | ...
3
votes
1answer
1k views

Magento registration returns 'Last name cannot be empty'

I am trying to deploy Magento 1.9.2.1. I used the package from the official site. But a strange thing happened to me. Among all the instances I deploy, it fails at any page that requires validation ...
1
vote
1answer
42 views

How to get product from custom attribute in Magneto 2?

I have a Custom attribute on Product in which i have save a string i want to get count of those products which have same attribute value in Magento 2 using an Controller or Model.
0
votes
1answer
947 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
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
1answer
51 views

How to add Data to Custom table in database using model in magento 2.3.5

I am created one form for contact and i want to insert form data into custom table in database in magento 2.3.5 so can anyone have idea about it then please send me solution. <?php namespace Aspl\...
3
votes
2answers
222 views

What is difference between these models and design patterns used in Magento?

Yes, I know this question has many answers in google, but please clear my confusion. What is the difference between Repository and Factory, and when should We use a Repository vs a Factory in Magento ...
0
votes
1answer
21 views

Cannot filter the data collection

I'm trying to filter the data collection from 4 hours to now and I have the below code but its not working. public function getWishlistProduct($wishlistid){ $to = date("Y-m-d h:i:s"); $from ...
0
votes
1answer
63 views

I want to create column in sales_order table and view custom field on order edit section in magento 2.3.5

I am added one custom field in checkout address form and i want to store that field data in Database and also display this field in admin order edit page in magento 2.3.5, so anyone can have idea ...
0
votes
1answer
14 views

How to add created at and updated at column and update it on values save?

I want to add created_at and updated_at columns in a custom table and update both columns on saving the data.
0
votes
1answer
24 views

How to properly use Model Collection in Magento 2

I'm using Magento 2.3.4 , and i kinda confuse with how to use Magento 2 model correctly or follow the code standard. I have a model collection with database structure like this: brand_id | name | ...
0
votes
2answers
50 views

Magento 2: Model Override not working

I want to modify the code of Magento\Sales\Model\Service\PaymentFailuresService.php. So I'm overriding Model file using the below code but it's not working. etc/di.xml <?xml version="1.0"?> &...
0
votes
2answers
82 views

Magento2.3: How to collect the data by time?

I want to collect the records from 10PM to 5AM of wishlist data. I have already created a module and not sure how to filter the records by this timeframe. The wishlist table contains a field called ...
0
votes
1answer
37 views

Load Customer Model by Extension Attribute in Magento 2

How can I load the Customer Model and Collection by Extension Attribute in Magento 2? I've declared an extension attribute in extension_attributes.xml and saved to the Customer Model. Now, How can I ...
0
votes
1answer
39 views

Save data of custom form in db using model

My controller file <?php namespace Afg\Dealerreferral\Controller\Index; use Afg\Dealerreferral\Model\DataFactory; use Magento\Framework\Controller\ResultFactory; class formdata extends \Magento\...
0
votes
0answers
16 views

How to pass data from model file to phtml file?

I want to pass collection from model file and then, get HTML into model file. How to do that? Please help me. Thanks.
0
votes
0answers
34 views

Shipping method based on City

I'm trying to make my flat rate shipping method appear only for peoples in a specific city. Magento version 2.2.11 My model is: <?php namespace RaphaelCordeiro\CepLimit\Model\Carrier; use Magento\...
1
vote
1answer
23 views

Declaration warning when extending _afterLoad() in AbstractModel

I've created a backend module to which I've added the possibility to set storeview specific data today. That worked and showed up fine. So I'm trying to load and save my storeview data now but it just ...
6
votes
3answers
814 views

Magento 2: Use a model with a dynamic name

I have a M1 module that I'm looking at porting to M2, and part of one of helpers contains code that looks like this: public function getModel($code) { return Mage::getSingleton('vendor/...
0
votes
1answer
24 views

how to set group by and order by for custom model collection query in magento 2.3.4

$Custommodel=$this->mycustommodelFactory->create(); $collection = $Custommodel->getCollection()->addFieldToFilter("customer_id",$customerid); $collection->getSelect()->group('...
0
votes
2answers
55 views

How to get data from a model without calling the objectManager in the template

I have a custom Order model, it has a method in it @method int getIncrementId() I have a template to transfer the id of the current order/app/code/Qq/Www/view/frontend/templates/success/index/...
12
votes
6answers
21k views

How to Get country name from country code in Magento 2?

i want to get country name from country code, i got the country code from the data order like this : $data = $order->getShippingAddress()->getData(); $countryCode = $data['country_id']; echo $...
4
votes
1answer
213 views

getCollection return null on custom model collection Magento 2.3.4

I'm creating a custom module to make a model by using mage2gen, I named this model critic: app/code/Vendor/Module/Model/Critic.php namespace Vendor\Module\Model; use Vendor\Module\Api\Data\...
1
vote
2answers
129 views

Magento 2.3.3 create popup

How to create a popup? I want to create a popup for every page unless the customer clicked close. I want to show a popup with the cms block content. I am not sure what to do or how to start I have ...
0
votes
1answer
21 views

Magento 2 - Injecting a model into a class? How to?

I have a class where I'd like to inject a model into it, to use the code already created in the model. How would I go about doing this in my class? Thank you.
2
votes
2answers
8k views

is Mage::getModel('my_module')->getCollection()->getData(); ok performance wise?

For a homepage I am getting data like this from my module's table: Mage::getModel('my_module')->getCollection()->getData(); I wonder if this is the best thing performance wise. There are only ...
0
votes
1answer
61 views

How can I get pre-hashed password after customer registration

Please note: I understand this would be open to a potential security risk. However, due to the nature of my site, I want to exhaust as many solutions as possible to help stop fraud from taking place. ...

1
2 3 4 5
15