/** * @group utility */ function testIsFloat() { $this->assertFalse(InputValidator::isFloat("String")); $this->assertFalse(InputValidator::isFloat(array())); $this->assertFalse(InputValidator::isFloat(array(1.2))); $this->assertFalse(InputValidator::isFloat(3)); $this->assertFalse(InputValidator::isFloat(null)); $this->assertTrue(InputValidator::isFloat(1.2)); $this->assertTrue(InputValidator::isFloat(-1.2)); }
/** * Sets an the amount of a product price. * * @author David Pauli <*****@*****.**> * @param float $amount The new amount of price. * @since 0.1.2 */ public function setAmount($amount) { $this->errorReset(); $allowedTypes = array(ProductPriceTypes::PRICE, ProductPriceTypes::MANUFACTURER, ProductPriceTypes::ECOPARTICIPATION, ProductPriceTypes::DEPOSIT); // if parameter is no float if (!InputValidator::isFloat($amount)) { $this->errorSet("PP-2"); Logger::warning("ep6\\ProductPrice\nAmount for product price (" . $amount . ") is not a float."); return; } // if PATCH does not work if (!RESTClient::setRequestMethod("PATCH")) { $this->errorSet("RESTC-9"); return; } // if this operation is not allowed for this price type if (InputValidator::isEmptyArrayKey($allowedTypes, $this->type)) { $this->errorSet("PP-3"); Logger::warning("ep6\\ProductPrice\nChanging product price is not allowed for this " . $this->type . " product price method."); return; } $parameter = array("op" => "add", "path" => "/priceInfo/" . $this->type . "/amount", "value" => $amount); RESTClient::send("product/" . $this->productID, $parameter); }
/** * Loads the stock level. * * @author David Pauli <*****@*****.**> * @since 0.1.0 * @param float $step The step to change. */ private function changeStockLevel($step) { // if parameter is wrong or GET is blocked if (!RESTClient::setRequestMethod(HTTPRequestMethod::PUT) || !InputValidator::isFloat($step)) { return; } $postfields = array("changeStocklevel" => $step); $content = RESTClient::send(self::$RESTPATH . "/" . $this->productID . "/" . self::$RESTPATH_STOCKLEVEL, $postfields); // if respond is empty if (InputValidator::isEmpty($content) || InputValidator::isEmptyArrayKey($content, "stocklevel")) { return; } $this->stockLevel = (double) $content["stocklevel"]; // update timestamp when make the next request $timestamp = (int) (microtime(true) * 1000); self::$NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::NEXT_RESPONSE_WAIT_TIME; }
/** * Change the stock level with a step. * * @author David Pauli <*****@*****.**> * @since 0.1.0 * @since 0.1.1 Unstatic every attributes. * @since 0.1.2 Add error reporting. * @param float $step The step to change. */ private function changeStockLevel($step) { // if parameter is wrong or GET is blocked if (!RESTClient::setRequestMethod(HTTPRequestMethod::PUT)) { self::errorSet("RESTC-9"); return; } if (!InputValidator::isFloat($step)) { self::errorSet("P-8"); Logger::error("The " . $step . " step to change the stocklevel is no float."); return; } $postfields = array("changeStocklevel" => $step); RESTClient::send(self::RESTPATH . "/" . $this->productID . "/" . self::RESTPATH_STOCKLEVEL, $postfields); $content = RESTClient::getJSONContent(); // if respond is empty if (InputValidator::isEmpty($content)) { self::errorSet("P-6"); return; } // if there are no items if (InputValidator::isEmptyArrayKey($content, "stocklevel")) { self::errorSet("P-7"); Logger::error("Respond for " . self::RESTPATH . "/" . $this->productID . "/" . self::RESTPATH_STOCKLEVEL . " can not be interpreted."); return; } $this->stockLevel = (double) $content["stocklevel"]; // update timestamp when make the next request $timestamp = (int) (microtime(true) * 1000); $this->NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME; }