Questions tagged [model]

Models contain most of the business logic in Magento modules

Filter by
Sorted by
Tagged with
0
votes
1answer
14 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
53 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/...
10
votes
6answers
17k 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 $...
0
votes
1answer
740 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 ...
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 ...
3
votes
1answer
68 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\...
0
votes
2answers
1k 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. ...
1
vote
2answers
62 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 ...
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
1answer
16 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.
0
votes
2answers
869 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 ...
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 ...
5
votes
4answers
7k 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 ...
0
votes
1answer
53 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. ...
0
votes
1answer
25 views

Magento getData() vs getFieldName() in model

After load('id') function in model, we can get data by either model->getData('field_name') or model->getFieldName(). I know that both functions are provided by DataObject class but what I want ...
2
votes
1answer
25 views

What PHP class executes the SQL to select models and collections from the database?

When I have a PHP model or collection of a Magento entity (such as a product or customer), what PHP class(es) is in charge of constructing and executing the SQL that selects that model or collection ...
0
votes
1answer
765 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 ...
5
votes
2answers
2k 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
3answers
32k 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 = $...
1
vote
2answers
6k views

How to remove a product's attribute value

I am updating produts programmatically and it sometimes happens that an attribute for a product is not used anymore. In that case, the attribute value should of course be removed. However, I can not ...
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 ...
2
votes
6answers
604 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 ...
2
votes
1answer
548 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/...
0
votes
1answer
25 views

Custom column is not updating in customer_entity table

I added custom column 'email_status' in customer_entity table via dc_schema.xml <?xml version="1.0"?> <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
0
votes
0answers
24 views

How can I get data from table using repositories? | Magento 2.x

How can I create repository in magento 2 and than get data from me custom table using this repository? Model of this tables is created.
2
votes
1answer
2k 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="...
1
vote
0answers
42 views

Adding data to database [closed]

I'm able to fetch data from custom form but not able to put it in database table. $model = $this->_name->create(); $entity = $this->getRequest()->getParams(); $model->...
0
votes
1answer
23 views

How do I check my override Model is working?

I wrote an override to \vendor\magento\module-sales\Model\Order\Pdf\AbstractPdf.php I did enable my override, I did run magento setup, di compile and flush the cache. Everything went smooth. But ...
1
vote
0answers
95 views

Magento cache concept store custom block or custom model object data

I do not understand properly cache concept in magento. I want to store data in cache so when user again refer data/page ,it automatically get from cache that data rather than fire server request.When ...
8
votes
4answers
8k views

How prevent a model data save using _save_before event

I have create a model which has its own database table. For a customization I need to trigger save_before event of this model. If one field value is not matched, then the data should not be saved. ...
5
votes
1answer
38 views

Error Call to a member function beginTransaction() on a non-object when saving to database

I am at a loss, I've tried a lot of stuff but nothing seems to work to get rid of this error. Fatal error: Call to a member function beginTransaction() on a non-object in /home1/powertg2/public_html/...
1
vote
1answer
49 views

Magento 2 How do I override \vendor\magento\module-fedex\Model\Carrier.php?

I want to make changes on vendor\magento\module-fedex\Model\Carrier.php How do I override this core file? I just want this completely override. Like what folder I should create and what files I ...
1
vote
1answer
619 views

How to update data if product sku already available in magento using custom script for product import?

I have created custom import script for simple product csv import in magento. It is working fine for the newly products. But I want to update the products if sku already exists. How can I achieve ...
1
vote
1answer
119 views

Magento2: How to override customer model file?

I want to override AccountManagement.php in Magento\Customer\Model\AccountManagement.php directory. My di.xml :- <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
3
votes
3answers
4k views

Override model function Magento 2

I want to override one of the function in Magento core model which is located in vendor\magento\module-sales\Model\Order\Email\Sender\OrderSender.php <?php /** * Copyright © 2016 Magento. All ...
1
vote
3answers
1k views

Magento 2 model fields validation?

Where is the correct place to validate field in model? For example, I have a database, with a table Product, but the database designer didn't force NOT NULL in some required fields (for instance, ...
2
votes
2answers
1k views

Increase Prices According to Customer Group including Tier Prices

So magento doesnt support this and its often asked about. My customer enters all their prices as Trade pricing, but wants anyone with out that type of account ie not in a particular customer group ...
0
votes
3answers
839 views

Where does Magento keeps it's business logic?

I went through some articles which describes Magento architecture. As we all knows Magento uses MVC ( Model-View-Controller ) architecture. It separates the business logic, data access layer and ...
1
vote
1answer
203 views

Magento 2.3.2: How to override a Inventory Deduction API model?

I want to override below Magento core file vendor/magento/module-inventory-source-deduction-api/Model/SourceDeductionService.php to add code $qty=0; inline 83. I tried by my self but getting an ...
2
votes
2answers
636 views

[Solved]Cannot override Pdf/Total/Default.php model

Good morning everybody! I have a problem trying to override the model app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php with app/code/local/Mycompany/Sales/Model/Order/Pdf/Total/Default.php. ...
2
votes
3answers
8k views

Get primary billing / shipping address of customer model

I got a customer model and want to get the primary billing / shipping address. I tried it like this: $customerObj->getPrimaryBillingAddress(); $customerObj->getDefaultBillingAddress(); $...
20
votes
3answers
3k views

What is IdentityInterface in Magento2

I see that a lot of the models in Magento 2 implement Magento\Framework\DataObject\IdentityInterface. This interface has a single method called getIdentities The implementations of the method usually ...
5
votes
4answers
16k views

Magento 2: how to get Model in Block

I want to use an instance of a Model into a Block. in Magento 1 they uses: $exple = Mage::getModel('exple/standard'); How can I do this with Magento 2?
0
votes
0answers
14 views

Category not being updates for products

I currently have a cronjob plugin running in the background of my magento 2 installation which imports products from an XML file to the db. The code checks if the product exists, and if it does it ...
3
votes
1answer
57 views

Shell script dumps Model source code

Weird things happening. I've written a customized product import script which is executed as a shell script. In this script, I gather some XML input, parse it into an array and then try to import the ...
58
votes
4answers
16k views

Deprecated save and load methods in Abstract Model

I see that in the develop branch of the Magento 2 repo the methods load and save from Magento\Framework\Model\AbstractModel class are deprecated. But there are a gazillion classes in the core that ...
1
vote
1answer
225 views

Updating product name/description (that has group prices) via model causes Integrity constraint violation (in catalog_product_entity_group_price)

I have this simple code, which tries to update the product's name & description like this: $productID = Mage::getModel('catalog/product') ->getIdBySku($product->Sku); if ($productID) { ...
1
vote
2answers
108 views

Magento2.3.1 How to overide Model file?

I am using Magento2.3.1 and i trying to override model in our theme. our model file path app/code/XXXX/General/Model/Layer <?php namespace XXXXX\General\Model\Layer; class FilterList extends \...
0
votes
0answers
27 views

When I post the data ,the data will save repeatedly into database

How to check weather the value is in database when i insert the data $amount_model = Mage::getModel('donations/amount'); if(isset($post_data['amount']) && $post_data['amount'] != '') { $...
0
votes
0answers
38 views

Magento 2: Custom value save in sales_order_grid table

I have a custom column in the sales_order_grid table and want to save some custom values that are not in sales_order table. Too many tutorials are there that populate sales_order table column into ...

1
2 3 4 5
15