Skip to content

Instantly share code, notes, and snippets.

@carrowheap
Last active June 24, 2020 08:08
Show Gist options
  • Select an option

  • Save carrowheap/3873a2e24f882addb080668fad1da859 to your computer and use it in GitHub Desktop.

Select an option

Save carrowheap/3873a2e24f882addb080668fad1da859 to your computer and use it in GitHub Desktop.

Revisions

  1. carrowheap revised this gist Jun 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion woocomerce_create_and_send_variations.php
    Original file line number Diff line number Diff line change
    @@ -60,7 +60,7 @@ public function index()
    $resp = $client->post('products', $product);

    // post product variations
    $data = $client->post('products/' + $resp->id + '/variations', $data);
    $data = $client->post('products/' . $resp->id . '/variations', $data);


    return $this->render('default/index.html.twig', [
  2. carrowheap renamed this gist Jun 24, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. carrowheap created this gist Jun 24, 2020.
    70 changes: 70 additions & 0 deletions .php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    <?php

    namespace App\Controller;


    use Automattic\WooCommerce\Client;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    use Symfony\Component\Routing\Annotation\Route;

    class DefaultController extends AbstractController
    {

    public function index()
    {
    $client = new Client(
    'http://172.22.0.1:8090',
    'ck_4e2802c67793d32dba3237f994dbbca45577e2d5',
    'cs_796a3ab9ec3fb6bf6482280f3fcfbaa90a71a55c',
    [
    'wp_api' => true,
    'version' => 'wc/v3',
    'query_string_auth' => true,
    'verify_ssl' => false,
    'timeout' => 400, // curl timeout
    ]
    );

    // product to create
    $product = array(
    'name' => 'MAC PRO BOOK ZEND X MAN',
    'regular_price' => '537.90',
    'attributes' => array(
    array(
    'name' => 'Color', // parameter for custom attributes
    'visible' => true, // default: false
    'variation' => true,
    'options' => array(
    'RED',
    'BLUE'
    )
    )));


    // variant to send
    $data = [
    'regular_price' => '7.00',
    'manage_stock' => true,
    'stock_quantity' => 56,
    'status' => 'publish',
    'attributes' => [
    [
    'name' => 'Color',
    'option' => 'RED'
    ]
    ],
    ];


    // post product
    $resp = $client->post('products', $product);

    // post product variations
    $data = $client->post('products/' + $resp->id + '/variations', $data);


    return $this->render('default/index.html.twig', [
    'controller_name' => 'DefaultController',
    ]);
    }
    }