PHP code example of inklabs / kommerce-core
1. Go to this page and download the library: Download inklabs/kommerce-core 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/ */
inklabs / kommerce-core example snippets
$applyToShipping = true;
$command = new CreateStateTaxRateCommand('CA', 9.5, $applyToShipping);
$this->dispatch($command);
$productId = '15dc6044-910c-431a-a578-430759ef5dcf';
$query = new GetProductQuery($productId);
/** @var GetProductResponse $response */
$response = $this->dispatchQuery($query);
$productDTO = $response->getProductDTO();
var_export($productDTO);
inklabs\kommerce\EntityDTO\ProductDTO::__set_state([
'slug' => 'test-product',
'sku' => '5b6541751fd10',
'name' => 'Test Product',
'unitPrice' => 1200,
'quantity' => 10,
'isInventoryRequired' => false,
'isPriceVisible' => true,
'isActive' => true,
'isVisible' => true,
'isTaxable' => true,
'isShippable' => true,
'isInStock' => true,
'areAttachmentsEnabled' => false,
'shippingWeight' => 16,
'description' => null,
'rating' => null,
'tags' => [],
'images' => [],
'tagImages' => [],
'options' => [],
'textOptions' => [],
'productQuantityDiscounts' => [],
'optionProducts' => [],
'productAttributes' => [],
'price' => inklabs\kommerce\EntityDTO\PriceDTO::__set_state([
'origUnitPrice' => 1200,
'unitPrice' => 1200,
'origQuantityPrice' => 1200,
'quantityPrice' => 1200,
'catalogPromotions' => [],
'productQuantityDiscounts' => []
]),
'id' => inklabs\kommerce\Lib\UUID::fromString('15dc6044-910c-431a-a578-430759ef5dcf'),
'created' => DateTime::__set_state([
'date' => '2018-08-04 06:04:26.000000',
'timezone_type' => 3,
'timezone' => 'UTC',
]),
'updated' => null,
'createdFormatted' => 'August 3, 2018 11:04 pm PDT',
'updatedFormatted' => null,
]);
// UserEntity:
public function setPassword($password)
{
$this->passwordHash = // hash the password...
$this->raise(
new PasswordChangedEvent(
$this->id,
$this->email,
$this->getFullName()
)
);
}
// UserService:
$user = $this->userRepository->findOneById($userId);
$user->setPassword($password);
$this->userRepository->update($user);
$this->eventDispatcher->dispatch($user->releaseEvents());
// CartService:
$order = Order::fromCart($cart);
$this->orderRepository->create($order);
$this->eventDispatcher->dispatchEvent(
new OrderCreatedFromCartEvent($order->getId())
);
$tag = new Entity\Tag
$tag->setName('Test Tag');
$product = new Entity\Product;
$product->setName('Test Product');
$product->setUnitPrice(500);
$product->setQuantity(1);
$product->setIsInventoryRequired(true);
$product->addTag($tag);
if ($product->inStock()) {
// Show add to cart button
}
$productRepository = $this->entityManager->getRepository(Product::class);
$productId = 1;
$product = $productRepository->findOneById($productId);
$product->setUnitPrice(600);
$productRepository->persist($product);
$product = new Entity\Product;
$product->addTag(new Entity\Tag);
$productDTO = $product->getDTOBuilder()
->withAllData(new Lib\Pricing)
->build();
echo $productDTO->sku;
echo $productDTO->price->unitPrice;
echo $productDTO->tags[0]->name;
$creditCard = new Entity\CreditCard;
$creditCard->setName('John Doe');
$creditCard->setZip5('90210');
$creditCard->setNumber('4242424242424242');
$creditCard->setCvc('123');
$creditCard->setExpirationMonth('1');
$creditCard->setExpirationYear('2020');
$chargeRequest = new Lib\PaymentGateway\ChargeRequest;
$chargeRequest->setCreditCard($creditCard);
$chargeRequest->setAmount(2000);
$chargeRequest->setCurrency('usd');
$chargeRequest->setDescription('[email protected] ');
$stripe = new Lib\PaymentGateway\StripeFake;
$charge = $stripe->getCharge($chargeRequest);
html
Product: <?=$productDTO->name