Example #1
0
 // grab the mySQL connection
 $pdo = connectToEncryptedMySql("/etc/apache2/capstone-mysql/invtext.ini");
 // handle all RESTful calls to Product
 // get some or all Products
 if ($method === "GET") {
     // set an XSRF cookie on GET requests
     setXsrfCookie("/");
     if (empty($productId) === false) {
         if ($getLocations === true) {
             $reply->data = Product::getLocationByProductId($pdo, $productId);
         } else {
             if ($getNotifications) {
                 $reply->data = Product::getNotificationByProductId($pdo, $productId);
             } else {
                 if ($getUnitOfMeasures) {
                     $reply->data = Product::getUnitOfMeasureByProductId($pdo, $productId);
                 } else {
                     if ($getFinishedProducts) {
                         $reply->data = Product::getFinishedProductByProductId($pdo, $productId);
                     } else {
                         $product = Product::getProductByProductId($pdo, $productId);
                         $quantityOnHand = $product->getQuantityOnHand($pdo);
                         $flatObject = json_decode(json_encode($product));
                         $flatObject->quantityOnHand = $quantityOnHand;
                         $reply->data = $flatObject;
                     }
                 }
             }
         }
     } else {
         if (empty($vendorId) === false) {
Example #2
0
 /**
  * test grabbing unit of measure by the product id
  **/
 public function testGetValidUnitOfMeasurementByProductId()
 {
     // create a new product and insert to into mySQL
     $product = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title);
     $product->insert($this->getPDO());
     $quantity = 5.9;
     // create a new product and insert to into mySQL
     $productLocation = new ProductLocation($this->location->getLocationId(), $product->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity);
     $productLocation->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoUnitOfMeasureArray = Product::getUnitOfMeasureByProductId($this->getPDO(), $product->getProductId());
     for ($i = 0; $i < count($pdoUnitOfMeasureArray); $i++) {
         if ($i === 0) {
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getVendorId(), $this->vendor->getVendorId());
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getDescription(), $this->VALID_description);
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getLeadTime(), $this->VALID_leadTime);
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getSku(), $this->VALID_sku);
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getTitle(), $this->VALID_title);
         } else {
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getUnitId(), $this->unitOfMeasure->getUnitId());
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getUnitCode(), $this->unitOfMeasure->getUnitCode());
             $this->assertSame($pdoUnitOfMeasureArray[$i]->getQuantity(), $this->unitOfMeasure->getQuantity());
         }
     }
 }