Creating and updating products using the V3 API - api

I've been using Bigcommerce's csv import to create and update simple products with c# and headless browser control. This is a relatively easy method as I can include custom fields, category names, images, GPS information, and all of the other fields that the csv import allows. Even so, my long term goal will be to move to the API. So far it appears that the API is very limited. For instance, instead of just including a category name with the new product, you have to include a category ID. As far as I can see, that would mean that for every new product I would have to create the categories for the product, then retrieve the category(s) id with an API call and lastly create the product. It appears that this is just the beginning. It appears that many of the fields that are easily included in the csv now have to be created and then attached to the product. Am I missing something?

Related

Custom field in a new ticket creation by agent: Dropdown list that its values are live updated

I want to create a custom field in the agent new ticket screen.
I want the field to be shown as a dropdown list where the values in the dropdown list will be values taken from an API of other service.
I know Zendesk custom fields have an option to upload a csv file with options but since I want to the values to be live updated it won't work for me.
I'm wondering whether I need to create a plugin that will do that job or Zendesk have a solution for this need.
I am not sure this is a suitable stackoverflow questions, but if you have control over the backend of the other service, it is better to automate a call from it to Zendesk custom fields API whenever there are changes to the drop down options.
However, this is a bad idea in the first place because drop down options are associated to tags. There might be conflicts with other field options or other tags used by agents. This will be a nightmare for the data analysts who rely on tags for Zendesk Explore reports, especially if you delete an options and its associated tags.

How to create Pretty URL without ProductCode for PDP page in Spartacus?

Requirement:
The business provides a URL in the format as (":category/:name") and against this format, system will have an SKU defined for which PDP needs to be opened without changing the URL.
e.g. for a defined URL -- https://example.com/categoryName/baseProductName and SKU (SKU123) will be configured in backend.
When a customer opens the above URL, the PDP of SKU123 should load where the URL remains the same.
Spartacus code has a constraint that PDP cannot be opened without providing a product code (SKU number) to it. We have tried to override the routing configurations but internally spartacus is redirecting to a 404 page.
In Spartacus Docs(https://sap.github.io/spartacus-docs/route-configuration/) it is mentioned that it is not allowed otherwise functionality will break.
I am looking for a workaround on the same to allow routing config as (":category/:name") and (":category/:name/:productCode") both which seems to be a constraint from Spartacus end. We can feed in the productCode but the URL needs to be as is.
The current PDP functionality should not break.
Spartacus: 1.4.4
SAP Commerce: 1905
that's an interesting question, and not straightforward to solve actually. I'll give you a few pointers to workaround.
First off, Spartacus uses the product code as a unique key in all layers of the application. The code is used in the routing logic, in the store and to load the product from the backend.
Moreover, the code is passed to the CMS, as the CMS is capable to resolve custom page structure per product; you can configure a specific CMS page structure for a specific product code or product category; therefor the product code is passed as an id to the CMS when loading.
To workaround these features you need to configure and override a number of things:
Bring product name into the routing configuration
You can easily do this with the routing configuration, or just by provide a paramsMapping from product.code to product.name. More on this can be found at the docs. Additionally, you could prettify the product name (avoid spaces and other characters to avoid ugly encoding)
Bring the category name into the routing configuration
Before you can configure the router (see 1) for the category name, you need to get the category from the backend. You can do this by normalising the (first) category from the product model. However, by default the product doesn't contain the categories, which is why you'd need to configure the OCC field configuration. It's all described at https://sap.github.io/spartacus-docs/connecting-to-other-systems/. Special attention is required for the SOLR results, as they also need to expose the categories.
Additionally, you could prettify the product name (avoid spaces and other characters to avoid ugly encoding)
Change the product key internally
To ensure that the category name and product name are used instead of the product code to store (ngrx) and load (OCC) the product, you need to trick the system. You can provide a custom implementation of the CurrentProductService, where you'd evaluate if the Router state contains the category name and product name parameters. If those parameters are available, you would concatenate them so that they can later on be reconstructed.
Load product data by category and product name
You could introduce a custom adapter to resolve the product code by it's category and product name, but i'd not recommend this. It would involve an additional API call, and that's expensive. Instead, I would implement a custom backend endpoint, that takes the the category and product name. You could still provide a custom adapter in Spartacus, for deconstructing the concatenated category and product name from step 3, as this would result in a cleaner code base.
Load CMS product page by category and product name
The CMS uses the product code (id) as well to load the right cms structure. You could do 2 things here:
a. use the same pattern from step 4; create custom OCC endpoint to resolve the product code and then load the right CMS product page structure
b. use a static (but existing) product code in a customer OccCmsPageAdapter, to load the same CMS structure for all product pages. This will obviously block existing CMS functionality, but it might be ok. Or at least for your first implementation you can get it to work with this workaround.
Hope that gives you an idea or 2.
All of this being said, I believe this is quite an uncommon requirement. Not that you need pretty URLs and want to use the product name as a unique "code". But using both the category name and product name as a unique key. If possible, I'd try to move into this pattern:
use the product category and product name in the title for SEO purposes (exactly as you require)
only depend on the product code as being the unique property
change the product code structure in the backend; the product.code there are various ways to do this, the idea is that the actual product code could be stored in an alternative field, and the generated (based on name) product.code in the native code field.
all application logic (UIs, APIs, SOLR, Spartacus) will transparently use the product name as the unique key.

Set Woocommerce product attributes

everyone,
I have a "small" problem here for which I have not yet found a suitable solution. I hope you have the right food for thought for me.
We are currently in the process of introducing a new ERP (Weclapp - www.weclapp.com), which will transfer the product data to Woocommerce via ERP's own API. Many of our products are quite similar and available in different versions (industrial parts with different alloys, angles, sizes, etc.). Our product range includes tens of thousands of different products, so it is essential to offer the user a filtering option. Although it would be possible to create a variant article in the ERP, we would like to avoid this if possible (due to the circumstances that this would create on the part of the ERP). Unfortunately, the API does not allow us to transfer product attributes directly to single articles. The API only offers the possibility to transfer your own fields (created in the ERP) and output them in Woocommerce in the tab "Additional Information" or alternatively to fill an existing field in Woocommerce (can also be a custom field) via Meta Data Key.
I found the Meta Data Key for the product attributes, but I only have the possibility to transfer simple values like "Stainless Steel", "180°", "2SN" etc. The Meta Data Key for the product attributes looks a bit more cryptic and would be replaced by the simple values.
Does anyone have an idea or a workaround how I can use the values of the additional fields of the ERP as filterable data in Woocommerce?
Thanks a lot already!

VirtoCommerce API getting item prices

I am using VirtoCommerce 2.9 and have some questions regarding the API and what would be the best way to get all the information I need, while keeping the number of API requests down.
Right now I am using the endpoint /api/catalog/search to find items that matches a number of attributes. But the response does not include prices and product texts. Both I would like to present to the end user. What would be the correct or best way to retrieve this information?
Thanks!
Cheers!
Currently search service does not return the description and price for the products.
To get this details you need to use separate queries
api/catalog/product/ids?respGroup='ItemSmall'
to get product detail with description and
api/pricing/evaluate
to retrieve actual products prices. You can call them in parallel for better performance.
Be aware to use WithProperties response group because it may cause
perfomance problem. Anyway product returned with all properties values
and this 'response group' is only responsible for retrieving properties meta-information
(as possible dictionary values, multilingual, required or optional flag etc) this information often used in admin area and in storefront almost not used.
Indexed search module will be serious changed in future versions, and you will be able to have more control over the product details in the search index.

What`s the best practice for Magento to update stock from code

I have to integrate my webshop with an external system. This system provides several functionalities, described in their API. This is what I want to do:
Import/sync products (this is available as CSV via request)
Update stock of products (also available as webrequest)
So I have to hook into the Magento stock check and I want some script which updates the products like everyday.
Where should I implement my changes? What is the best way to do this? I can imagine Magento already have some API stock functionalities, but can`t seem to find the right documentation.
Thanks in advance!
Firstly you could use the Magento web service via either SOAP and XML-RPC:
http://www.magentocommerce.com/api/soap/introduction.html#Introduction-SOAP
There's an API for updating stock levels:
http://www.magentocommerce.com/api/soap/catalogInventory/cataloginventory_stock_item.update.html
However, this is usually quite slow and can take some time to update large collections of products, in which case you are better going for a solution which uses the Magento object model directly, or something custom.
Depending upon your level of development expertise there's a few options available. One library to checkout is Magmi:
http://sourceforge.net/apps/mediawiki/magmi/index.php?title=Magmi_Wiki
this is useful for updating lots of product data / stock levels quite quickly.
If you do no require an automated solution, you could always use the standard Magento import/export profiles to import stock levels from a CSV file, a quick search for 'Magento Import Export Profiles' should give you a good starting place:
http://www.seenbest-web-design.com/techclub/importing-a-csv-of-products-to-magento/
http://www.woolleydesign.net/2011/02/updating-store-inventory-in-magento/
I am fully functionally using Magmi now. I have written a plugin to automatically create configurable products, so if anyone is ever interested let me know.
There is already a plugin to process configurable products, my plugin is dependent on that plugin.
Basically, you will only be able to create configurable products if you especially have added this to your CSV, with a column named 'type'. In the column type you can set simple or configurable. With my module that won`t be nessecary. By some logic I automatically recognize the simple products and create a new configurable containing those products.
A little explanation on why I need this:
The stock system of our client updates a list of product (CSV) every few hours, containing entries of products. They sell clothing, and every size, and every color is a new entry. So one product can have 10 entries, entry 1: t-shirt green, size 12; entry 2: t-shirt green, size 13, etc.
I explain this, just in case anybody would ever need something like this, my plugin will probably help you. It will although need a few modification for your situation, since this is very specific to how your list of products is composed.
Anyway, thanks for your help!