1. Go to this page and download the library: Download devanych/yii2-cart 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/ */
// Product is an AR model
$product = Product::findOne(1);
// Get component of the cart
$cart = \Yii::$app->cart;
// Add an item to the cart
$cart->add($product, $quantity);
// Adding item quantity in the cart
$cart->plus($product->id, $quantity);
// Change item quantity in the cart
$cart->change($product->id, $quantity);
// Removes an items from the cart
$cart->remove($product->id);
// Removes all items from the cart
$cart->clear();
// Get all items from the cart
$cart->getItems();
// Get an item from the cart
$cart->getItem($product->id);
// Get ids array all items from the cart
$cart->getItemIds();
// Get total cost all items from the cart
$cart->getTotalCost();
// Get total count all items from the cart
$cart->getTotalCount();
// Product is an AR model
$product = Product::findOne(1);
// Get component of the cart
$cart = \Yii::$app->cart;
// Get an item from the cart
$item = $cart->getItem($product->id);
// Get the id of the item
$item->getId();
// Get the price of the item
$item->getPrice();
// Get the product, AR model
$item->getProduct();
// Get the cost of the item
$item->getCost();
// Get the quantity of the item
$item->getQuantity();
// Set the quantity of the item
$item->setQuantity($quantity);