Skip to content

Products

Joey de Haas edited this page Sep 19, 2022 · 18 revisions

Introduction

For how to handle the exceptions correctly, see Exceptions.

Show

To load more information see Extra Information.

use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;

$client  = new Client($token);
$service = new OrderService($client);

$product = $service->find(1);

$createdAt        = $product->createdAt();
$deletedAt        = $product->deletedAt();
$description      = $product->description();
$id               = $product->id();
$isPhysical       = $product->IsPhysical();
$publicTitle      = $product->publicTitle();
$sku              = $product->sku();
$slug             = $product->slug();
$title            = $product->title();
$type             = $product->type();
$updatedAt        = $product->updatedAt();

Index

To load more information see Extra Information.

use \PlugAndPay\Sdk\Enum\ProductIncludes;
use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;

$client  = new Client($token);
$service = new ProductService($client);

$products = $service->include(ProductIncludes::PRICING, ProductIncludes::SHIPPING)->get();

Filter

use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;
use \PlugAndPay\Sdk\Filters\ProductFilter;

$client  = new Client($token);
$service = new ProductService($client);

$products = $service->get(function(ProductFilter $filter) {
    $filter
      ->direction(\PlugAndPay\Sdk\Enum\Direction::ASC)
      ->hasLimitedStock(1)
      ->isDeleted(1)
      ->limit(10)
      ->page(1)
      ->q('Lorem')
      ->sort(\PlugAndPay\Sdk\Enum\ProductSortType::ACTIVE_SUBSCRIPTIONS)
      ->tag(['blauw', 'boek'])
      ->type(\PlugAndPay\Sdk\Enum\ProductSortType::SUBSCRIPTION);
});

Create Product

When creating an product, to load more information see Extra Information.

use \PlugAndPay\Sdk\Entity\Product;
use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;

$product = (new Product())
    ->setDescription('natoque penatibus et magnis dis parturient montes')
    ->setPhysical(true)
    ->setLedger(8001)
    ->setPublicTitle('Penatibus')
    ->setSku('70291520')
    ->setSlug('natoque-penatibus')
    ->setStock((new Stock())
        ->setEnabled(true)
        ->setHidden(false)
        ->setValue(10)
    )
    ->setTitle('Lorem Ipsum')
    ->setType(ProductType::ONE_OFF)
    ->setPricing((new Pricing())
        ->setShipping((new Shipping())
            ->setAmount(10.50)
        )
        ->setTax((new PricingTax())
            ->setRate((new TaxRate())
                ->setId(1)
            )
        )
    );

$product = $service->create($product);
$productId = $product->id();

Destroy product

use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;

$client  = new Client($token);
$service = new ProductService($client);

$productId = 12;

$service->delete($productId);

Extra Information

By using the include method you can get more information. It is important that you only request the information you need.

use \PlugAndPay\Sdk\Enum\ProductIncludes;
use \PlugAndPay\Sdk\Service\Client;
use \PlugAndPay\Sdk\Service\ProductService;

$client  = new Client($token);
$service = new ProductService($client);

$service
    ->include(
        ProductIncludes::PRICING,
        ProductIncludes::SHIPPING,
    )
    ->find(1);
Clone this wiki locally