Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [service-contract]

Denotes questions related to Magento 2 Service Contracts.

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

Where should I connect model-data-access?

I am building a custom feature to create lists of favourite products. For this purpose I have created 2 models: The actual list-entity and a model representing information about a single product. For ...
Hurrpadurr's user avatar
0 votes
2 answers
1k views

How to get the shipping address by order ID?

How to get the correct shipping address for an order ID? I am using Magento\Sales\Api\OrderRepositoryInterface to get the order information by order ID, but there are no methods for getting the ...
audio-engineer's user avatar
0 votes
1 answer
79 views

Need some brief difference about interfaces and model?

As we know save method by using modelfactory is deprecated i just want to know what is the alternative and how it is implemented because i tried API interfaces but at save i got stuck so kindly anyone ...
Asad Ullah's user avatar
  • 1,461
0 votes
1 answer
301 views

Override third party module service contract

There is third party custom module. For add entries they used service contract entities. I need to add one more entry. Don't want to touch third party module. How can i extend their interface and ...
Nadim's user avatar
  • 91
0 votes
1 answer
239 views

magento 2 resource model "save" to implement service contract persistence operations. not saving POST empty

I have a custom rest api for PUT and POST that the post data is an empty array therefore not saving as it's empty can anyone advise why or what could be wrong? /** * Save data. * * @...
Juliano Vargas's user avatar
1 vote
1 answer
1k views

magento 2 setFilterGroups is not working of custom module SearchCriteriaBuilder

I have a build service contact on an entity of custom module And it has 3 fields like pk,order_id.order_item. And When try to apply setFilterGroups on SearchCriteria getting Error. Uncaught ...
Amit Bera's user avatar
  • 77.5k
10 votes
1 answer
1k views

What is/means/does Magento\Framework\EntityManager\MetadataPool and Magento\Framework\EntityManager\Operation\ExtensionPool

There are new things we can see at Magento 2.3 in di.xml for service contracts. let's give an example:Magento_Cms module Like Magento\Framework\EntityManager\MetadataPool Magento\Framework\...
Amit Bera's user avatar
  • 77.5k
0 votes
1 answer
424 views

Magento2 - rest API on custom module "items" object is not populated

I build a custom module with a stores repository that I query using the following webapi.xml: <?xml version="1.0"?> <routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
grll's user avatar
  • 143
9 votes
3 answers
5k views

Magento 2 - Difference between Model, ResourceModel. Collection and Repository

I'm studying Magento and I'm confusing about the differences between these four layers. What I have understood is the following: Model Is the entity class with ONLY getters/setters and magic methods....
Mirko Rapisarda's user avatar
4 votes
1 answer
2k views

Is there a way to select a field to be returned when using the getList() function within a Repository?

MAGENTO v2.2.6 To better illustrate my question here's an example. When using the ordinary collection I can limit the attributes/fields returned like so: NOTE: I wouldn't normally use the object ...
NSwanson7's user avatar
  • 453
4 votes
2 answers
818 views

Magento 2.3 - Add custom customer entity attribute with service contract

I have some problem to save custom customer entity attribute in database. I've created a Patch to add this attribute to the customer entity. The attribute is shown correctly in the backend, but when I ...
Mirko Rapisarda's user avatar
2 votes
1 answer
244 views

How do I persist data in custom table in Magento Database (the right way)?

I have created a module that adds a custom table. I also created a Model, ResourceModel and Collection classes, and was able to use them to insert data into this new table by calling the ...
Ricardo Martins's user avatar
2 votes
1 answer
825 views

how can we implement service contracts in magento 2 in controller? [duplicate]

please answer with simple example of customer detail in which we can access customer detail save() data Delete() getbyid() update() requirements. all functions in controller using ...
Asad Ullah's user avatar
  • 1,461
1 vote
1 answer
112 views

Implementing service contract Magento 2? Getting error "Class Assign\RestService\Model\ResourceModel\Hamburger\CollectionFactory does not exist"

I am implementing simple service contracts. don't have much knowledge about service contracts following example from here How to implement service contract for a custom module in Magento 2? i am ...
Asad Ullah's user avatar
  • 1,461
1 vote
1 answer
1k views

Magento 2 Service Contracts and WebApi

I have implemented the Magento 2 Service Contracts, everything is working as expected, I can use my repository's getById and getList in Controller but as we know we can use Service Contracts for ...
Adnan's user avatar
  • 853
8 votes
1 answer
616 views

What are the use of ExtensionAttribute JoinProcessorInterface and CollectionProcessorInterface at magento 2.2.3

I built Magento 2 Module which has a model and Service contracts/API. During this implementation, I have followed vinai Kopp article and also magento2 module Magento_Quote. On this Magento\Quote\...
Amit Bera's user avatar
  • 77.5k
0 votes
1 answer
2k views

Magento 2: Use of ObjectManager in Controller

Let's say I want to load a order item in a controller. I can use: $order = $this->_objectManager->create('Magento\Sales\Model\Order\item')->load($id); I see this happening in a lot of free ...
Coen Ponsen's user avatar
1 vote
1 answer
3k views

How to load a quote item via it's id?

Is there a way to load a quote_item directly using current Magento coding standards? Right now I'm loading the cart and then finding the quote item like so: $cart_id = $this->getRequest()->...
jamil's user avatar
  • 985
3 votes
2 answers
558 views

The difference in use Repository or RepositoryInterface to load model

I found two ways to load model on net by service contracts in Magento 2. One is use the Repository, another is using the RepositoryInterface directly. Both work well. What is the difference between ...
Key Shang's user avatar
  • 3,425
1 vote
1 answer
2k views

In Repository, how to replace deprecated load() function?

I know we should use service contracts(Repository) over $model->load(), but in Repository itself, how to replace the deprecated load() function? For example, in Magento\Cms\Model\PageRepository, ...
Key Shang's user avatar
  • 3,425
3 votes
1 answer
5k views

Magento2: How to use Magento\Framework\Api\FilterBuilder?

I am able to use the addFilter in the searchCriteriaBuilder like this: $this->searchCriteriaBuilder->addFilter( 'name', 'M%', 'like' ); For example in this code I can get all the ...
Mehdi's user avatar
  • 878
1 vote
1 answer
839 views

Using Quote Repository creates a new row after save

So I am trying to get to grips with Magento 2's new way of handling data using service contracts. I have the following code: $formData = [ 'quoteId' => '', 'purchaseOrderNumber' => '', ...
Wildcard27's user avatar
0 votes
1 answer
23 views

Repositories and Methods

Does anybody have a link where I can find a list of all Magento 2.1 (or Magento 2) repositories and their methods? I tried to find this in Magento Devdocs and can't seem to find anything. Maybe I am ...
Rws's user avatar
  • 1
4 votes
2 answers
688 views

Magento 2 - what functions can I use?

Recently I've went through the "Fundamentals of Magento 2 development" course and there was such statement that we SHOULD NOT use functions from other modules that are not defined in the API ...
Sebastian's user avatar
  • 528
2 votes
0 answers
204 views

What is the proper way of implementing service contracts in Magento 2?

I have a simple module with custom entity and I wanted to implement service contracts. I've read some articles about it and watched the course on Magento U (Fundamentals of Magento 2 development). ...
Sebastian's user avatar
  • 528
7 votes
1 answer
1k views

Using repositories on frontend with paging

I've created a CRUD module in the proper way, with service contracts (SC). I'm using these SC in the backend with ui-components and everything. This works nicely, but I want to use the repository's ...
Marius's user avatar
  • 198k
2 votes
0 answers
50 views

service contract save method flow - magento 2 [duplicate]

I can able to get custom table records from database using service contract but hard to understand the save flow. di.xml <preference for="Mobi\Service\Api\RcRepositoryInterface" type="Mobi\...
Bilal Usean's user avatar
  • 9,987
1 vote
1 answer
381 views

How to get and add Core Table data in magento2

I need to get and add a new Core table data. So, I tried based on get custom table data way(Model, ResourceModel) but it's not working for me. For example I need to collect customer_group data What ...
Rajkumar .E's user avatar
  • 3,570
2 votes
0 answers
2k views

add new extension attribute to the response of quote item (/V1/carts/:cartId)

I am trying to add some custom extension_extributes (For example: is_free_product & unit_price) to item node response of Magento\Quote\Model\QuoteRepository::get($cartId) Here is what I tried so ...
MagePsycho's user avatar
  • 4,656
2 votes
1 answer
277 views

Code Generator for Services in Magento 2

Magento 2 recommends us to use Service Contracts and we have to define all getter/setters explicitly in the interface and them provide a base implementation to save fields in the database. It's a lot ...
Amasty's user avatar
  • 6,508
0 votes
2 answers
3k views

"Call to a member function getIsInStock() on null" with getExtensionAttributes()->getStockItem()

I try to access stock data for a product, using $product->getExtensionAttributes()->getStockItem()->getIsInStock() and receive the following error on this line PHP Fatal error: Call to ...
Fabian Schmengler's user avatar
0 votes
1 answer
535 views

Magento 2 Service Contract API Example For Creating A Shipment and Adding Items

What would be the correct way to within my Magento 2 module create a shipment, add items to it, and save it? I think the general idea would be to inject: \Magento\Sales\Api\...
Kevin Chavez's user avatar
10 votes
2 answers
429 views

Magento 2 and Services Contracts

I know there is a lot of topics about this question but I'm not sure to clearly understand.. When did we need to use service contract ? Are they replacing the CRUD done by Model / ResourceModel ? ...
TaKe_Da_ShAkEr's user avatar
32 votes
2 answers
5k views

Magento 2 - Why is Magento\Checkout\Model\Cart deprecated?

Since Magento 2.1, Cart has a @deprecated tag. Nevertheless, it is still used by Magento itself to store products when shopping. Is the deprecation intended, and if so, and what should we use instead?
Patrick van Bergen's user avatar
3 votes
1 answer
81 views

Magento 2 Session Service Layer

I'm trying to figure out the best way to interact with the Customer session using the service layer. I couldn't identify the proper repository to use. Any ideas?
ryanF's user avatar
  • 2,279
5 votes
0 answers
2k views

Proper way to get product collection with store specific values in admin area

For a custom indexer, I need to load a product collection with the attribute values for a given store, while not in a store context. As it has been established in Magento 2: How to Filter a Product ...
Fabian Schmengler's user avatar
5 votes
2 answers
7k views

How to create store view or store programmatically and do it right in Mage 2?

I want to create store or store view programmatically and I use the followng code (for store view): $storeView = $objectManager->create(\Magento\Store\Model\Store::class); // Store - is a ...
Alex Gusev's user avatar
  • 2,019
0 votes
0 answers
369 views

Localized frontend value for getCustomAttribute() (select or multiselect attributes)

Given a Magento\Catalog\Api\Data\ProductInterface $product and string $attributeCode of an arbitrary attribute, I can access the attribute value, using: $product->getCustomAttribute($attributeCode)...
Fabian Schmengler's user avatar
3 votes
1 answer
366 views

Get child products of configurable product via Service Contract / API

In Magento 2, is it possible to get the associated simple products of a configurable product, via Service Contracts? The only reference to the product type that I can find is ProductInterface::...
Fabian Schmengler's user avatar
6 votes
1 answer
823 views

Get Category IDs for Product via Service Contract / API

In Magento 2, is there a way to get the assigned category ids for a given product, via Service Contracts? The CategoryLinkManagementInterface API interface only has one method that returns the ...
Fabian Schmengler's user avatar
1 vote
1 answer
454 views

How can I get a product's image URL using service contracts?

I know that in Magento 2.0, there is a recommended way to access products info from another module using service contracts. So, my first question: how can I get a product's image URL using service ...
Michel Gokan Khan's user avatar
5 votes
1 answer
604 views

Magento 2: difference between Api\SearchCriteriaBuilder and Api\Search\SearchCriteriaBuilder?

Those two classes are very similar but I don't get the differences and why should one be used instead of another ? Magento\Framework\Api\Search\SearchCriteriaBuilder => a handful of references in the ...
Raphael at Digital Pianism's user avatar
3 votes
1 answer
783 views

Magento 2 API vs. Web Interface vs. Web API

Just as a basic question in Magento 2. In Magento U tutorials, it says: In Magento 2 Modules only communicate through API One module in not aware of the internals of another, so the ...
Amin Memariani's user avatar
16 votes
3 answers
3k views

Magento 2: what are the benefits of using service contracts?

So as some of you may know, Magento 2 recommended way to deal with models/collections for CRUD actions is to use service contracts. But still according to the Magento SE Q&A it seems like most ...
Raphael at Digital Pianism's user avatar
55 votes
3 answers
30k views

How to implement service contract for a custom module in Magento 2?

As seen in this post : Deprecated save and load methods in Abstract Model the save and load methods are deprecated in the Magento 2 develop branch. Thus, the good practice is now to be implement ...
Raphael at Digital Pianism's user avatar
2 votes
4 answers
6k views

Magento2 cannot add stock data via StockItemInterface

I am writing a module that loops over a result-set and creates products. Creating products works fine, but some how I am not able to save stock qty. This is my code: http://pastebin.com/7Drn8Jht ...
Joachim Vanthuyne's user avatar
25 votes
3 answers
6k 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 = $...
Fabian Schmengler's user avatar
1 vote
2 answers
14k views

How to create customer via customer repository in Magento 2

To create customer via Magento 2 services from php client i have used two files test.php <?php require __DIR__ . '/app/bootstrap.php'; $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $...
prasad maganti's user avatar
5 votes
1 answer
4k views

Magento2: How Data interface and model function interact with each other?

I've been following article on Models and Resources here. According to my understanding, Magento2 uses service contract to provide model access to 3rd parties. Here I'm interested in Data interface ...
amitshree's user avatar
  • 7,036
6 votes
1 answer
2k views

On Magento2, is it better to declare Interfaces on Api/Data before create Model and Ressource?

I'm creating a custom module, and I want to know if it's better to create a module with this structure : Api/Data/CustomInterface.php Model/Custom.php Model/ResourceModel/Custom.php Model/...
Maxime Huran's user avatar