PHP code example of stnc / shopping-cart

1. Go to this page and download the library: Download stnc/shopping-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/ */

    

stnc / shopping-cart example snippets


composer 


       
        // use use \Stnc\ShoppingCart\Cart;
$cart_name = 'stnc'; // sepetin session değerine bir değer atadık
$cart = new Cart($cart_name);
$cart->groups=false;

$data = array(
		'productID' => 100,
		'productName' => "ice cream",
		'productImageURL' => "https://example.org/icecream.jpg",
		'URL' => "https://example.org/product/100",
		'price' => 40.99,
		"totalEach" => 1,
		'stockUnit'=>'unit',
		"totalPrice" => 40.99
);
$cart->addToCart("100", $data);
	  echo '<pre>';
	  print_r($cart->getArray());
	  echo '</pre>';

   $cart->removeCart(100);
	  echo '<pre>';
	  print_r($cart->getArray());
	  echo '</pre>';

   $cart->getJson();

   $cart->emptyCart();
 	  echo '<pre>';
	  print_r($cart->getArray());
	  echo '</pre>';

	  echo '<pre>';
	  print_r($cart->getArray());
	  echo '</pre>';

	  print_r($cart->cartCount());

	  print_r($cart->cartInfo());