2017 © Pedro PelΓ‘ez
 

library cart

Shopping Cart component

image

mindy/cart

Shopping Cart component

  • Thursday, February 22, 2018
  • by max107
  • Repository
  • 0 Watchers
  • 0 Stars
  • 64 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 2 % Grown

The README.md

ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ Ρ€Π°Π±ΠΎΡ‚Ρ‹ с ΠΊΠΎΡ€Π·ΠΈΠ½ΠΎΠΉ покупатСля

Build Status codecov Latest Stable Version Total Downloads FOSSA Status, (*1)

Установка

composer require mindy/cart --prefer-dist

ИспользованиС

Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΡ ΠΊΠΎΡ€Π·ΠΈΠ½Ρ‹

На Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ доступно 2 Ρ…Ρ€Π°Π½ΠΈΠ»ΠΈΡ‰Π° SymfonySessionStorage ΠΈ NativeSessionStorage., (*2)

// Symfony
$session = new Session(new MockArraySessionStorage());
$cart = new Cart(new SymfonySessionStorage($session));
// Native $_SESSION
$cart = new Cart(new NativeSessionStorage());

Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ

Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ простого класса Ρ‚ΠΎΠ²Π°Ρ€Π°, (*3)

<?php

declare(strict_types=1);

use Mindy\Cart\ProductInterface;

class SimpleProduct implements ProductInterface
{
    /**
     * @var float
     */
    protected $price;
    /**
     * @var string
     */
    protected $uniqueId;

    /**
     * SimpleProduct constructor.
     *
     * @param array $data
     */
    public function __construct(array $data)
    {
        foreach ($data as $key => $value) {
            if (property_exists($this, $key)) {
                $this->{$key} = $value;
            }
        }
    }

    /**
     * {@inheritdoc}
     */
    public function getPrice(): float
    {
        return (float) $this->price;
    }

    /**
     * {@inheritdoc}
     */
    public function getUniqueId(): string
    {
        return $this->uniqueId;
    }
}

ИспользованиС, (*4)

<?php

// Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ
$product = new SimpleProduct(['price' => 100, 'uniqueId' => 'foo']);
$quantity = 2;
$options = ['cpu' => 'xeon', 'memory' => '4'];
$cart->add($product, $quantity, $options);
assert(1, count($cart->all()));

$cart->add($product, $quantity, $options);
assert(2, count($cart->all()));

$cart->add($product, $quantity, $options, true); // Π—Π°ΠΌΠ΅Π½Π° ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ
assert(1, count($cart->all()));

// ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° наличия ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ
$cart->has($product, $options);

// Π£Π΄Π°Π»Π΅Π½ΠΈΠ΅ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ
$cart->remove($product, $options);

// Поиск ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ
$position = $cart->find($product, $options);

// ВсС ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ
$cart->all();

// ΠžΡ‡ΠΈΡΡ‚ΠΊΠ°
$cart->clear();

// Π”ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ количСства
$cart->setQuantity($key, 5);

// ИзмСнСниС количСства
$cart->setQuantity($key, 5, true);

// ИзмСнСниС количСства - Π°Π»ΡŒΡ‚Π΅Ρ€Π½Π°Ρ‚ΠΈΠ²Π½Ρ‹ΠΉ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚
$position = $cart->get($key);
$position->setQuantity($position->getQuantity() + 2);
$cart->replace($key, $position);

License

FOSSA Status, (*5)

The Versions

22/02 2018

dev-master

9999999-dev

Shopping Cart component

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maksim Falaleev

22/02 2018

2.2.1

2.2.1.0

Shopping Cart component

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maksim Falaleev

22/02 2018

2.2

2.2.0.0

Shopping Cart component

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maksim Falaleev

22/02 2018

2.1

2.1.0.0

Shopping Cart component

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maksim Falaleev

22/02 2018

2.0

2.0.0.0

Shopping Cart component

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maksim Falaleev

24/01 2018

1.1

1.1.0.0

Shopping Cart component

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maksim Falaleev

23/01 2018

1.0

1.0.0.0

Shopping Cart component

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maksim Falaleev

19/07 2016

1.0.3

1.0.3.0

Shopping cart component

  Sources   Download

MIT

The Requires

 

The Development Requires

19/07 2016

1.0.2

1.0.2.0

Shopping cart component

  Sources   Download

MIT

The Requires

 

The Development Requires

19/07 2016

1.0.1

1.0.1.0

Shopping cart component

  Sources   Download

MIT

The Requires

 

The Development Requires