Looking through the available endpoints we can see there are a couple options to POST a new specification group. If we just have one to create we can use the Feedback
/v1.0/optionCategories/ endpoint. If we have many, then using the /v1.0/optionCategories/batch endpoint. For our shop wear example, we only have one new specification group called Fabric Details, so we'll use the former.
To understand what we need our payload to look like, I always like to use the API Explorer and use the GET on the same endpoint that I am working with. In the response, there will be a JSON array of items that were created by the Minium accelerator and from that array I will pick one as an example to to examine:
In this case, the only field we'd need to remove would be the id which will be provided by Liferay upon a successful import. We're also not going to be using description so I'll omit it for now. So using the API Explore we can post the following payload to create our new specification group:
{
"key": "fabric-details",
"priority": 10,
"title": {
"en_US": "Fabric Details",
"es_ES": "Detalles de la Tela"
}
}
Creating or Importing Specifications
With our specification groups defined, we can now start define any new specifications that are needed for our shop wear line of products. Just like the specification group, the specifications are also a very simple data model with many of the same fields. Working through the UI, we're going to use the same Specification widget (Commerce > Product Management > Specifications), but now we'll be working through the Specification Labels tab.
To define our specification label we provide a localizable label and description, a numeric priority, and a key. These are very similar to what we've seen with specification group. Additionally, we have the option to indicate if this specification label should be used in the Specification Facet widget and with which specification group it should be listed.
Just like before, with the specification group, we can also create and manage these values through our headless APIs. And I know what you're probably already thinking. If the specification group is found in the headless-commerce-admin-catalog/v1.0 application under a section called OptionCategory, then the specification must be found under a section called Option, right? Well, not quite they are actually found in a section called Specifications ¯\_(ツ)_/¯
And by now, you can probably guess that we could POST to the /v1.0/specifications endpoint to create new specification labels one at a time or we could use the /v1.0/specifications/batch endpoint to create specification labels en masse.
A quick GET to the /v1.0/specifications endpoint provides us with an array of items from which we can extract one to examine in order to determine what our payload should look like.
We can again remove the id field when creating our payload since Liferay will generate that when we import. We can also omit the description as we're not going to use a description for specification label in our design. The optionCategory is a little tricky because you might think you could just provide the key or id values, but with a little trial and error will find you need the id, the key and at least the empty title object.
In this case, let's use the batch end point so we can create a few different specification labels related to fabric details. We'll use fabric type label to track if the garment is made of cotton, polyester, or perhaps a blend of different types and we'll use care instructions to track how the garment should be laundered. In the case of fabric type, we'll want to make sure that this is included in the Specification Facet widget, because it is likely that someone might have a need to filter products based on the type and there probably won't be too many different variations. However, for the care instructions we will exclude them from the Specification Facet Widget. They are important and should be displayed on the product detail page, but probably aren't something that you would use to filter products. Also, with different products possibly coming from different suppliers it's possible that there might be a lot of very similar care instructions with only slight differences which would be overwhelming in a Specification Facet. With this in mind, we can POST the following payload to the /v1.0/specifications/batch endpoint:
It's important to note that while it's possible to create Specifications "on-the-fly" as Products are being created through the UI or the API. However, if you do so, you won't have the ability to set some of the default values like the priority or if the specification should be used for faceted search.
One More Thing...
And of course, before we wrap things up I have one more thing that might be useful to consider when working with specifications. While they might seem simple, specifications actually support some more complex aspects of Liferay assets such as custom fields on both the specification label and on the specification value that's specific to a product.
Custom fields on a specification label might be useful if you have some specifications that should only display in certain situations (e.g. printOnly, displayDetailView, displaySummaryView). You could extend the specification label data model with a flag that could be checked in the Product Detail widget or the Product Comparison Table widget. And, all Custom Fields are automatically included in our headless APIs so the data would also be available to any external system or view that's consuming our headless APIs.
An interesting use case for extending specification values with custom fields is the ability to provide SKU specific specification values. By default the specification values are defined at the product level and they are shared by all SKUs. Liferay allows you to have multiple specification entries with the same specification label on a single product so you could use a custom field to associate each of the specification entries with a specific SKU and then you would just need to provide your own Product Detail template to show the right specification based on the selected SKU.
Conclusion
So that wraps up our second installment and we're a little bit closer to actually importing products. I know that was a pretty long post so thanks for sticking around. Hopefully you have a deeper understanding of the benefits you get from properly using Liferay product specifications. You should also know how to create and manage both specifications and specification groups and import that data from an external system. And lastly you should know how and when to extend the out-of-the-box data model for specifications.
Next time we're going to take a closer look at a somewhat related concept, product options. With product options you can not only support simple product variations such as size or color, but you can also support more complex use cases such as customizable products and configurable product bundles.
نحن نستخدم ملفات تعريف الارتباط لتقديم محتوى مخصص وتحليل التوجهات وإدارة الموقع وتتبع حركات المستخدم على الموقع وجمع معلومات سكانية عن قاعدة المستخدمين بشكل عام. اقبل جميع ملفات تعريف الارتباط للحصول على أفضل تجربة ممكنة على موقعنا أو إدارة تفضيلاتك.
زيارة سياسة الخصوصية