Create a localized product
In the following code example, you localize a product for the languages that are available in your Sitefinity CMS project.
In the example below, you perform the following:
- Get an instance of the CatalogManager class.
- Get an instance of the EcommerceManager class.
- Using theCatalogManager, check whether a product with the same title already exists.
If a product with the same name does exist, discontinue the execution of the method and return an empty Guid.
- Using the EcommerceManager, check whether the specified product type that you want to create already exists.
If the product type does not exist, discontinue the execution of the method and return an empty Guid.
- Using the CatalogManager, check whether a product with the same ID already exists.
If a product with the same ID does not exist, create the product by calling the CreateProduct method of the CatalogManager class. When calling the CreateProduct method, pass the product type that you want to create.
- Set the properties of the product objects.
To ensure that the product is localized for a particular culture, create a
using scope with an instance of the
CultureRegion class and modify the Title inside this scope.
- Set the ApprovalWorkflowState to Published for the desired localized version by passing the culture.
- Save the changes.
- Publish the product by calling the MessageWorkflow of the WorkflowManager.
This forces the new item to go through the Ecommerce module's workflow for creating products.