Overview
  • Namespace
  • Class

Namespaces

  • MailChimp
    • AuthorizedApps
    • Automations
    • Batches
    • CampaignFolders
    • Campaigns
    • Conversations
    • Ecommerce
    • FileManager
    • Lists
    • Reports
    • TemplateFolders
    • Templates

Classes

  • MailChimp\AuthorizedApps\AuthorizedApps
  • MailChimp\Automations\Automations
  • MailChimp\Batches\Batches
  • MailChimp\CampaignFolders\CampaignFolders
  • MailChimp\Campaigns\Campaigns
  • MailChimp\Campaigns\Content
  • MailChimp\Campaigns\Feedback
  • MailChimp\Conversations\Conversations
  • MailChimp\Ecommerce\Carts
  • MailChimp\Ecommerce\Customers
  • MailChimp\Ecommerce\Ecommerce
  • MailChimp\Ecommerce\Orders
  • MailChimp\Ecommerce\Products
  • MailChimp\FileManager\Files
  • MailChimp\FileManager\Folders
  • MailChimp\Lists\Interests
  • MailChimp\Lists\Lists
  • MailChimp\Lists\Members
  • MailChimp\Lists\MergeFields
  • MailChimp\Lists\Segments
  • MailChimp\Lists\SignupForms
  • MailChimp\Lists\Webhooks
  • MailChimp\MailChimp
  • MailChimp\Reports\Reports
  • MailChimp\TemplateFolders\TemplateFolders
  • MailChimp\Templates\Templates
  1 <?php
  2 namespace MailChimp\Ecommerce;
  3 
  4 class Products extends Ecommerce
  5 {
  6 
  7     /**
  8      * Get information about a store’s customers.
  9      *
 10      * @param string $store_id
 11      * @param  array (optional) $query
 12      * @return object
 13      */
 14     public function getProducts($store_id, array $query = [])
 15     {
 16         return self::execute("GET", "ecommerce/stores/{$store_id}/products", $query);
 17     }
 18 
 19     /**
 20      * Get information about a store’s customers.
 21      *
 22      * @param string $store_id
 23      * @param string $product_id
 24      * @param  array (optional) $query
 25      * @return object
 26      */
 27     public function getProduct($store_id, $product_id, array $query = [])
 28     {
 29         return self::execute("GET", "ecommerce/stores/{$store_id}/products/{$product_id}", $query);
 30     }
 31 
 32     /**
 33      * Add a new product to a store
 34      *
 35      * @param string $store_id
 36      * @param string $product_id
 37      * @param string $title
 38      * @param array $variants
 39      * @param  array (optional) $optional_settings
 40      * @return object
 41      */
 42     public function addProduct($store_id, $product_id, $title, array $variants = [], array $optional_settings = null)
 43     {
 44         $optional_fields = ["handle", "url", "description", "type", "vendor", "image_url", "published_at_foreign"];
 45         $data = [
 46             "id" => $product_id,
 47             "title" => $title,
 48             "variants" => $variants
 49         ];
 50 
 51         // If the optional fields are passed, process them against the list of optional fields.
 52         if (isset($optional_settings)) {
 53             $data = array_merge($data, self::optionalFields($optional_fields, $optional_settings));
 54         }
 55         return self::execute("POST", "ecommerce/stores/{$store_id}/products", $data);
 56     }
 57 
 58     /**
 59      * Get information about a product’s variants.
 60      *
 61      * @param string $store_id
 62      * @param string $product_id
 63      * @param  array (optional) $query
 64      * @return object
 65      */
 66     public function getVariants($store_id, $product_id, array $query = [])
 67     {
 68         return self::execute("GET", "ecommerce/stores/{$store_id}/products/{$product_id}/variants", $query);
 69     }
 70 
 71     /**
 72      * Get information about a specific product variant.
 73      *
 74      * @param string $store_id
 75      * @param string $product_id
 76      * @param string $variant_id
 77      * @param  array (optional) $query
 78      * @return object
 79      */
 80     public function getVariant($store_id, $product_id, $variant_id, array $query = [])
 81     {
 82         return self::execute("GET", "ecommerce/stores/{$store_id}/products/{$product_id}/variants/{$variant_id}", $query);
 83     }
 84 
 85     /**
 86      * Add a new variant to the product.
 87      *
 88      * @param string $store_id
 89      * @param string $product_id
 90      * @param string $variant_id
 91      * @param string title.
 92      * @param array (optional) $optional_settings
 93      * @return object
 94      * TODO: expand comment
 95      */
 96     public function addVariant($store_id, $product_id, $variant_id, $title, array $optional_settings = [])
 97     {
 98         $optional_fields = ["url", "sku", "price", "inventory_quantity", "image_url", "backorders", "visibility"];
 99         $data = [
100             "id" => $variant_id,
101             "title" => $title
102         ];
103         // If the optional fields are passed, process them against the list of optional fields.
104         if (isset($optional_settings)) {
105             $data = array_merge($data, self::optionalFields($optional_fields, $optional_settings));
106         }
107         return self::execute("POST", "ecommerce/stores/{$store_id}/products/{$product_id}/variants", $data);
108     }
109 
110     /**
111      * Add or update a product variant.
112      *
113      * @param string $store_id
114      * @param string $product_id
115      * @param string $variant_id
116      * @param array $data
117      * @return object
118      */
119     public function upsertVariant($store_id, $product_id, $variant_id, array $data = [])
120     {
121         return self::execute("PUT", "ecommerce/stores/{$store_id}/products/{$product_id}/variants/{$variant_id}", $data);
122     }
123 
124     /**
125      * Update a product variant.
126      *
127      * @param string $store_id
128      * @param string $product_id
129      * @param string $variant_id
130      * @param array $data
131      * @return object
132      */
133     public function updateVariant($store_id, $product_id, $variant_id, array $data = [])
134     {
135         return self::execute("PATCH", "ecommerce/stores/{$store_id}/products/{$product_id}/variants/{$variant_id}", $data);
136     }
137 
138     /**
139      * Delete a product variant.
140      *
141      * @param string $store_id
142      * @param string $product_id
143      * @param string variant_id
144      */
145     public function deleteVariant($store_id, $product_id, $variant_id)
146     {
147         return self::execute("DELETE", "ecommerce/stores/{$store_id}/products/{$product_id}/variants/{$variant_id}");
148     }
149 
150     /**
151      * Delete a product.
152      *
153      * @param string $store_id
154      * @param string $product_id
155      */
156     public function deleteProduct($store_id, $product_id)
157     {
158         return self::execute("DELETE", "ecommerce/stores/{$store_id}/products/{$product_id}");
159     }
160 
161 
162 }
163 
API documentation generated by ApiGen