Questions tagged [service-contract]

Denotes questions related to Magento 2 Service Contracts.

Filter by
Sorted by
Tagged with
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
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
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
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
9 votes
2 answers
9k 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" ...
Bojjaiah's user avatar
  • 4,002
8 votes
1 answer
614 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
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
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,009
3 votes
1 answer
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() )-&...
Alana Storm's user avatar
  • 44.4k
2 votes
1 answer
276 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
2 votes
6 answers
14k 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 ...
Silvan's user avatar
  • 1,347
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
1 vote
1 answer
823 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