add() public method

Adds an item to the cart
public add ( Buyable $buyable, number $quantity = 1, unknown $filter = [] ) : boolean | OrderItem
$buyable Buyable
$quantity number
$filter unknown
return boolean | OrderItem false or the new/existing item
Esempio n. 1
0
 public function testComputesReducedVatForTheRightCountry()
 {
     $shoppingCart = new ShoppingCart(new Austria());
     $article = new Article(new ArticleName('Test'), new ArticleDescription(''), new Euro(1000), new ArticleTypeReduced());
     $shoppingCart->add($article);
     $shoppingCart->add($article);
     $this->assertEquals(new Money(2200, new Currency('EUR')), $shoppingCart->total());
 }
Esempio n. 2
0
 public function addToShoppingCart(Article $article)
 {
     $this->shoppingCart->add($article);
 }
Esempio n. 3
0
?>
	</table>
</div>

<div class="col-md-12">
	<h4>Shop Cart</h4>
	<?php 
require 'shoppingCart.class.php';
$cart = new ShoppingCart();
$action = isset($_GET['action']) ? $_GET['action'] : '';
$name = isset($_GET['name']) ? $_GET['name'] : 0;
switch ($action) {
    case 'add':
        foreach ($products as $product) {
            if ($product['name'] == $name) {
                $cart->add($name);
                break;
            }
        }
        break;
    case 'empty':
        $cart->clear();
        break;
    case 'remove':
        $cart->remove($name);
        break;
}
$items = $cart->getItems();
if (!empty($items)) {
    echo '
		<table class="table">
Esempio n. 4
0
    }
    $link = preg_replace('/\\/\\//', '/', $link);
    header("HTTP/1.1 301 Moved Permanently");
    header('location: ' . $link);
    exit;
}
// Добавление в корзину
if ((int) Text::get_get('add_to_cart') > 0) {
    $id = (int) Text::get_get('add_to_cart');
    $product_set = (int) Text::get_get('product_set');
    $cart = new ShoppingCart($current_lang, $object->getLocalization());
    if ($product_set == 1) {
        // Получение комплекта товаров
        $complect = $object->getRelationList(PREF . 'catalog_set', PREF . 'catalog_items', 'item_id1', 'item_id2', $id);
        // Добавление в корзину
        $cart->add($id, 1);
        if (is_array($complect) && !empty($complect)) {
            for ($i = 0; $i < count($complect); $i++) {
                $cart->add($complect[$i]['id'], 1);
            }
        }
    } else {
        // Добавление в корзину
        $cart->add($id, 1);
    }
    if (Text::get_get('ajaxSetCart') == 1) {
        $cart_info = array('count' => $cart->count(), 'cost' => $cart->cost());
        $smarty->assign('cart', $cart_info);
        $smarty->assign('__lang', $object->getLocalization());
        $data = $smarty->fetch(DOC . 'templates/site/matches/header_cart_block.tpl');
        echo $data;