1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
-
- namespace App\Model\Module;
-
- Use App\Model\Module\Inventori;
-
- class AuctionSale
- {
- public $items = null;
- public $totalQty = 0;
- public $totalPrice = 0;
-
- public function __construct($oldCart)
- {
- if ($oldCart){
- $this->items=$oldCart->items;
- $this->totalQty=$oldCart->totalQty;
- $this->totalPrice=$oldCart->totalPrice;
- }
- }
-
- public function add($item, $id, $harga, $barcode){
- // $inv = Inventori::where('_id',$id)->first();
- $storedItem = ['qty'=>0,'price'=>$harga, 'item'=>$item, 'barcode'=>array()];
- if($this->items){
- if(array_key_exists($id, $this->items))
- {
- $storedItem = $this->items[$id];
- }
- }
- $storedItem['qty']++;
- $storedItem['price'] = $harga * $storedItem['qty'];
- array_push($storedItem['barcode'], $barcode);
- $this->items[$id] = $storedItem;
- $this->totalQty++;
- $this->totalPrice += $harga;
- }
- }
|