Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function curl_post($url, array $post = NULL, array $options = array())
- {
- $username = 'admin';
- $password = 'admin';
- $defaults = array(
- CURLOPT_POST => 1,
- CURLOPT_HEADER => 0,
- CURLOPT_URL => $url,
- CURLOPT_FRESH_CONNECT => 1,
- CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_BINARYTRANSFER => 1,
- CURLOPT_FORBID_REUSE => 1,
- CURLOPT_TIMEOUT => 4,
- CURLOPT_USERPWD => $username . ":" . $password,
- CURLOPT_POSTFIELDS => http_build_query($post)
- );
- $ch = curl_init();
- curl_setopt_array($ch, ($options + $defaults));
- if( ! $result = curl_exec($ch))
- {
- trigger_error(curl_error($ch));
- }
- curl_close($ch);
- return $result;
- }
- function prepareProducts() {
- $product01 = array(
- 'supplier_id' => '12345',
- 'name' => 'Rumpel',
- 'supplier' => 'lcwaikiki',
- 'description_short' => 'Rumpel description+',
- 'description' => 'Rumpel very long description',
- 'category_id' => 299,
- 'category_name' => 'Jabberwocky',
- 'supplier_url' => 'http =>//microsoft.com',
- 'color' => 'red',
- 'price' => 1500,
- 'image' => 'http =>//vignette3.wikia.nocookie.net/muppet/images/5/58/Rumpelco.jpg/revision/latest?cb=20090522111255',
- 'images' => array(
- 'http =>//cdn1.stuttgarter-zeitung.de/media.media.151be88a-f2be-47c5-9e61-b5abb1e4ba89.normalized.jpeg',
- 'http =>//vignette1.wikia.nocookie.net/muppet/images/9/9f/1_Sesamstrasse_Schaf_2002.jpg/revision/latest?cb=20090522112938'
- ),
- 'variants' => array(
- array(
- 'sku' => 'rum01',
- 'name' => 'Rumpel01',
- 'price' => 1500,
- 'amount' => 7
- ),
- array(
- 'sku' => 'rum02',
- 'name' => 'Rumpel02',
- 'price' => 1600,
- 'amount' => 6
- ),
- array(
- 'sku' => 'rum03',
- 'name' => 'Rumpel03',
- 'price' => 1300,
- 'amount' => 8
- ),
- array(
- 'sku' => 'rum04',
- 'name' => 'Rumpel04',
- 'price' => 1900,
- 'amount' => 14
- ),
- )
- );
- $product02 = array(
- 'supplier_id' => '12346',
- 'name' => 'Stumpel',
- 'supplier' => 'lcwaikiki',
- 'description_short' => 'Stumpel description',
- 'description' => 'Stumpel very long description',
- 'category_id' => 302,
- 'category_name' => 'Jabberwocky',
- 'supplier_url' => 'http =>//microsoft.com',
- 'color' => 'blue',
- 'price' => 2500,
- 'image' => 'http =>//vignette3.wikia.nocookie.net/muppet/images/5/58/Rumpelco.jpg/revision/latest?cb=20090522111255',
- 'images' => array(
- 'http =>//cdn1.stuttgarter-zeitung.de/media.media.151be88a-f2be-47c5-9e61-b5abb1e4ba89.normalized.jpeg',
- 'http =>//vignette1.wikia.nocookie.net/muppet/images/9/9f/1_Sesamstrasse_Schaf_2002.jpg/revision/latest?cb=20090522112938'
- ),
- 'variants' => array(
- array(
- 'sku' => 'stum01',
- 'name' => 'Stumpel01',
- 'price' => 34500,
- 'amount' => 6
- ),
- array(
- 'sku' => 'stum02',
- 'name' => 'Stumpel02',
- 'price' => 1600,
- 'amount' => 12
- ),
- array(
- 'sku' => 'stum03',
- 'name' => 'Stumpel03',
- 'price' => 1200,
- 'amount' => 4
- ),
- )
- );
- $data = [$product01, $product02];
- return $data;
- }
- function setProduct()
- {
- $url = "http://grooger.tm/api/setProduct/";
- $data = prepareProducts();
- $post = ['data' => json_encode($data)];
- echo curl_post($url, $post);
- }
- setProduct();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement