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());
 }
Exemplo n.º 2
0
    public function create(Category $category, $name, $price, $stock, $image, $description)
    {
        $errors = array();
        $item = new Item($this->db);
        try {
            $item->setCategory($category);
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
        try {
            $item->setName($name);
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
        try {
            $item->setPrice($price);
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
        try {
            $item->setStock($stock);
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
        try {
            $item->setImage($image);
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
        try {
            $item->setDescription($description);
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
        if (count($errors) == 0) {
            $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());
            $idCategory = $item->getCategory()->getId();
            $query = '	INSERT INTO item (id_category, name, price, stock, image, description)
								VALUES(' . $idCategory . ',' . $name . ',' . $price . ',' . $stock . ',' . $image . ',' . $description . ')';
            $res = $this->db->exec($query);
            if ($res) {
                $id = $this->db->lastInsertId();
                if ($id) {
                    return $this->readByID($id);
                } else {
                    throw new Exception('Internal server Error');
                }
            }
        }
    }
Exemplo n.º 3
0
 public function testSetGetPrice()
 {
     // Arrange
     $item = new Item();
     $item->setPrice(2.5);
     $expectedResult = 2.5;
     // Act
     $result = $item->getPrice();
     // Assert
     $this->assertEquals($result, $expectedResult);
 }
Exemplo n.º 4
0
 public static function buildRawExamples()
 {
     // Order persons
     echo ' 8: Initial data: <pre>';
     var_dump(\OrderPerson::getListOfTypeOrderPerson(array('forAutocompletion' => false)));
     echo '</pre>';
     // Inserting an order person
     $newOrderPerson = new \OrderPerson();
     $newOrderPerson->setEmail('*****@*****.**');
     $newOrderPerson->setFirstName('lilian');
     $newOrderPerson->setLastName('tikk');
     $newOrderPerson->insert();
     echo ' 10: After insertion: <pre>';
     var_dump(\OrderPerson::getListOfTypeOrderPerson(array('forAutocompletion' => false)));
     echo '</pre>';
     // Querying full data of an order person
     $orderPerson = new OrderPerson();
     $orderPerson->setId(3);
     $orderPerson->setCompleteOrderPerson();
     echo ' 20: Order person #3: <pre>';
     var_dump($orderPerson);
     echo '</pre>';
     // Updating data of an order person
     $orderPerson->setAddress('Pärnu, Pärnu');
     $orderPerson->update();
     echo ' 24: After updating the order person #3: <pre>';
     var_dump(\OrderPerson::getListOfTypeOrderPerson(array('forAutocompletion' => false)));
     echo '</pre>';
     // Deleting the order person #2
     $orderPerson = new \OrderPerson();
     $orderPerson->setId(2);
     $orderPerson->delete();
     echo ' 43: After deleting the order person #2: <pre>';
     var_dump(\OrderPerson::getListOfTypeOrderPerson(array('forAutocompletion' => false)));
     echo '</pre>';
     // Items
     require_once dirname(__FILE__) . '/Item.php';
     $item = new Item();
     $item->setId(1);
     $item->setName('õun');
     $item->setPrice(1.0);
     $item->setAmount(20.0);
     $item->insertItem($item);
     $item = new \shiporder\Item();
     $item->setId(2);
     $item->setName('pirn');
     $item->setPrice(2.0);
     $item->setAmount(10.0);
     $item->insertItem($item);
     $items = $item->getItems();
     var_dump($items);
 }
Exemplo n.º 5
0
 function createAction(Request $request, Application $app)
 {
     if (null === ($user = $app['session']->get('user'))) {
         return $app->redirect('/login');
     }
     $newItem = new Item();
     $newItem->setName($request->get('name'));
     $newItem->setDescription($request->get('description'));
     $newItem->setPrice($request->get('price'));
     $newItem->setCalories($request->get('calories'));
     $newItem->setAllergyInformation($request->get('allergyInformation'));
     $em = $app['orm.em'];
     $categoryRepository = $em->getRepository('Category');
     $Category = $categoryRepository->find($request->get('category'));
     $newItem->setCategory($Category);
     $file = $request->files->get('photo');
     $newItem->setPhoto($file->getClientOriginalName());
     $file = $request->files->get('photo');
     $file->move(__DIR__ . '/../public/img', $file->getClientOriginalName());
     $em->persist($newItem);
     $em->flush();
     return $app->redirect('/itemAdmin');
 }
Exemplo n.º 6
0
 /**
  * @param array $data
  */
 public function setItemsByData($data)
 {
     foreach ($data as $itemData) {
         $item = new Item();
         if (isset($itemData['item'])) {
             $itemData = array_merge($itemData, $itemData['item']);
         }
         // stop if quantity is smaller than 0
         if ($this->getProperty('quantity', $itemData, 0) < 1) {
             continue;
         }
         $item->setPrice($this->getProperty('price', $itemData, 0));
         $item->setQuantity($this->getProperty('quantity', $itemData));
         $item->setQuantityUnit($this->getProperty('quantityUnit', $itemData));
         $item->setAddress($this->getProperty('address', $itemData));
         $item->setUseProductsPrice($this->getProperty('useProductsPrice', $itemData));
         $item->setDeliveryDate($this->getProperty('deliveryDate', $itemData));
         $item->setNetShippingCosts($this->getProperty('netShippingCosts', $itemData));
         if (isset($itemData['product'])) {
             $product = new Product($this->getProperty('id', $itemData['product']));
             $item->setProduct($product);
         }
         // set account to customer
         if (isset($itemData['account']) && !isset($itemData['customer'])) {
             $itemData['customer'] = $itemData['account'];
         }
         if (isset($itemData['customer'])) {
             $customer = new Account($this->getProperty('id', $itemData['customer']), $this->getProperty('name', $itemData['customer']));
             $item->setCustomerAccount($customer);
         }
         if (isset($itemData['supplier'])) {
             $customer = new Account($this->getProperty('id', $itemData['supplier']), $this->getProperty('name', $itemData['supplier']));
             $item->setSupplierAccount($customer);
         }
         // add to items array
         $this->items[] = $item;
         // create ordered item arrays
         $customerId = 0;
         $supplierId = 0;
         if ($item->getCustomerAccount()) {
             $customerId = $item->getCustomerAccount()->getId();
         }
         if ($item->getSupplierAccount()) {
             $supplierId = $item->getSupplierAccount()->getId();
         }
         $this->customerItems[$customerId][] = $item;
         $this->customerSupplierItems[$customerId]['supplierItems'][$supplierId][] = $item;
     }
 }
 /**
  * @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;
     }
 }
Exemplo n.º 8
0
 /**
  * Initialize the object with raw data
  *
  * @param $data
  * @return Item
  */
 public static function initializeWithRawData($data)
 {
     $item = new Item();
     if (isset($data['description'])) {
         $item->setDescription($data['description']);
     }
     if (isset($data['amount'])) {
         $item->setAmount($data['amount']);
     }
     if (isset($data['price'])) {
         $item->setPrice($data['price']);
     }
     if (isset($data['vat'])) {
         $item->setVat($data['vat']);
     }
     if (isset($data['reference_id'])) {
         $item->setReferenceId($data['reference_id']);
     }
     if (isset($data['total_without_vat'])) {
         $item->setTotalWithoutVat($data['total_without_vat']);
     }
     if (isset($data['total_vat'])) {
         $item->setTotalVat($data['total_vat']);
     }
     if (isset($data['total_with_vat'])) {
         $item->setTotalWithVat($data['total_with_vat']);
     }
     if (isset($data['discount'])) {
         $item->setDiscount($data['discount']);
     }
     if (isset($data['percentage'])) {
         $item->setDiscountIsPercentage($data['percentage']);
     }
     if (isset($data['discount_description'])) {
         $item->setDiscountDescription($data['discount_description']);
     }
     return $item;
 }
Exemplo n.º 9
0
 static function getItems(Feed &$feed)
 {
     $fid = $feed->getId();
     $text = $feed->getMessage();
     static::doParse($text);
     $assocs = static::$array;
     $result = array();
     foreach ($assocs as $index => $assoc) {
         $item = new Item();
         $item->setId($fid . '_' . $index);
         $item->setFeed($feed);
         if (isset($assoc['type'])) {
             $item->setType($assoc['type']);
         } else {
             $item->setType('GLOBAL');
         }
         if (isset($assoc['description'])) {
             $item->setDescription($assoc['description']);
         }
         if (isset($assoc['global'])) {
             $item->setGlobal($assoc['global']);
         }
         if (isset($assoc['name'])) {
             $item->setName($assoc['name']);
         }
         if (isset($assoc['note'])) {
             $item->setNote($assoc['note']);
         }
         if (isset($assoc['price_digit'])) {
             $item->setPrice($assoc['price_digit']);
         }
         if (isset($assoc['price'])) {
             $item->setPriceStr($assoc['price']);
         }
         if (isset($assoc['status'])) {
             $item->setStatus($assoc['status']);
         }
         $result[] = $item;
     }
     if (!$result) {
         $item = new Item();
         $item->setId($fid . '_0');
         $item->setFeed($feed);
         $item->setType('GLOBAL');
         $item->setGlobal($text);
         $result[] = $item;
     }
     return $result;
 }