|
| 1 | +## Product models |
| 2 | + |
| 3 | +### Get a product model |
| 4 | + |
| 5 | +```php |
| 6 | +$client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin'); |
| 7 | + |
| 8 | +/* |
| 9 | + * Returns an array like this: |
| 10 | + * [ |
| 11 | + * 'code' => 'rain_boots_red', |
| 12 | + * 'family_variant' => 'boots_color_size', |
| 13 | + * 'parent' => 'rain_boots', |
| 14 | + * 'categories' => ['2014_collection', 'winter_collection', 'winter_boots'], |
| 15 | + * 'values' => [ |
| 16 | + * 'name' => [ |
| 17 | + * [ |
| 18 | + * 'locale' => 'en_US', |
| 19 | + * 'scope' => null, |
| 20 | + * 'data' => 'Red rain boots', |
| 21 | + * ] |
| 22 | + * ], |
| 23 | + * ], |
| 24 | + * 'created' => '2017-10-17T14:12:35+00:00', |
| 25 | + * 'updated' => '2017-10-17T14:12:35+00:00' |
| 26 | + * ] |
| 27 | + */ |
| 28 | +$productModel = $client->getProductModelApi()->get('rain_boots_red'); |
| 29 | +``` |
| 30 | + |
| 31 | +### Create a product model |
| 32 | + |
| 33 | +If the product model does not exist yet, this method creates it, otherwise it throws an exception. |
| 34 | + |
| 35 | +```php |
| 36 | +$client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin'); |
| 37 | + |
| 38 | +$client->getProductModelApi()->create('saddle_rain_boots', [ |
| 39 | + 'family_variant' => 'boots_color_size', |
| 40 | + 'parent' => 'rain_boots', |
| 41 | + 'categories' => ['2014_collection', 'winter_boots', 'winter_collection'], |
| 42 | + 'values' => [ |
| 43 | + 'name' => [ |
| 44 | + [ |
| 45 | + 'locale' => 'en_US', |
| 46 | + 'scope' => null, |
| 47 | + 'data' => 'Saddle rain boots', |
| 48 | + ] |
| 49 | + ], |
| 50 | + 'color' => [ |
| 51 | + [ |
| 52 | + 'locale' => null, |
| 53 | + 'scope' => null, |
| 54 | + 'data' => 'saddle' |
| 55 | + ] |
| 56 | + ] |
| 57 | + ] |
| 58 | +]); |
| 59 | +``` |
| 60 | + |
| 61 | +Product model values use the same format as the product values. If you want to know more, take a look at [here](/documentation/resources.html#product-values). |
| 62 | + |
| 63 | +### Get a list of product models |
| 64 | + |
| 65 | +There are two ways of getting product models. |
| 66 | + |
| 67 | +#### By getting pages |
| 68 | + |
| 69 | +This method allows to get product models page per page, as a classical pagination. |
| 70 | +It's possible to get the total number of product models with this method. |
| 71 | + |
| 72 | +```php |
| 73 | +$client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin'); |
| 74 | + |
| 75 | +$firstPage = $client->getProductModelApi()->listPerPage(50, true); |
| 76 | +``` |
| 77 | + |
| 78 | +::: warning |
| 79 | +There is a maximum limit allowed on server side for the parameter `limit`. |
| 80 | +::: |
| 81 | + |
| 82 | +::: warning |
| 83 | +Setting the parameter `with_count` to `true` can drastically decrease the performance. |
| 84 | +It's recommended to let this parameter with the default value `false` if the total number of product models is not needed in the response. |
| 85 | +::: |
| 86 | + |
| 87 | +You can get more information about this method [here](/php-client/list-resources.html#by-getting-pages). |
| 88 | + |
| 89 | +#### With a cursor |
| 90 | + |
| 91 | +This method allows to iterate the product models. It will automatically get the next pages for you. |
| 92 | + |
| 93 | +```php |
| 94 | +$client = new \Akeneo\Pim\AkeneoPimClientBuilder('http://akeneo.com/')->buildAuthenticatedByPassword('client_id', 'secret', 'admin', 'admin'); |
| 95 | + |
| 96 | +$productModels = $client->getProductModelApi()->all(50); |
| 97 | +``` |
| 98 | + |
| 99 | +:::warning |
| 100 | +There is a maximum limit allowed on server side for the parameter `pageSize`. |
| 101 | +::: |
| 102 | + |
| 103 | +You can get more information about this method [here](/php-client/list-resources.html#with-a-cursor). |
0 commit comments