Skip to content

Product

Paride Azzari edited this page Aug 24, 2024 · 1 revision

This entrypoint allows to manage your products and your subscriptions, and upload images of your products.

The product model has the following properties:

[
    'id' => int,
    'product_desc' => string,
    'product_name' => string,
    'product_options' => array,
    'product_price' => double,
    'product_short_desc' => string,
    'sku' => string,
    'status' => int,
    'subscription_only' => boolean,
    'subscription_plans' => array,
    'url' => string,
]

List

The list method retrieves an array with all the products.

use KeapGeek\Keap\Facades\Keap;

Keap::product()->list([
    'active' => ?bool,
    'limit' => ?int,
    'offset' => ?int
]);

This method accepts different optional parameters, to query on:

  • active is the boolean of the status of the product, if active or not.
  • limit is the amount of products to return, it defaults to 1000.
  • offset is the first item that starts the set, it defaults to 0.

Count

The count method counts the products.

use KeapGeek\Keap\Facades\Keap;

Keap::product()->count([
    'active' => ?bool
]);

This method accepts active as an optional parameter.

  • active is the boolean of the status of the product, if active or not.

Create

The create method allows to create a new product.

use KeapGeek\Keap\Facades\Keap;

Keap::product()->create([
    'product_desc' => ?string,
    'product_name' => string, //required
    'product_price' => ?double,
    'product_short_desc' => ?string,
    'sku' => string,
    'subscription_only' => boolean,
]);

The only required parameter is the product_name.

Update

The update method allows to update a product.

use KeapGeek\Keap\Facades\Keap;

Keap::product()->create($product_id, [
    'product_desc' => ?string,
    'product_name' => string, //required
    'product_price' => ?double,
    'product_short_desc' => ?string,
    'sku' => string,
    'subscription_only' => boolean,
]);

The only required parameter is the product_name. The other parameters are optional.

It will return the updated product model.

Find

The find method allows to retrieve the Product model from the id of the product.

use KeapGeek\Keap\Facades\Keap;

Keap::product()->find($product_id);

This method returns the product model or null if not found.

Delete

The delete method allows to delete a product from its id.

use KeapGeek\Keap\Facades\Keap;

Keap::product()->delete($product_id);

Upload Product Image

Via the uploadImage method you are allowed to upload a product image base64 encoded.

use KeapGeek\Keap\Facades\Keap;

Keap::product()->uploadImage(int $product_id, [
    'file_data' => string, // required
    'file_name' => string, // required, with extension
    'checksum' => string,
]);

The file_data is the image data encoded in base64. In php it can be obtained using base64_encode.

file_name is the name of the file, including the extension (only allowed: png, gif, jpg, jpeg).

The checksum is not required, but it is the checksum of the image, for verifying the integrity of the image. Use hash_file('sha256', $filePath) in PHP.

Delete Product Image

The deleteImage method deletes the image of a product.

use KeapGeek\Keap\Facades\Keap;

Keap::product()->deleteImage($product_id);

Create a Subscription

Via the createSubscription method a new subscription can be created. The subscription has a model that can be used to create a new one.

It returns the subscription model.

[
    'active' => bool,
    'cycle_type' => string, // ENUM
    'frequency' => int,
    'id' => int,
    'number_of_cycles' => int,
    'plan_price' => double,
    'subscription_plan_index' => int,
    'subscription_plan_name' => string,
    'url' => string,
]

To create a new subscription, use the following syntax:

use KeapGeek\Keap\Facades\Keap;

Keap::product()->createSubscription(int $product_id, [
    'active' => bool,
    'cycle_type' => string, //ENUM Required
    'frequency' => ?int,
    'number_of_cycles' => ?int,
    'plan_price' => double, //required
    'subscription_plan_index' => ?int,
]);

where plan_price and cycle_type are the required parameters.

The plan_price is a string that can be: "YEAR", "MONTH", "WEEK", "DAY".

It returns the created subscription model.

Find a Subscription

The findSubscription subscription method retrieves the subscription associated to a product.

use KeapGeek\Keap\Facades\Keap;

Keap::product()->findSubscription(
    int $product_id,
    int $subscription_id
);

It retuns a subscription model.

Delete a Subscription

The delete subscription method deletes the subscription associated to a product.

use KeapGeek\Keap\Facades\Keap;

Keap::product()->deleteSubscription(
    int $product_id,
    int $subscription_id
);
Clone this wiki locally