Advertisement
Guest User

cart

a guest
May 23rd, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.24 KB | None | 0 0
  1. <?php
  2. declare(strict_types = 1);
  3.  
  4. namespace Gwo\Recruitment\Cart;
  5.  
  6. use Gwo\Recruitment\Entity\Product;
  7.  
  8. /**
  9.  * Class Cart
  10.  * @package Gwo\Recruitment\Cart
  11.  */
  12.  
  13. class Cart
  14. {
  15.     private $cart = array();
  16.     private $Items = array();
  17.     private $product;
  18.     private $totalPrice;
  19.     private $item;
  20.     private $id;
  21.     private $quantity;
  22.     private $index;
  23.  
  24.     /**
  25.      * @return array
  26.      */
  27.     public function getItems(): array
  28.     {
  29.         return $this->Items;
  30.     }
  31.  
  32.     /**
  33.      * @return mixed
  34.      */
  35.     public function getIndex()
  36.     {
  37.         return $this->index;
  38.     }
  39.  
  40.     /**
  41.      * @param mixed $index
  42.      */
  43.     public function setIndex($index): void
  44.     {
  45.         $this->index = $index;
  46.     }
  47.     /**
  48.      * @return array
  49.      */
  50.     public function getCart(): array
  51.     {
  52.         return $this->cart;
  53.     }
  54.  
  55.     /**
  56.      * @param array $cart
  57.      */
  58.     public function setCart(array $cart): void
  59.     {
  60.         $this->cart = $cart;
  61.     }
  62.  
  63.     /**
  64.      * @return mixed
  65.      */
  66.     public function getId()
  67.     {
  68.         return $this->id;
  69.     }
  70.  
  71.     /**
  72.      * @param mixed $id
  73.      */
  74.     public function setId($id): void
  75.     {
  76.         $this->id;
  77.     }
  78.  
  79.     /**
  80.      * @param array $Items
  81.      */
  82.     public function setItems(array $Items): void
  83.     {
  84.         $this->Items = $Items;
  85.     }
  86.  
  87.     /**
  88.      * @return mixed
  89.      */
  90.     public function getQuantity()
  91.     {
  92.         return $this->quantity;
  93.     }
  94.  
  95.     /**
  96.      * @param Product $product
  97.      * @param mixed $quantity
  98.      * @return Cart
  99.      */
  100.     public function setQuantity(Product $product, $quantity)
  101.     {
  102.         $this->product = $product;
  103.         $this->quantity = $quantity;
  104.         return $this;
  105.     }
  106.  
  107.     /**
  108.      * @return mixed
  109.      */
  110.     public function getProduct()
  111.     {
  112.  
  113.         return $this->product;
  114.     }
  115.  
  116.     /**
  117.      * @param mixed $product
  118.      * @return Cart
  119.      */
  120.     public function setProduct($product)
  121.     {
  122.         $this->product = $product;
  123.         return $this;
  124.     }
  125.  
  126.  
  127.     /**
  128.      * @param $index
  129.      * @return mixed
  130.      */
  131.     public function getItem($index)
  132.     {
  133.         $this->index = $index;
  134.  
  135.  
  136.         return $this;
  137.     }
  138.  
  139.  
  140.     public function setItem($item)
  141.     {
  142.         $this->item = $item;
  143.         return $this;
  144.     }
  145.  
  146.     /**
  147.      * @return mixed
  148.      */
  149.  
  150.     public function getTotalPrice()
  151.     {
  152.         return $this->totalPrice =  $this->getProduct()->getUnitPrice() * $this->getQuantity();
  153.     }
  154.     //return $this->totalPrice =  count($this->getItems()) * $this->getProduct()->getUnitPrice() * $this->getQuantity();
  155.  
  156.  
  157.  
  158.     /**
  159.      * @param mixed $totalPrice
  160.      */
  161.     public function setTotalPrice($totalPrice): void
  162.     {
  163.         $this->totalPrice = $totalPrice;
  164.     }
  165.  
  166.     public function addProduct(Product $product, $quantity)
  167.     {
  168.  
  169.         // to do
  170.         $this->cart = array();
  171.         $this->product = $product;
  172.         $this->quantity = $quantity;
  173.         $this->setProduct(array($this));
  174.         $this->setItems(array($product));
  175.         $this->setTotalPrice($product);
  176.  
  177.  
  178.         return $this;
  179.     }
  180.  
  181.     public function removeProduct(Product $product)
  182.     {
  183.         // to do
  184.     }
  185.  
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement