PHP code example of paloma / shop-client

1. Go to this page and download the library: Download paloma/shop-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

paloma / shop-client example snippets



// Create Paloma client
$factory = new Paloma\Shop\PalomaClientFactory($options);

$client = $factory->create([
    'base_url' => 'https://demo.paloma.one/api/', 
    'api_key' => 'yourAPIKey',
    'channel' => 'yourChannel',
    'locale' => 'yourLocale',
]);

// Create security service
$security = new MyPalomaSecurity(); // implements \Paloma\Shop\Security\PalomaSecurityInterface

// Create Paloma catalog
$catalog = new \Paloma\Shop\Catalog\Catalog($client, new \Paloma\Shop\Common\PricingContextProvider($security));

// Call API, e.g. fetch catalog categories
$categories = $catalog->getCategories();

// Create Symfony validator
$validator = new Validator(); // implements Symfony\Component\Validator\Validator\ValidatorInterface

// Create Paloma checkout
$checkout = new \Paloma\Shop\Checkout\Checkout($client, $security, $validator);

// Add cart item
$checkout->addCartItem('100-200', 1);


$page = $catalog->search(new SearchRequest(...));

$order = $checkout->getCart();

$order = $checkout->addCartItem('12345', 1);

$checkout->updateCartItem('123' /* order item id */, 2 /* quantity */);

$checkout->removeCartItem('123');

// Number of order items
$checkout->getCart()->itemsCount();

// Number of items times quantities
$checkout->getCart()->unitsCount();

$billingAddress = new Address(...);
$shippingAddress = new Address(...);
$checkout->setAddresses($billingAddress, $shippingAddress);

$payment = $checkout->initializePayment(new PaymentInitParameters(...));

$orderPurchase = $checkout->purchase();
echo 'Purchased order ' . $orderPurchase->getOrderNumber() . '!';