/** * Reload the REST information. * This is only a empty placeholder. The child class can override it. * * @author David Pauli <*****@*****.**> * @since 0.0.0 * @since 0.0.1 Use HTTPRequestMethod enum. * @since 0.1.0 Use a default Locale. * @since 0.1.1 Unstatic every attributes. */ private function load() { // if the REST path empty -> this is the not the implementation or can't get something else if (InputValidator::isEmpty(self::RESTPATH) || !RESTClient::setRequestMethod(HTTPRequestMethod::GET)) { return; } $content = RESTClient::sendWithLocalization(self::RESTPATH, Locales::getLocale()); // if respond is empty if (InputValidator::isEmpty($content)) { return; } // reset values $this->resetValues(); if (!InputValidator::isEmptyArrayKey($content, "name")) { $this->NAME = $content["name"]; } if (!InputValidator::isEmptyArrayKey($content, "navigationCaption")) { $this->NAVIGATIONCAPTION = $content["navigationCaption"]; } if (!InputValidator::isEmptyArrayKey($content, "description")) { $this->DESCRIPTION = $content["description"]; } // update timestamp when make the next request $timestamp = (int) (microtime(true) * 1000); $this->NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME; }
/** * Returns the quantity unit. * * @author David Pauli <*****@*****.**> * @since 0.1.0 * @api * @param String $locale The localization. * @return String Gets the quantity unit. */ public function getQuantityUnit($locale) { if (!InputValidator::isLocale($locale)) { return; } return !InputValidator::isEmptyArrayKey($this->quantityUnit, $locale) ? $this->quantityUnit[$locale] : null; }
/** * Gets the default and possible currencies of the shop. * * @author David Pauli <*****@*****.**> * @since 0.0.0 * @since 0.1.0 Use HTTPRequestMethod enum * @since 0.1.0 Save timestamp of the last request. * @since 0.1.0 Add configured used Currency. * @api */ private static function load() { // if request method is blocked if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) { return; } $content = RESTClient::send(self::RESTPATH); // if respond is empty or there are no default AND items element if (InputValidator::isEmptyArrayKey($content, "default") || InputValidator::isEmptyArrayKey($content, "items")) { Logger::error("Respond for " . self::RESTPATH . " can not be interpreted."); return; } // reset values self::resetValues(); // save the default currency self::$DEFAULT = $content["default"]; // parse the possible currencies self::$ITEMS = $content["items"]; // set the configured shop Locale if it is empty. if (InputValidator::isEmpty(self::$USED)) { self::$USED = $content["default"]; } // update timestamp when make the next request $timestamp = (int) (microtime(true) * 1000); self::$NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME; }
/** * Sets an occured error. * * @author David Pauli <*****@*****.**> * @param String $errorNumber The error number to set. * @return True if the error number is valid, false if not. * @since 0.1.2 */ private static function errorSet($errorNumber) { // if the parameter is empty or not a defined error number. if (InputValidator::isEmpty($errorNumber) || InputValidator::isEmptyArrayKey(self::$ERRORMESSAGES, $errorNumber)) { return false; } self::$ERROR = $errorNumber; return true; }
/** * This is the constructor of the Quantity object. * * @api * @author David Pauli <*****@*****.**> * @param mixed[] $quantityParameter The quantity parameter. * @since 0.2.0 */ public function __construct($quantityParameter) { if (InputValidator::isArray($quantityParameter)) { if (!InputValidator::isEmptyArrayKey($quantityParameter, "amount")) { $this->quantityAmount = $quantityParameter['amount']; } if (!InputValidator::isEmptyArrayKey($quantityParameter, "unit")) { $this->quantityUnit = $quantityParameter['unit']; } } }
/** * @group utility */ function testIsEmptyArrayKey() { $this->assertTrue(InputValidator::isEmptyArrayKey(array(), "Key")); $this->assertTrue(InputValidator::isEmptyArrayKey(array("String" => "Value"), "Key")); $this->assertTrue(InputValidator::isEmptyArrayKey(array("String" => 123), "Key")); $this->assertTrue(InputValidator::isEmptyArrayKey(array(123), "Key")); $this->assertTrue(InputValidator::isEmptyArrayKey(array("String"), "Key")); $this->assertTrue(InputValidator::isEmptyArrayKey(array("String", 123), "Key")); $this->assertFalse(InputValidator::isEmptyArrayKey(array("Key" => "Value"), "Key")); $this->assertFalse(InputValidator::isEmptyArrayKey(array("Key" => 123), "Key")); $this->assertTrue(InputValidator::isEmptyArrayKey(array("Key" => null), "Key")); $this->assertFalse(InputValidator::isEmptyArrayKey(array("Key" => ""), "Key")); }
/** * This is the constructor of the price object. * * @api * @author David Pauli <*****@*****.**> * @since 0.0.0 * @since 0.1.0 Add functionality to construct. * @param mixed[] $priceParamter The price parameter. */ public function __construct($priceParameter) { if (InputValidator::isArray($priceParameter)) { if (!InputValidator::isEmptyArrayKey($priceParameter, "amount")) { $this->amount = $priceParameter['amount']; } if (!InputValidator::isEmptyArrayKey($priceParameter, "taxType")) { $this->taxType = $priceParameter['taxType']; } if (!InputValidator::isEmptyArrayKey($priceParameter, "currency")) { $this->currency = $priceParameter['currency']; } } }
/** * This is the constructor. * * @author David Pauli <*****@*****.**> * @param String[] $paymentMethodParameter The payment method in an array to construct. * @since 0.1.3 */ public function __construct($paymentMethodParameter) { // if parameter is no string if (!InputValidator::isArray($paymentMethodParameter)) { $this->errorSet("SM-1"); Logger::error("ep6\\PaymentMethod\nThe parameter payment method paramater " . $paymentMethodParameter . " is no array."); return; } if (!InputValidator::isEmptyArrayKey($paymentMethodParameter, "id")) { $this->paymentMethodId = $paymentMethodParameter["id"]; } if (!InputValidator::isEmptyArrayKey($paymentMethodParameter, "name")) { $this->name = $paymentMethodParameter["name"]; } }
/** * This is the constructor. * * @author David Pauli <*****@*****.**> * @param String[] $shippingMethodParameter The shipping method in an array to construct. * @since 0.1.3 */ public function __construct($shippingMethodParameter) { self::errorReset(); // if parameter is no string if (!InputValidator::isArray($shippingMethodParameter)) { $this->errorSet("SM-1"); Logger::error("ep6\\ShippingMethod\nThe shipping method parameter " . $shippingMethodParameter . " is no array."); return; } if (!InputValidator::isEmptyArrayKey($shippingMethodParameter, "id")) { $this->shippingMethodId = $shippingMethodParameter["id"]; } if (!InputValidator::isEmptyArrayKey($shippingMethodParameter, "name")) { $this->name = $shippingMethodParameter["name"]; } }
/** * This is the constructor of the Price object. * * @author David Pauli <*****@*****.**> * @param mixed[] $priceParamter The price parameter to create the Price object. * @since 0.0.0 * @since 0.1.0 Add functionality to construct. * @since 0.1.1 Parse formatted attribute. */ public function __construct($priceParameter) { if (InputValidator::isArray($priceParameter)) { if (!InputValidator::isEmptyArrayKey($priceParameter, "amount")) { $this->amount = $priceParameter['amount']; } if (!InputValidator::isEmptyArrayKey($priceParameter, "taxType") && ($priceParameter['taxType'] == PriceTaxModel::GROSS || $priceParameter['taxType'] == PriceTaxModel::NET)) { $this->taxType = $priceParameter['taxType']; } if (!InputValidator::isEmptyArrayKey($priceParameter, "currency")) { $this->currency = $priceParameter['currency']; } if (!InputValidator::isEmptyArrayKey($priceParameter, "formatted")) { $this->formatted = $priceParameter['formatted']; } } }
/** * This function gets the product attributes. * * @author David Pauli <*****@*****.**> * @since 0.1.0 * @api * @param mixed[] $attribute The attribute in an array. */ public function __construct($attribute) { if (!InputValidator::isEmptyArrayKey($attribute, "key")) { $this->internName = $attribute["key"]; } if (!InputValidator::isEmptyArrayKey($attribute, "displayKey")) { $this->name = $attribute["displayKey"]; } if (!InputValidator::isEmptyArrayKey($attribute, "singleValue")) { $this->oneValue = $attribute["singleValue"]; } if (!InputValidator::isEmptyArrayKey($attribute, "type")) { $this->type = $attribute["type"]; } if (!InputValidator::isEmptyArrayKey($attribute, "type") && !InputValidator::isArray($attribute["values"])) { foreach ($attribute["values"] as $key => $value) { if (!InputValidator::isEmptyArrayKey($value, "value") && !InputValidator::isEmptyArrayKey($value, "displayValue")) { $this->values[$value["value"]] = $value["displayValue"]; } } } }
/** * Reload the REST information. * * @author David Pauli <*****@*****.**> * @since 0.0.0 * @since 0.0.1 Use HTTPRequestMethod enum. * @since 0.1.0 Use a default Locale. */ private static function load() { // if request method is blocked if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) { return; } $content = RESTClient::sendWithLocalization(self::$RESTPATH, Locales::getLocale()); // if respond is empty if (InputValidator::isEmpty($content)) { return; } // reset values self::resetValues(); if (!InputValidator::isEmptyArrayKey($content, "name")) { self::$NAME = $content["name"]; } if (!InputValidator::isEmptyArrayKey($content, "title")) { self::$TITLE = $content["title"]; } if (!InputValidator::isEmptyArrayKey($content, "navigationCaption")) { self::$NAVIGATIONCAPTION = $content["navigationCaption"]; } if (!InputValidator::isEmptyArrayKey($content, "shortDescription")) { self::$SHORTDESCRIPTION = $content["shortDescription"]; } if (!InputValidator::isEmptyArrayKey($content, "description")) { self::$DESCRIPTION = $content["description"]; } if (!InputValidator::isEmptyArrayKey($content, "company")) { self::$COMPANY = $content["company"]; } if (!InputValidator::isEmptyArrayKey($content, "contactPerson")) { self::$CONTACTPERSON = $content["contactPerson"]; } if (!InputValidator::isEmptyArrayKey($content, "contactPersonJobTitle")) { self::$CONTACTPERSONJOBTITLE = $content["contactPersonJobTitle"]; } if (!InputValidator::isEmptyArrayKey($content, "address")) { self::$ADDRESS = $content["address"]; } if (!InputValidator::isEmptyArrayKey($content, "phone")) { self::$PHONE = $content["phone"]; } if (!InputValidator::isEmptyArrayKey($content, "email")) { self::$EMAIL = $content["email"]; } // update timestamp when make the next request $timestamp = (int) (microtime(true) * 1000); self::$NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::NEXT_RESPONSE_WAIT_TIME; }
/** * Returns a large image. * * @author David Pauli <*****@*****.**> * @since 0.1.0 * @since 0.1.1 Fix bug with returning image. * @api * @param int $image The image number to get * @return Image|null The large image. */ public function getLargeImage($image) { if ($this->getCountImages() == 0 || !InputValidator::isRangedInt($image, 0, $this->getCountImages() - 1) || InputValidator::isEmptyArrayKey($this->images[$image], "Large")) { return null; } return $this->images[$image]["Large"]; }
/** * This function gets the product images. * * @author David Pauli <*****@*****.**> * @param String $productID The product ID to get images. * @since 0.1.0 * @since 0.1.1 Fix bug with nonsetted product URL and delete reload functionality. * @since 0.1.1 Use unstatic variables. * @since 0.1.2 Add error reporting. * @since 0.2.1 Implement REST client fixes. */ private function load($productID) { // if parameter is wrong if (!InputValidator::isProductId($productID)) { $this->errorSet("PS-1"); Logger::warning("ep6\\ProductSlideshow\nInvalid product ID " . $productId . " to load slideshow."); return; } // if GET is blocked if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) { $this->errorSet("RESTC-9"); return; } RESTClient::send("products/" . $productID . "/" . self::RESTPATH); $content = RESTClient::getJSONContent(); // if respond is empty if (InputValidator::isEmpty($content)) { $this->errorSet("PS-2"); Logger::warning("ep6\\ProductSlideshow\nEmpty response while getting product slideshow."); return; } // if there is items if (InputValidator::isEmptyArrayKey($content, "items")) { $this->errorSet("PS-3"); Logger::error("Respond for product slidehows can not be interpreted."); return; } // is there any images found: load the images. foreach ($content['items'] as $number => $image) { // parse every image size if (!InputValidator::isEmptyArrayKey($image, "sizes")) { $object = null; foreach ($image["sizes"] as $size) { // if there is "url" and "classifier" set in the image if (!InputValidator::isEmptyArrayKey($size, "url") && !InputValidator::isEmptyArrayKey($size, "classifier")) { $object[$size["classifier"]] = $size["url"]; } } // if all needed sizes are available, save it if (!InputValidator::isEmptyArrayKey($object, "Thumbnail") && !InputValidator::isEmptyArrayKey($object, "Small") && !InputValidator::isEmptyArrayKey($object, "HotDeal") && !InputValidator::isEmptyArrayKey($object, "MediumSmall") && !InputValidator::isEmptyArrayKey($object, "Medium") && !InputValidator::isEmptyArrayKey($object, "MediumLarge") && !InputValidator::isEmptyArrayKey($object, "Large")) { array_push($this->images, $object); } } } }
/** * This function returns the products by using the product filter. * * @author David Pauli <*****@*****.**> * @since 0.0.0 * @since 0.1.0 Use a default Locale. * @since 0.1.1 Unstatic every attributes. * @api * @return Products[] Returns an array of products. */ public function getProducts() { $parameter = $this->getParameter(); // if request method is blocked if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) { return; } $content = RESTClient::send(self::RESTPATH . "?" . $parameter); // if respond is empty if (InputValidator::isEmpty($content)) { return; } // if there is no results, page AND resultsPerPage element if (InputValidator::isEmptyArrayKey($content, "results") || InputValidator::isEmptyArrayKey($content, "page") || InputValidator::isEmptyArrayKey($content, "resultsPerPage")) { Logger::error("Respond for " . self::RESTPATH . " can not be interpreted."); return; } $products = array(); // is there any product found: load the products. if (!InputValidator::isEmptyArrayKey($content, "items") && sizeof($content['items']) != 0) { foreach ($content['items'] as $item) { $product = new Product($item); array_push($products, $product); } } return $products; }
/** * Parses the REST response data and save it. * * @author David Pauli <*****@*****.**> * @param Array $orderParameter The order in an array. * @since 0.1.3 */ private function parseData($orderParameter) { // if the product comes from the shop API if (InputValidator::isArray($orderParameter) && !InputValidator::isEmptyArrayKey($orderParameter, "orderId")) { $this->orderId = $orderParameter['orderId']; if (!InputValidator::isEmptyArrayKey($orderParameter, "orderNumber")) { $this->orderNumber = $orderParameter['orderNumber']; } if (!InputValidator::isEmptyArrayKey($orderParameter, "creationDate")) { $this->creationDate = new Date($orderParameter['creationDate']); } if (!InputValidator::isEmptyArrayKey($orderParameter, "billingAddress") && InputValidator::isArray($orderParameter["billingAddress"])) { $this->billingAddress = new Address($orderParameter['billingAddress']); } if (!InputValidator::isEmptyArrayKey($orderParameter, "shippingAddress") && InputValidator::isArray($orderParameter["shippingAddress"])) { $this->shippingAddress = new Address($orderParameter['shippingAddress']); } if (!InputValidator::isEmptyArrayKey($orderParameter, "invoicedOn")) { $this->invoiceDate = new Date($orderParameter['invoicedOn']); } if (!InputValidator::isEmptyArrayKey($orderParameter, "deliveredOn")) { $this->deliveryDate = new Date($orderParameter['deliveredOn']); } if (!InputValidator::isEmptyArrayKey($orderParameter, "pendingOn")) { $this->pendingDate = new Date($orderParameter['pendingOn']); } if (!InputValidator::isEmptyArrayKey($orderParameter, "archivedOn")) { $this->archiveDate = new Date($orderParameter['archivedOn']); } if (!InputValidator::isEmptyArrayKey($orderParameter, "dispatchedOn")) { $this->dispatchDate = new Date($orderParameter['dispatchedOn']); } if (!InputValidator::isEmptyArrayKey($orderParameter, "viewedOn")) { $this->viewDate = new Date($orderParameter['viewedOn']); } if (!InputValidator::isEmptyArrayKey($orderParameter, "rejectedOn")) { $this->rejectionDate = new Date($orderParameter["rejectedOn"]); } if (!InputValidator::isEmptyArrayKey($orderParameter, "closedOn")) { $this->closeDate = new Date($orderParameter["closedOn"]); } if (!InputValidator::isEmptyArrayKey($orderParameter, "paidOn")) { $this->payDate = new Date($orderParameter["paidOn"]); } if (!InputValidator::isEmptyArrayKey($orderParameter, "returnedOn")) { $this->returnDate = new Date($orderParameter["returnedOn"]); } if (!InputValidator::isEmptyArrayKey($orderParameter, "currencyId") && !InputValidator::isEmptyArrayKey($orderParameter, "taxModel")) { $priceParameter = array("taxType" => $orderParameter["taxModel"], "currency" => $orderParameter["currencyId"]); if (!InputValidator::isEmptyArrayKey($orderParameter, "grandTotal")) { $priceParameter["amount"] = $orderParameter["grandTotal"]; $this->totalPrice = new Price($priceParameter); } if (!InputValidator::isEmptyArrayKey($orderParameter, "totalBeforeTax")) { $priceParameter["amount"] = $orderParameter["totalBeforeTax"]; $this->totalWithoutTaxPrice = new Price($priceParameter); } if (!InputValidator::isEmptyArrayKey($orderParameter, "totalTax")) { $priceParameter["amount"] = $orderParameter["totalTax"]; $this->taxPrice = new Price($priceParameter); } } if (!InputValidator::isEmptyArrayKey($orderParameter, "customerComment")) { $this->customerComment = $orderParameter["customerComment"]; } if (!InputValidator::isEmptyArrayKey($orderParameter, "internalNote")) { $this->internalNote = $orderParameter["internalNote"]; } if (!InputValidator::isEmptyArrayKey($orderParameter, "shippingData")) { $shippingData = $orderParameter["shippingData"]; if (!InputValidator::isEmptyArrayKey($shippingData, "shippingMethod")) { $this->shippingMethod = new ShippingMethod($shippingData["shippingMethod"]); } if (!InputValidator::isEmptyArrayKey($shippingData, "price")) { $this->shippingPrice = new Price($shippingData["price"]); } } if (!InputValidator::isEmptyArrayKey($orderParameter, "paymentData")) { $paymentData = $orderParameter["paymentData"]; if (!InputValidator::isEmptyArrayKey($paymentData, "paymentMethod")) { $this->paymentMethod = new ShippingMethod($paymentData["paymentMethod"]); } if (!InputValidator::isEmptyArrayKey($paymentData, "price")) { $this->paymentPrice = new Price($paymentData["price"]); } } } // update timestamp when make the next request $timestamp = (int) (microtime(true) * 1000); $this->NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME; }
/** * Gets a specific Header value from response. * * @author David Pauli <*****@*****.**> * @param String headerKey The key of requested cookie. * @return String|null The value of the cookie or null of cookie is not set. * @since 0.2.1 */ public static function getHeader($headerKey) { if (!InputValidator::isEmptyArrayKey(self::$HEADERS, $headerKey)) { return self::$HEADERS[$headerKey]; } Logger::notify("pogo\\RESTClient:\nRequested header is not set."); return; }
/** * Unsets the amount of a product price. * * @author David Pauli <*****@*****.**> * @since 0.1.2 */ public function unsetAmount() { $this->errorReset(); $allowedTypes = array(ProductPriceTypes::PRICE, ProductPriceTypes::MANUFACTURER, ProductPriceTypes::ECOPARTICIPATION, ProductPriceTypes::DEPOSIT); // 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" => "remove", "path" => "/priceInfo/" . $this->type . "/amount"); RESTClient::send("product/" . $this->productID, $parameter); }
/** * This is the constructor. * * @author David Pauli <*****@*****.**> * @param String[] $addressParameter The array with information of the adddress. * @since 0.1.3 */ public function __construct($addressParameter) { self::errorReset(); // if parameter is no array if (!InputValidator::isArray($addressParameter)) { self::errorSet("A-1"); Logger::error("ep6\\Address\nThe address parameter " . $addressParameter . " is no array."); return; } if (!InputValidator::isEmptyArrayKey($addressParameter, "birthday")) { $this->birthday = $addressParameter["birthday"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "city")) { $this->city = $addressParameter["city"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "company")) { $this->company = $addressParameter["company"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "country")) { $this->country = $addressParameter["country"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "emailAddress")) { $this->emailAddress = $addressParameter["emailAddress"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "firstName")) { $this->firstName = $addressParameter["firstName"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "lastName")) { $this->lastName = $addressParameter["lastName"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "salutation")) { $this->salutation = $addressParameter["salutation"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "state")) { $this->state = $addressParameter["state"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "street")) { $this->street = $addressParameter["street"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "streetDetails")) { $this->streetDetails = $addressParameter["streetDetails"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "title")) { $this->title = $addressParameter["title"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "vatId")) { $this->VATID = $addressParameter["vatId"]; } if (!InputValidator::isEmptyArrayKey($addressParameter, "zipCode")) { $this->zipCode = $addressParameter["zipCode"]; } }
/** * This function returns the products by using the product filter. * * @author David Pauli <*****@*****.**> * @return Product[] Returns an array of products. * @since 0.0.0 * @since 0.1.0 Use a default Locale. * @since 0.1.1 Unstatic every attributes. * @since 0.1.2 Add error reporting. * @since 0.1.3 Get all results. * @since 0.2.0 Set error message for empty responses to notify. * @since 0.2.1 Implement REST client fixes. */ public function getProducts() { $this->errorReset(); $parameter = $this->getParameter(); // if request method is blocked if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) { $this->errorSet("RESTC-9"); return; } RESTClient::send(self::RESTPATH . "?" . $parameter); $content = RESTClient::getJSONContent(); // if respond is empty if (InputValidator::isEmpty($content)) { $this->errorSet("PF-8"); Logger::notify("ep6\\ProductFilter\nREST respomd for getting products is empty."); return; } // if there is no results, page AND resultsPerPage element if (InputValidator::isEmptyArrayKey($content, "results") || InputValidator::isEmptyArrayKey($content, "page") || InputValidator::isEmptyArrayKey($content, "resultsPerPage")) { $this->errorSet("PF-9"); Logger::error("ep6\\ProductFilter\nRespond for " . self::RESTPATH . " can not be interpreted."); return; } $this->results = $content['results']; $products = array(); // is there any product found: load the products. if (!InputValidator::isEmptyArrayKey($content, "items") && sizeof($content['items']) != 0) { foreach ($content['items'] as $item) { $product = new Product($item); // go to every filter foreach ($this->filters as $filter) { switch ($filter->getAttribute()) { case 'stocklevel': $value = array(); $value["stocklevel"] = $product->getStocklevel(); break; case 'price': $value = array(); $value["price"] = $product->getPrice()->getAmount(); break; case 'category': $value = array(); $value["category"] = $product->getCategories(); break; default: $value = $item; break; } if (!InputValidator::isEmptyArrayKey($value, $filter->getAttribute()) || $filter->getOperator() == FilterOperation::UNDEF) { if (!InputValidator::isArray($value[$filter->getAttribute()])) { if (!$filter->isElementInFilter($value)) { continue 2; } } } else { continue 2; } } array_push($products, $product); } } return $products; }
/** * This function finally prints the message. * * @author David Pauli <*****@*****.**> * @param String $message The message to print. * @param boolean $showStacktrace = 'false' True if a stacktrace show be shown, false if not. * @since 0.0.0 * @since 0.0.1 Restructor the output message. * @since 0.1.2 Restructure log message and print to file. */ private static function printMessage($message, $showStacktrace = false) { // build output $output = ""; if (!InputValidator::isEmptyArrayKey($_SERVER, 'REMOTE_ADDR')) { $output = $_SERVER['REMOTE_ADDR'] . " - "; } $output .= "[" . date("d/M/Y:H:i:s O") . "] "; // print message, if it is array or string if (is_array($message)) { $output .= print_r($message, true); } else { $output .= "\n" . $message; } // print stacktrace if its needed if ($showStacktrace) { $output .= "\nStacktrace:\n" . self::getStacktrace(); } switch (self::$OUT) { case LogOutput::SCREEN: echo "<pre>"; echo $output; echo "</pre>"; break; case LogOutput::FILE: $handle = fopen(self::$OUTPUT_FILE, "a"); fwrite($handle, $output); fwrite($handle, "\n===\n\n"); fclose($handle); break; } }
/** * Parses the REST response data and save it. * * @author David Pauli <*****@*****.**> * @param Array $productParameter The product in an array. * @since 0.1.3 */ private function parseData($productParameter) { // if the product comes from the shop API if (InputValidator::isArray($productParameter) && !InputValidator::isEmptyArrayKey($productParameter, "productId")) { $this->productID = $productParameter['productId']; if (!InputValidator::isEmptyArrayKey($productParameter, "forSale")) { $this->forSale = $productParameter['forSale']; } if (!InputValidator::isEmptyArrayKey($productParameter, "specialOffer")) { $this->specialOffer = $productParameter['specialOffer']; } if (!InputValidator::isEmptyArrayKey($productParameter, "name")) { $this->name = $productParameter['name']; } if (!InputValidator::isEmptyArrayKey($productParameter, "shortDescription")) { $this->shortDescription = $productParameter['shortDescription']; } if (!InputValidator::isEmptyArrayKey($productParameter, "description")) { $this->description = $productParameter['description']; } if (!InputValidator::isEmptyArrayKey($productParameter, "availabilityText")) { $this->availabilityText = $productParameter['availabilityText']; } if (!InputValidator::isEmptyArrayKey($productParameter, "productNumber")) { $this->productNumber = $productParameter['productNumber']; } if (!InputValidator::isEmptyArrayKey($productParameter, "energyLabelsString")) { $this->energyLabelsString = $productParameter['energyLabelsString']; } if (!InputValidator::isEmptyArrayKey($productParameter, "manufacturer")) { $this->manufacturer = $productParameter['manufacturer']; } if (!InputValidator::isEmptyArrayKey($productParameter, "upc")) { $this->UPC = $productParameter['upc']; } if (!InputValidator::isEmptyArrayKey($productParameter, "ean")) { $this->EAN = $productParameter['ean']; } if (!InputValidator::isEmptyArrayKey($productParameter, "essentialFeatures")) { $this->essentialFeatures = $productParameter['essentialFeatures']; } if (!InputValidator::isEmptyArrayKey($productParameter, "searchKeywords")) { $this->searchKeywords = $productParameter['searchKeywords']; } if (!InputValidator::isEmptyArrayKey($productParameter, "visibility")) { $this->visibility = $productParameter['visibility']; } if (!InputValidator::isEmptyArrayKey($productParameter, "deliveryPeriod")) { $this->deliveryPeriod = $productParameter['deliveryPeriod']; } if (!InputValidator::isEmptyArrayKey($productParameter, "deliveryWeight")) { $this->deliveryWeight = new Quantity($productParameter['deliveryWeight']); } if (!InputValidator::isEmptyArrayKey($productParameter, "availibility") && ($productParameter['availibility'] == ProductAvailibility::ONSTOCK || $productParameter['availibility'] == ProductAvailibility::WARNSTOCK || $productParameter['availibility'] == ProductAvailibility::OUTSTOCK)) { $this->availibility = $productParameter['availibility']; } if (!InputValidator::isEmptyArrayKey($productParameter, "energyLabelSourceFile")) { $this->energyLabelSourceFile = $productParameter['energyLabelSourceFile']; } // parse images if (!InputValidator::isEmptyArrayKey($productParameter, "images")) { foreach ($productParameter['images'] as $image) { if (InputValidator::isArray($image) && !InputValidator::isEmptyArrayKey($image, "classifier") && !InputValidator::isEmptyArrayKey($image, "url")) { $this->images[$image['classifier']] = new Image($image['url']); } } } // parse price if (!InputValidator::isEmptyArrayKey($productParameter, "priceInfo")) { $priceInformation = $productParameter['priceInfo']; if (!InputValidator::isEmptyArrayKey($priceInformation, "price") && !InputValidator::isEmptyArrayKey($priceInformation, "quantity")) { $this->price = new ProductPrice($this->productID, ProductPriceType::PRICE, $priceInformation['price'], $priceInformation['quantity']); } if (!InputValidator::isEmptyArrayKey($priceInformation, "depositPrice")) { $this->depositPrice = new ProductPrice($this->productID, ProductPriceType::DEPOSIT, $priceInformation['depositPrice'], $priceInformation['quantity']); } if (!InputValidator::isEmptyArrayKey($priceInformation, "ecoParticipationPrice")) { $this->ecoParticipationPrice = new ProductPrice($this->productID, ProductPriceType::ECOPARTICIPATION, $priceInformation['ecoParticipationPrice'], $priceInformation['quantity']); } if (!InputValidator::isEmptyArrayKey($priceInformation, "priceWithDeposits")) { $this->withDepositPrice = new ProductPrice($this->productID, ProductPriceType::WITHDEPOSITS, $priceInformation['priceWithDeposits'], $priceInformation['quantity']); } if (!InputValidator::isEmptyArrayKey($priceInformation, "manufacturerPrice")) { $this->manufacturerPrice = new ProductPrice($this->productID, ProductPriceType::MANUFACTURER, $priceInformation['manufacturerPrice'], $priceInformation['quantity']); } if (!InputValidator::isEmptyArrayKey($priceInformation, "basePrice")) { $this->basePrice = new ProductPrice($this->productID, ProductPriceType::BASE, $priceInformation['basePrice'], $priceInformation['quantity']); } } } // update timestamp when make the next request $timestamp = (int) (microtime(true) * 1000); $this->NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME; }
/** * 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; }
/** * This function returns the orders by using the order filter. * * @author David Pauli <*****@*****.**> * @return Order[] Returns an array of orders. * @since 0.1.3 * @since 0.2.0 Set error message for empty responses to notify. * @since 0.2.1 Implement REST client fixes. */ public function getOrders() { $this->errorReset(); $parameter = $this->getParameter(); // if request method is blocked if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) { $this->errorSet("RESTC-9"); return; } RESTClient::send(self::RESTPATH . "?" . $parameter); $content = RESTClient::getJSONContent(); // if respond is empty if (InputValidator::isEmpty($content)) { $this->errorSet("OF-1"); Logger::notify("ep6\\OrderFilter\nREST respond for getting orders is empty."); return; } // if there is no results, page AND resultsPerPage element if (InputValidator::isEmptyArrayKey($content, "results") || InputValidator::isEmptyArrayKey($content, "page") || InputValidator::isEmptyArrayKey($content, "resultsPerPage")) { $this->errorSet("OF-2"); Logger::error("ep6\\OrderFilter\nRespond for " . self::RESTPATH . " can not be interpreted."); return; } $this->results = $content['results']; $orders = array(); // is there any order found: load the products. if (!InputValidator::isEmptyArrayKey($content, "items") && sizeof($content['items']) != 0) { foreach ($content['items'] as $item) { $order = new Order($item); // go to every filter foreach ($this->filters as $filter) { if (!InputValidator::isEmptyArrayKey($item, $filter->getAttribute()) || $filter->getOperator() == FilterOperation::UNDEF) { if (!InputValidator::isArray($item[$filter->getAttribute()])) { if (!$filter->isElementInFilter($item)) { continue 2; } } } else { continue 2; } } array_push($orders, $order); } } return $orders; }