Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [service-contract]

Denotes questions related to Magento 2 Service Contracts.

2
votes
1answer
51 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....
1
vote
1answer
21 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 ...
4
votes
2answers
67 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 ...
2
votes
1answer
28 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 ...
1
vote
1answer
103 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 ...
1
vote
1answer
30 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 ...
0
votes
1answer
120 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 ...
7
votes
1answer
145 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\...
0
votes
1answer
453 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 ...
0
votes
1answer
466 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()->...
3
votes
2answers
128 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 ...
0
votes
1answer
798 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, ...
2
votes
0answers
943 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 ...
0
votes
1answer
437 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' => '', ...
0
votes
1answer
14 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 ...
5
votes
2answers
378 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 ...
2
votes
0answers
75 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). ...
6
votes
1answer
358 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 ...
1
vote
0answers
34 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\...
1
vote
1answer
182 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 ...
2
votes
0answers
895 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 ...
2
votes
1answer
123 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 ...
0
votes
2answers
1k 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 ...
0
votes
1answer
364 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\...
10
votes
2answers
236 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 ? ...
30
votes
2answers
3k 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?
3
votes
1answer
64 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?
5
votes
0answers
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 ...
4
votes
2answers
4k 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 ...
0
votes
0answers
344 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)...
2
votes
1answer
224 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::...
6
votes
1answer
622 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 ...
1
vote
1answer
426 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 ...
4
votes
1answer
421 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 ...
3
votes
1answer
382 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 ...
15
votes
3answers
1k 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 ...
35
votes
3answers
12k 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 ...
1
vote
4answers
3k 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 ...
22
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 = $...
0
votes
2answers
6k 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, $...
5
votes
1answer
2k 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 ...
5
votes
1answer
1k 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/...
3
votes
1answer
3k views

What is the correct way to change order status in Magento 2

After placing an order, my module calls an external API. If success from external API, I need to update the order status. I know how to update status in Magento 1 but how do you do this in Magento 2?...
1
vote
6answers
9k views

Products can't be added to cart

I'm busy developing a Magento 2 theme. Now I updated my local and production server to Magento 2 (the latest release from yesterday). Since this version I get this error when I try to add a product to ...
3
votes
1answer
1k views

Magento 2: Serializing a Category Tree as Primitive Types

In Magento 2, I can get a category tree with the following $tree = $this->treeFactory->create(); var_dump( $tree->getTree( $tree->getRootNode() )-&...
19
votes
3answers
2k views

Magento 2: What's a Service Contract

In Magento 2, is there a concrete example of something that's built using the Service Contract concept? I've seen this term thrown around a lot, but looking at Magento 2 as it exists now it's not ...
4
votes
1answer
3k views

How to return Associative Array from API in Magento 2

I have created Custom Api which returns associativeArray. If I use associativeArray it's giving error If I use string[] it's working But I want to return associativeArray. Error: Class "array" ...