Questions tagged [repository]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
9
votes
2answers
5k views

How should I save new or updated entities of models?

In Magento 2 we have repositories classes. Classic method save() used heavily in Magento 1.9 are deprecated, if I am correct, from 2.04 or 2.05. I was using factories to create new object and after ...
1
vote
1answer
304 views

Magento 2: links between entities: best practices

I have a question regarding link between entities. Consider that a car is linked to a brand. The car entity will have a brand_Id attribute. Coming from the "Symfony universe", using the Doctrine ORM, ...
0
votes
1answer
194 views

REST API Not saving products Magento2

Using the REST api of M2 and for some reason I can't save a new product ? Here's my code Here's the error I get. Any suggestions?
2
votes
3answers
1k views

“URL key for specified store already exists” when updating an existing product?

I am getting the above error on a limited number of products, when loading and saving them with this code: $product = $productRepo->get($_sku); $product->setStockData(['qty'=>$new_qty,'...
5
votes
0answers
466 views

_origData is null for some models in Magento 2 before or after save

Let's get a customer save process from the admin panel as an example. We have an event observer for model_save_before and trying to get a set of values for the model that have been changed upon the ...
3
votes
2answers
4k views

How to join a table with a Magento 2 repository

I am trying to extend inventory stock items by joining my own table with added information. When the product page is loaded it gets the stock item via StockItemRepository::getList($criteria). So I ...
6
votes
2answers
943 views

Can the NPM fiasco happen to Magento 2?

As some of you may know, a huge fiasco happened a month ago with NPM As of now, Magento 2 composer.json file includes a lot of external resources (details on the Magento 2 GitHub) What if one of ...
23
votes
3answers
3k views

Is there ever a reason to prefer $model->load() over service contracts?

I understand that the preferred way to work in between modules in Magento 2 is using the service contracts. So if I want to load a product, I use the product repository: $product = $...
3
votes
1answer
3k views

Magento 2: Can you Filter By store_id Using a Product Repository

In Magento 2, it's not possible to add a store_id filter to a product collection directly. Instead, you need to use the addStoreFilter method, which adds a special "product limitation filter". It ...
12
votes
2answers
9k views

Magento 2: Product Repositories, Filter Groups, and `AND`

I'm trying to use a product repository to fetch a list of products. I want to fetch based on two filters, combined with an AND criteria, but things don't seem to be working. Do I not understand how ...
23
votes
2answers
19k views

Filtering a Magento 2 Object Repository

In Magento 2, can you use a product repository to filter by product attributes? In Magento 2, you can use a search criteria object \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria, ...
0
votes
1answer
630 views

My Custom Module API Data not saving in magento 2

I have created a custom module (Blog) which contains a save() method, it is executed but values are not saved and it returns an empty object. <?php namespace Learning\Blog\Model\Resource; use ...