} } } } } else { if (empty($vendorId) === false) { $reply->data = Product::getProductByVendorId($pdo, $vendorId); } else { if (empty($description) === false) { $reply->data = Product::getProductByDescription($pdo, $description); } else { if (empty($leadTIme) === false) { $reply->data = Product::getProductByLeadTime($pdo, $leadTime); } else { if (empty($sku) === false) { $reply->data = Product::getProductBySku($pdo, $sku); } else { if (empty($title) === false) { $reply->data = Product::getProductByTitle($pdo, $title)->toArray(); } else { if (is_int($page) === true && $page >= 0) { $allProducts = Product::getAllProducts($pdo, $page); $replyData = []; foreach ($allProducts as $index => $product) { $replyData[$index] = json_decode(json_encode($product)); $replyData[$index]->quantityOnHand = $product->getQuantityOnHand($pdo); } $reply->data = $replyData; } else { throw new InvalidArgumentException("no parameters given", 405); }
/** * test grabbing a Product by sku **/ public function testGetValidProductBySku() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("product"); // 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()); // grab the data from mySQL and enforce the fields match our expectations $pdoProducts = Product::getProductBySku($this->getPDO(), $product->getSku()); $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("product")); foreach ($pdoProducts as $pdoProduct) { $this->assertSame($pdoProduct->getVendorId(), $this->vendor->getVendorId()); $this->assertSame($pdoProduct->getDescription(), $this->VALID_description); $this->assertSame($pdoProduct->getLeadTime(), $this->VALID_leadTime); $this->assertSame($pdoProduct->getSku(), $this->VALID_sku); $this->assertSame($pdoProduct->getTitle(), $this->VALID_title); } }