Carts Guru - Custom Integration
  • Carts Guru - Custom Integration
  • Carts Guru API
    • Contacts
    • Carts
    • Orders
  • Data APIs
    • Request Authentication
    • Contacts Api
      • Batch
  • Custom Integration
    • PHP SDK
    • Other language
  • FAQ
  • Ressources
Powered by GitBook
On this page
  • Introduction
  • How install it ?
  • Using composer
  • Using our git
  • How to use it
  • #1 - Create a CartsGuruController class
  • #2 - Use it !
  • FAQ
  • How carts are identified ?
  1. Custom Integration

PHP SDK

PreviousCustom IntegrationNextOther language

Last updated 4 years ago

Introduction

We have developed a ready to use PHP library to allow you to connect your shop with our service in less than one.

How install it ?

Using composer

Our plugin is available via compose. Just run the following command to install it composer require cartsguru/cartsguru

Using our git

You can download the library follow this url

How to use it

#1 - Create a CartsGuruController class

Our SDK expose a CartsGuru class that you should extend to adapt it to your needs: - override the constructor to set your API credentials. - override adaptCart, adaptOrder and adaptProduct to convert your data into our API models. You can find documentation about and

Example of class

cartsguru-controller.php
<?php

require __DIR__ . '/vendor/autoload.php';

use CartsGuru\CartsGuru\CartsGuru as CartsGuru;

class CartsGuruController extends CartsGuru
{
    function __construct()
    {
        $params = array(
            'site_id' => 'your-site-id',
            'auth_key' => 'your-auth-key',
        );
        parent::__construct($params);
    }

    public function adaptCart($item)
    {
        return $item;
    }

    public function adaptOrder($item)
    {
        return $item;
    }

    public function adaptProduct($item)
    {
        return $item;
    }
}

#2 - Use it !

Send your cart

$cg = new CartsGuruController();
$cg->trackCart($cart);

A cart must be sent on each update.

Send your orders

$cg = new CartsGuruController();
$cg->trackOrder($order);

An order must be sent when it is created or state change.

Add online retargeting feature

You should insert the tag on each page that the visitor can access

$cg = new CartsGuruController();
$context = array(
    'cart' => $cart,        // Everywhere when cart exists
    'order' => $order,      // Only on the order page confirmation
    'product' => $product,  // On product page
);

$cg->generateTag($context);

FAQ

How carts are identified ?

We must distinguish two kind of cart : identified and non identified. When the visitor is logged in, we speak about identified cart. You must set the accountId field with the user email on this case. When the visitor is anonymous, it's a non identified cart. And so, you should set the visitorId field using the value of the cookie trkcg_vid

https://bitbucket.org/market-wave/cartsguru-lib-php
cart model
order model