/**
  * Checks if Item price falls between bounds
  *
  * @param Item $item
  *
  * @return bool
  */
 public function isSatisfiedBy(Item $item)
 {
     if (!empty($this->maxPrice) && $item->getPrice() > $this->maxPrice) {
         return false;
     }
     if (!empty($this->minPrice) && $item->getPrice() < $this->minPrice) {
         return false;
     }
     return true;
 }
 public function isSatisfiedBy(Item $item) : bool
 {
     if ($this->maxPrice !== null && $item->getPrice() > $this->maxPrice) {
         return false;
     }
     if ($this->minPrice !== null && $item->getPrice() < $this->minPrice) {
         return false;
     }
     return true;
 }
 public function test_accessors()
 {
     /** === Test Data === */
     $STOCK_ITEM_REF = 'stock item ref';
     $PRICE = 'price';
     /** === Call and asserts  === */
     $this->obj->setStockItemRef($STOCK_ITEM_REF);
     $this->obj->setPrice($PRICE);
     $this->assertEquals($STOCK_ITEM_REF, $this->obj->getStockItemRef());
     $this->assertEquals($PRICE, $this->obj->getPrice());
 }
 /**
  * Check whether Item can be added
  * 
  * @param Item $item
  * 
  * @return boolean
  */
 public function canAddItem(Item $item)
 {
     if ($this->getTotalPrice() + $item->getPrice() > $this->maxPricePerPackage) {
         return false;
     } else {
         return true;
     }
 }
Example #5
0
 public function testSetGetPrice()
 {
     // Arrange
     $item = new Item();
     $item->setPrice(2.5);
     $expectedResult = 2.5;
     // Act
     $result = $item->getPrice();
     // Assert
     $this->assertEquals($result, $expectedResult);
 }
 /**
  * @param Subcategory $subcategory
  * @param $name
  * @param $descr
  * @param $short_descr
  * @param $price
  * @param $stock
  * @return array
  * @throws Exception
  */
 public function create(Subcategory $subcategory, $name, $descr, $short_descr, $price, $stock)
 {
     $errors = array();
     $item = new Item($this->db);
     try {
         $item->setName($name);
         $item->setDescription($descr);
         $item->setShortDescription($short_descr);
         $item->setPrice($price);
         $item->setStock($stock);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if (count($errors) == 0) {
         $name = $this->db->quote($item->getName());
         $description = $this->db->quote($item->getDescription());
         $shortDescription = $this->db->quote($item->getShortDescription());
         $price = $this->db->quote($item->getPrice());
         $stock = $this->db->quote($item->getStock());
         $query = "  INSERT INTO item(id_subcategory, name, descr, short_descr, price, stock)\n                               VALUES(" . $subcategory->getId() . ", " . $name . ", " . $description . ", " . $shortDescription . ", " . $price . ", " . $stock . ")";
         $data = $this->db->exec($query);
         if ($data) {
             $id = $this->db->lastInsertId();
             if ($id) {
                 try {
                     return $this->findById($id);
                 } catch (Exception $e) {
                     $errors[] = $e->getMessage();
                     return $errors;
                 }
             } else {
                 throw new Exception('Last insert error');
             }
         } else {
             throw new Exception('Db error');
         }
     } else {
         return $errors;
     }
 }
Example #7
0
<?php

// Start by assuming the transaction operations will all succeed
$success = TRUE;
// Give the POSTed item ID a friendly variable name
$itemID = filter_var($_POST['itemid'], FILTER_VALIDATE_INT);
//$participant = new Participant();
//$buyerID = $participant->getParticipantKey();
// Retrieve the item seller and price using some fictitious item class
$item = new Item();
$sellerID = $item->getItemOwner($itemID);
$price = $item->getPrice($itemID);
// Instantiate the mysqli class
$db = new mysqli("localhost", "website", "secret", "chapter37");
// Disable the autocommit feature
$db->autocommit(FALSE);
// Debit buyer's account
$stmt = $db->prepare("UPDATE participants SET cash = cash - ? WHERE id = ?");
$stmt->bind_param('di', $price, $buyerID);
$stmt->execute();
if ($db->affected_rows != 1) {
    $success = FALSE;
}
// Credit seller's account
$query = $db->prepare("UPDATE participants SET cash = cash + ? WHERE id = ?");
$stmt->bind_param('di', $price, $sellerID);
$stmt->execute();
if ($db->affected_rows != 1) {
    $success = FALSE;
}
// Update trunk item ownership. If it fails, set $success to FALSE
Example #8
0
     break;
 case "getItemByName":
     $item = new Item();
     print json_encode($item->getItemByName($_POST["name"]));
     break;
 case "getItemByNameWithPrice":
     $item = new Item();
     print json_encode($item->getItemByNameWithPrice($_POST["idcustomer"], $_POST["name"]));
     break;
 case "getItemLowestCost":
     $item = new Item();
     print $item->getLowestCost($_POST["iditem"]);
     break;
 case "getItemPrice":
     $item = new Item();
     print $item->getPrice($_POST["idPriceList"], $_POST["iditem"]);
     break;
 case "getItemQuantity":
     $item = new Item();
     print $item->getQuantity($_POST["iditem"]);
     break;
 case "saveInventory":
     $item = new Item();
     $max = $_POST["max"];
     $items = array();
     for ($i = 0; $i <= $max; $i++) {
         if (isset($_POST["hidItem" . $i]) && $_POST["hidItem" . $i] != "") {
             //shouldn't be empty
             $items[] = array("iditem" => $_POST["hidItem" . $i], "itemName" => $_POST["txtItem" . $i], "system" => $_POST["hidSystem" . $i], "manual" => $_POST["txtManual" . $i], "virtualStock" => $_POST["virtualStock" . $i]);
         }
     }
Example #9
0
    public function update(Item $item)
    {
        $idCategory = $item->getCategory()->getId();
        $id = intval($id);
        $name = $this->db->quote($item->getName());
        $price = $this->db->quote($item->getPrice());
        $stock = $this->db->quote($item->getStock());
        $image = $this->db->quote($item->getImage());
        $description = $this->db->quote($item->getDescription());
        $query = '	UPDATE item
							SET name=' . $name . ',
								price=' . $price . ',
								stock=' . $stock . ',
								image=' . $image . ',
								description=' . $description . ',
								id_category=' . $idCategory . '
							WHERE id=' . $id;
        $res = $this->db->exec($query);
        if ($res) {
            $id = $this->db->lastInsertId();
            if ($id) {
                return $this->findByID($id);
            } else {
                throw new Exception('Internal server Error');
            }
        }
    }
 public function testDiscountTotalPriceOver10000()
 {
     $item = new Item('RedBull', '240', '2011-07', '100');
     $number = 77;
     $item_price = $item->getPrice() * $number;
     $this->cart->addToCart($item, $number);
     $delivery_price = 0;
     $this->cart->setDeliveryType('hurry');
     $expected = $item_price + $delivery_price;
     $this->assertEquals($expected, $this->cart->getTotalPrice());
 }