Visit Main Site
Join Partner Program
Login
     
Introduction
Installation
Python
Documentation
Category
Products
Carts
Variations
Currency
Tax
Tax Profile
Tax Rule
Tax Code
Tax Zone
Discount
Shipping
Shipping Profile
Shipping Rate
Shipping Rules
Customer
Orders
Blog
Settings
» Variation SDK Documentation

Getting All Variations

Function: admin_variation_get_list()

Purpose

This function is designed to retrieve a list of product variations, such as size, color, or material, which are used to define configurable product attributes. This is especially valuable in e-commerce systems for managing product customization and providing a rich shopping experience to users.

Parameters

ParameterTypeDescription
limitStringThe number of variations to retrieve.
offsetIntegerThe starting index for the variations. Useful for pagination.
directionStringSorting direction.
order_byStringField name to sort by.

Use Case

The admin_variation_get_list() function serves administrators who need to organize and manage variations across a product catalog. By retrieving a structured list of existing product variations, it ensures consistent application of variations (like size or color) throughout the catalog, which enhances both back-end inventory management and front-end filtering for customers.

Python
PHP
def admin_variation_get_list():
    SDKConfig.PRINT_REQUEST_DATA = False
    SDKConfig.PRINT_RAW_RESPONSE = False

    webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())

    try:
        response = webcommander_sdk.admin_variation.list(limit="limit")
        print(response)
    except WCException as ab:
        print(ab)
        print(ab.get_errors())
        print(ab.raw_response)
public function adminVariationGetList()
{
    try {
        $queryParams = [
            'limit' => 'PAGE_LIMIT',
            'offset' => 'PAGE_OFFSET',
            'direction' => 'SORT_DIRECTION'
        ];
        $response = $this->AdminVariationsService->ReadAllAdminVariations('API_VERSION', $queryParams);
        echo '<pre>' . json_encode($response, JSON_PRETTY_PRINT) . '</pre>';
    } catch (Exception $e) {
        echo 'Error: ' . $e->getMessage();
    }
}

Response

Python
PHP
VariationsListDTO(
    variations=[
        VariationDataDTO(
            id="VARIATION_ID",
            name="VARIATION_NAME",
            standard="VARIATION_STANDARD",
            isDisposable="VARIATION_IS_DISPOSABLE",
            options=[
                VariationOptionDTO(
                    id="VARIATION_OPTION_ID",
                    label="VARIATION_OPTION_LABEL",
                    value="VARIATION_OPTION_VALUE",
                    order="VARIATION_OPTION_ORDER",
                    default="VARIATION_OPTION_DEFAULT"
                )
            ]
        )
    ],
    pagination=PaginationDTO(
        records="PAGINATION_RECORDS",
        limit="PAGINATION_LIMIT",
        offset="PAGINATION_OFFSET",
        nextPage="PAGINATION_NEXT_PAGE_URL",
        previousPage="PAGINATION_PREVIOUS_PAGE_URL"
    )
)
{
  "variations": [
    {
      "id": "VARIATION_ID",
      "name": "VARIATION_NAME",
      "standard": "VARIATION_STANDARD",
      "is_disposable": "BOOLEAN",
      "options": [
        {
          "id": "OPTION_ID",
          "label": "OPTION_LABEL",
          "value": "OPTION_VALUE",
          "order": "OPTION_ORDER",
          "default": "BOOLEAN",
          "image": "OPTION_IMAGE_URL"
        }
      ]
    }
  ],
  "pagination": {
    "records": "TOTAL_RECORDS",
    "limit": "PAGE_LIMIT",
    "offset": "PAGE_OFFSET",
    "previous_page": "PREVIOUS_PAGE_URL",
    "next_page": "NEXT_PAGE_URL"
  }
}

Getting Specific Variation Information

Function: admin_variation_get_info()

Purpose

This function retrieves detailed information about a specific product variation, such as its configuration and option list. It is designed to support deeper insights into individual variations used in product definitions on e-commerce platforms.

Parameters

Parameter Type Description
id String The unique identifier of the product variation.

Use Case

The admin_variation_get_info() function is used by administrators to fetch the configuration and available options of a specific product variation. This is helpful when auditing, editing, or applying variation data to products, ensuring accurate and consistent product setup across the catalog.

Python
PHP
def admin_variation_get_info():
    SDKConfig.PRINT_REQUEST_DATA = True
    SDKConfig.PRINT_RAW_RESPONSE = True
    webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())

    try:
        response = webcommander_sdk.admin_variation.info(id="id")
        print(response)
    except WCException as ab:
        print(ab)
        print(ab.get_errors())
        print(ab.raw_response)
public function adminVariationGetInfo()
    {
        $variationId = 'VARIATION_ID';
        try {
            $response = $this->AdminVariationsService->ReadAdminVariationById($variationId, 'v4');
            echo '<pre>' . json_encode($response, JSON_PRETTY_PRINT) . '</pre>';
        } catch (Exception $e) {
            echo 'Error: ' . $e->getMessage();
        }
    }

Response

Python
PHP
VariationInfoDTO(
    variation=VariationDataDTO(
        id="VARIATION_ID",
        name="VARIATION_NAME",
        standard="VARIATION_STANDARD",
        isDisposable="VARIATION_IS_DISPOSABLE",
        options=[
            VariationOptionDTO(
                id="VARIATION_OPTION_ID",
                label="VARIATION_OPTION_LABEL",
                value="VARIATION_OPTION_VALUE",
                order="VARIATION_OPTION_ORDER",
                default="VARIATION_OPTION_DEFAULT"
            )
        ]
    )
)
{
  "variation": {
    "id": "VARIATION_ID",
    "name": "VARIATION_NAME",
    "standard": "VARIATION_STANDARD",
    "is_disposable": "BOOLEAN",
    "options": [
      {
        "id": "OPTION_ID",
        "label": "OPTION_LABEL",
        "value": "OPTION_VALUE",
        "order": "OPTION_ORDER",
        "default": "BOOLEAN",
        "image": "OPTION_IMAGE_URL"
      }
    ]
  }
}

Creating Variation

Function: admin_variation_create()

Purpose

This function empowers administrators and developers to programmatically create new product variations within an e-commerce catalog. These variations may include options such as size, color, material, or any other differentiating attribute required to present multiple configurations of a product. It is a vital part of the backend management system that streamlines inventory, enhances user experience, and supports scalable merchandising strategies. The function facilitates seamless integration of new product dimensions, reducing manual setup time and maintaining consistency across the platform.

Parameters

Parameter Type Description
name String The name of the variation.
standard String The format type such as "text", "image", or "color".
isDisposable Boolean Flag indicating whether the variation is temporary or reusable.
options List A list of VariationOptionDTO items representing the selectable choices for the variation.

Each VariationOptionDTO includes:

Field Type Description
id Integer Unique identifier for the option.
label String The display name shown to customers.
value String The value associated with the option.
order Integer Sorting order of the option.
default Boolean Indicates if this option is the default selection.

Use Case

The admin_variation_create() function is highly applicable in scenarios where a business needs to introduce product variations for enhanced customer selection. For example, when a new product is added to the catalog and requires options such as sizes (Small, Medium, Large) or colors (Red, Blue, Green), this function enables backend users to define those options with precision. Automating this process ensures that variations are accurately tied to product attributes and helps maintain a uniform structure across the catalog. By using this function, platforms can speed up their product onboarding process, ensure data integrity, and enhance the customer’s buying journey.

Python
PHP
def admin_variation_create():
    SDKConfig.PRINT_REQUEST_DATA = True
    SDKConfig.PRINT_RAW_RESPONSE = True
    webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())

    try:
        option1 = VariationOptionDTO(
            id="VARIATION_OPTION_ID_1",
            label="VARIATION_OPTION_LABEL_1",
            value="VARIATION_OPTION_VALUE_1",
            order="VARIATION_OPTION_ORDER_1",
            default="VARIATION_OPTION_DEFAULT_1"
        )
        option2 = VariationOptionDTO(
            id="VARIATION_OPTION_ID_2",
            label="VARIATION_OPTION_LABEL_2",
            value="VARIATION_OPTION_VALUE_2",
            order="VARIATION_OPTION_ORDER_2",
            default="VARIATION_OPTION_DEFAULT_2"
        )

        variation_data = VariationDataDTO(
            name="VARIATION_NAME",
            standard="VARIATION_STANDARD",
            isDisposable="VARIATION_IS_DISPOSABLE",
            options=[option1, option2]
        )
        variation_info = VariationInfoDTO(variation=variation_data)
        response = webcommander_sdk.admin_variation.create(request_data=variation_info)
        print(response)
    except WCException as ab:
        print(ab)
        print(ab.get_errors())
        print(ab.raw_response)
public function adminVariationCreate()
{
    $params = [
        "variation" => [
            "name" => "VARIATION_NAME",
            "standard" => "VARIATION_STANDARD",
            "is_disposable" => "BOOLEAN",
            "options" => [
                [
                    "label" => "OPTION_LABEL",
                    "value" => "OPTION_VALUE",
                    "order" => "OPTION_ORDER",
                    "default" => "BOOLEAN"
                ]
            ]
        ]
    ];
    try {
        $response = $this->AdminVariationsService->CreateAdminVariation($params, "API_VERSION");
        echo '<pre>' . json_encode($response, JSON_PRETTY_PRINT) . '</pre>';
    } catch (Exception $e) {
        echo 'Error: ' . $e->getMessage();
    }
}

Response

Python
PHP
VariationInfoDTO(
    variation=VariationDataDTO(
        id="VARIATION_ID",
        name="VARIATION_NAME",
        standard="VARIATION_STANDARD",
        isDisposable="VARIATION_IS_DISPOSABLE",
        options=[
            VariationOptionDTO(
                id="VARIATION_OPTION_ID_1",
                label="VARIATION_OPTION_LABEL_1",
                value="VARIATION_OPTION_VALUE_1",
                order="VARIATION_OPTION_ORDER_1",
                default="VARIATION_OPTION_DEFAULT_1"
            ),
            VariationOptionDTO(
                id="VARIATION_OPTION_ID_2",
                label="VARIATION_OPTION_LABEL_2",
                value="VARIATION_OPTION_VALUE_2",
                order="VARIATION_OPTION_ORDER_2",
                default="VARIATION_OPTION_DEFAULT_2"
            )
        ]
    )
)
{
  "variation": {
    "id": "VARIATION_ID",
    "name": "VARIATION_NAME",
    "standard": "VARIATION_STANDARD",
    "is_disposable": "BOOLEAN",
    "options": [
      {
        "id": "OPTION_ID",
        "label": "OPTION_LABEL",
        "value": "OPTION_VALUE",
        "order": "OPTION_ORDER",
        "default": "BOOLEAN",
        "image": "OPTION_IMAGE_URL"
      }
    ]
  }
}

Updating Specific Variation

Function: admin_variation_update()

Purpose

This function allows administrators to modify an existing variation for a product by updating its attributes, such as its name, structure (standard), and available options. It plays a crucial role in maintaining the flexibility of an evolving catalog, allowing updates as product offerings change. Whether renaming a variation, rearranging its options, or changing the default selection, this function helps in managing product diversity efficiently and ensures up-to-date information is reflected across the platform.

Parameters

Parameter Type Description
name String The updated name of the variation.
standard String The updated format type.
isDisposable Boolean Updated flag indicating whether the variation is temporary or reusable.
options List A list of VariationOptionDTO items representing the updated selectable choices.

Each VariationOptionDTO includes:

Field Type Description
id Integer Unique identifier for the option.
label String The display name shown to customers.
value String The updated value or reference for the option.
order Integer Updated sorting order of the option.
default Boolean Indicates if this option is now the default selection.

Use Case

The admin_variation_update() function is designed for scenarios where existing variations need to be updated to reflect changes in the product's attributes or business strategy. For example, a t-shirt variation labeled "Shirt 2023" with options for Small and Medium sizes may need to be renamed or its default option changed. This function allows such modifications to be made easily and programmatically, ensuring consistency across product listings, improving accuracy, and eliminating the need for manual intervention.

Python
PHP
def admin_variation_update():
    SDKConfig.PRINT_REQUEST_DATA = True
    SDKConfig.PRINT_RAW_RESPONSE = True
    webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())

    try:
        option1 = VariationOptionDTO(
            id="VARIATION_OPTION_ID_1",
            label="VARIATION_OPTION_LABEL_1",
            value="VARIATION_OPTION_VALUE_1",
            order="VARIATION_OPTION_ORDER_1",
            default="VARIATION_OPTION_DEFAULT_1"
        )
        option2 = VariationOptionDTO(
            id="VARIATION_OPTION_ID_2",
            label="VARIATION_OPTION_LABEL_2",
            value="VARIATION_OPTION_VALUE_2",
            order="VARIATION_OPTION_ORDER_2",
            default="VARIATION_OPTION_DEFAULT_2"
        )

        variation_data = VariationDataDTO(
            name="VARIATION_NAME_UPDATED",
            standard="VARIATION_STANDARD",
            isDisposable="VARIATION_IS_DISPOSABLE",
            options=[option1, option2]
        )
        variation_info = VariationInfoDTO(variation=variation_data)
        response = webcommander_sdk.admin_variation.update(id="VARIATION_ID", request_data=variation_info)
        print(response)
    except WCException as ab:
        print(ab)
        print(ab.get_errors())
        print(ab.raw_response)
public function adminVariationUpdate()
{
    $variationId = "VARIATION_ID";
    $params = [
        "variation" => [
            "name" => "VARIATION_NAME",
            "standard" => "VARIATION_STANDARD",
            "is_disposable" => "BOOLEAN",
            "options" => [
                [
                    "id" => "OPTION_ID",
                    "label" => "OPTION_LABEL",
                    "value" => "OPTION_VALUE",
                    "order" => "OPTION_ORDER",
                    "default" => "BOOLEAN"
                ]
            ]
        ]
    ];
    try {
        $response = $this->AdminVariationsService->UpdateAdminVariation($variationId, $params, "API_VERSION");
        echo '<pre>' . json_encode($response, JSON_PRETTY_PRINT) . '</pre>';
    } catch (Exception $e) {
        echo 'Error: ' . $e->getMessage();
    }
}

Response

Python
PHP
VariationInfoDTO(
    variation=VariationDataDTO(
        id="VARIATION_ID",
        name="VARIATION_NAME_UPDATED",
        standard="VARIATION_STANDARD",
        isDisposable="VARIATION_IS_DISPOSABLE",
        options=[
            VariationOptionDTO(
                id="VARIATION_OPTION_ID_1",
                label="VARIATION_OPTION_LABEL_1",
                value="VARIATION_OPTION_VALUE_1",
                order="VARIATION_OPTION_ORDER_1",
                default="VARIATION_OPTION_DEFAULT_1"
            ),
            VariationOptionDTO(
                id="VARIATION_OPTION_ID_2",
                label="VARIATION_OPTION_LABEL_2",
                value="VARIATION_OPTION_VALUE_2",
                order="VARIATION_OPTION_ORDER_2",
                default="VARIATION_OPTION_DEFAULT_2"
            )
        ]
    )
)
{
  "variation": {
    "id": "VARIATION_ID",
    "name": "VARIATION_NAME",
    "standard": "VARIATION_STANDARD",
    "is_disposable": "BOOLEAN",
    "options": [
      {
        "id": "OPTION_ID_1",
        "label": "OPTION_LABEL_1",
        "value": "OPTION_VALUE_1",
        "order": "OPTION_ORDER_1",
        "default": "BOOLEAN",
        "image": "OPTION_IMAGE_URL_1"
      },
      {
        "id": "OPTION_ID_2",
        "label": "OPTION_LABEL_2",
        "value": "OPTION_VALUE_2",
        "order": "OPTION_ORDER_2",
        "default": "BOOLEAN",
        "image": "OPTION_IMAGE_URL_2"
      }
    ]
  }
}

Deleting Variation

Function: admin_variation_delete()

Purpose

The admin_variation_delete() function is used to delete a specific variation from the system. It enables administrators to remove outdated or incorrect product configurations from the catalog, ensuring only current and relevant variations are available to customers.

Parameters

Parameter Type Description
id String The ID of the variation to be deleted.

Use Case

This function is helpful when a variation is no longer applicable, such as a discontinued product line, or when cleanup of redundant or erroneous variations is required. By using this function, administrators can maintain a clean and accurate product catalog.

Python
def admin_variation_delete():
    SDKConfig.PRINT_REQUEST_DATA = True
    SDKConfig.PRINT_RAW_RESPONSE = True
    webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())

    try:
        response = webcommander_sdk.admin_variation.delete(id="VARIATION_ID")
        print(response)
    except WCException as ab:
        print(ab)
        print(ab.get_errors())
        print(ab.raw_response)

Response

Returns a 204 No Content response code upon successful deletion, indicating the variation was successfully removed and no content is returned in the response body.

Terms and Conditions
Privacy Policy

© 2024 WebCommander | All Rights Reserved

contact@webcommander.com
1300 797 571

WebCommander
About Us
Features
Pricing
Compare
Partners
Contact Us
Resource
Find a Partner
Help Centre
Community
Blog
Solutions
Inventory Management
Omnichannel Sales
Ecommerce Automation
B2B Ecommerce
Headless Commerce
Website Design and Performance