/** * test grabbing location by productId **/ public function testGetValidProductByLocationId() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("location"); // create a new location and insert to into mySQL $location = new Location(null, $this->VALID_storageCode, $this->VALID_description); $location->insert($this->getPDO()); $quantity = 5.9; // create a new location and insert to into mySQL $productLocation = new productLocation($location->getLocationId(), $this->product->getProductId(), $this->unitOfMeasure->getUnitId(), $quantity); $productLocation->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoProductArray = Location::getProductByLocationId($this->getPDO(), $location->getLocationId()); for ($i = 0; $i < count($pdoProductArray); $i++) { if ($i === 0) { $this->assertSame($pdoProductArray[$i]->getStorageCode(), $this->VALID_storageCode); $this->assertSame($pdoProductArray[$i]->getDescription(), $this->VALID_description); } else { $this->assertSame($pdoProductArray[$i]->getProductId(), $this->product->getProductId()); $this->assertSame($pdoProductArray[$i]->getVendorId(), $this->product->getVendorId()); $this->assertSame($pdoProductArray[$i]->getDescription(), $this->product->getDescription()); $this->assertSame($pdoProductArray[$i]->getSku(), $this->product->getSku()); $this->assertSame($pdoProductArray[$i]->getTitle(), $this->product->getTitle()); } } }
/** * test grabbing a Product by alertId **/ public function testGetValidProductByAlertId() { // count the number of rows and save it for later $numRows = $this->getConnection()->getRowCount("alertLevel"); // create a new alertLevel and insert to into mySQL $alertLevel = new AlertLevel(null, $this->VALID_alertCode, $this->VALID_alertFrequency, $this->VALID_alertPoint, $this->VALID_alertOperator); $alertLevel->insert($this->getPDO()); // create a new productAlert and insert to into mySQL $productAlert = new productAlert($alertLevel->getAlertId(), $this->product->getProductId(), true); $productAlert->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoProductArray = AlertLevel::getProductByAlertId($this->getPDO(), $alertLevel->getAlertId()); for ($i = 0; $i < count($pdoProductArray); $i++) { if ($i === 0) { $this->assertSame($pdoProductArray[$i]->getAlertCode(), $this->VALID_alertCode); $this->assertSame($pdoProductArray[$i]->getAlertFrequency(), $this->VALID_alertFrequency); $this->assertSame($pdoProductArray[$i]->getAlertPoint(), $this->VALID_alertPoint); $this->assertSame($pdoProductArray[$i]->getAlertOperator(), $this->VALID_alertOperator); } else { $this->assertSame($pdoProductArray[$i]->getProductId(), $this->product->getProductId()); $this->assertSame($pdoProductArray[$i]->getVendorId(), $this->product->getVendorId()); $this->assertSame($pdoProductArray[$i]->getDescription(), $this->product->getDescription()); $this->assertSame($pdoProductArray[$i]->getSku(), $this->product->getSku()); $this->assertSame($pdoProductArray[$i]->getTitle(), $this->product->getTitle()); } } }
public static function create(Product $oProduct) { $oCartProduct = new CartProduct(); $oCartProduct->setImage($oProduct->getImage()); $oCartProduct->setId($oProduct->getId()); $oCartProduct->setDescription($oProduct->getDescription()); $oCartProduct->setName($oProduct->getName()); $oCartProduct->setPrice($oProduct->getPrice()); return $oCartProduct; }
public function add(Product $toBeAdded) { $stmt = $this->database->prepare("INSERT INTO `store`.`Products` (\n\t\t\t`pk` , `title` , `description` , `price` )\n\t\t\t\tVALUES (?, ?, ?, ?)"); if ($stmt === FALSE) { throw new \Exception($this->database->error); } $pk = $toBeAdded->getUniqueString(); $title = $toBeAdded->getTitle(); $description = $toBeAdded->getDescription(); $price = $toBeAdded->getPrice(); $stmt->bind_param('sssd', $pk, $title, $description, $price); $stmt->execute(); }
/** * Hozzá adja, elmenti az adatbázisban az új termék adatait. * * @param Product $product * @return Exception|string */ public function productAddStore($product) { //die("temrék neve: " . $product->getName()); if ($this->checkProductExist($product->getName()) === FALSE) { try { self::$conn->preparedInsert("termekek", array("nev", "kat_azon", "kisz_azon", "suly", "egysegar", "min_keszlet", "min_rend", "kim_azon", "akcio", "reszletek", "kep"), array($product->getName(), $product->getCategory(), $product->getPackage(), $product->getWeight(), $product->getPrice(), $product->getMinStock(), $product->getMinOrder(), $product->getHighlight(), $product->getDiscount(), $product->getDescription(), $product->getImg())); //die("Sql után!"); } catch (Exception $e) { return new Exception("Nem sikerült elmenteni a terméket!"); } //$stmt = $conn->preparedQuery("SELECT t_azon FROM termekek WHERE nev=?",array("$name")); return "Sikeres termék felvitel!"; } else { return "Létezik már ilyen termék!"; } }
public function create(SubCategory $sub_category, $name, $description, $price, $img, $stock) { $errors = array(); $product = new Product($this->db); try { $product->setSubCategory($sub_category); $product->setName($name); $product->setDescription($description); $product->setPrice($price); $product->setImg($img); $product->setStock($stock); } catch (Exception $e) { $errors[] = $e->getMessage(); } $errors = array_filter($errors, function ($val) { return $val !== true; }); if (count($errors) == 0) { $idSubCategory = intval($product->getIdSubCategory()); $name = $this->db->quote($product->getName()); $description = $this->db->quote($product->getDescription()); $price = $this->db->quote($product->getPrice()); $img = $this->db->quote($product->getImg()); $stock = $this->db->quote($product->getStock()); $query = "INSERT INTO product(id_sub_category, name, description, price, img, stock) VALUES('" . $idSub_category . "', " . $name . ", " . $description . ", " . $price . ", " . $img . ", " . $stock . ")"; $res = $this->db->exec($query); if ($res) { $id = $this->db->lastInsertId(); if ($id) { return $this->findById($id); } else { return "Internal Server error"; } } } else { return $errors; } }
/** * test grabbing a Product by description **/ public function testGetValidProductByDescription() { // create a new Product $newProduct = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title); $newProduct->insert($this->getPDO()); // grab the data from guzzle and enforce the status' match our expectations $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/product/?description=' . $newProduct->getDescription()); $this->assertSame($response->getStatusCode(), 200); $body = $response->getBody(); // echo $body . PHP_EOL; $product = json_decode($body); $this->assertSame(200, $product->status); }
/** * test grabbing an product by alert Id **/ public function testGetValidNotificationsByAlertId() { // create a new notification and insert to into mySQL $notification = new Notification(null, $this->alertLevel->getAlertId(), $this->VALID_emailStatus, $this->VALID_notificationDateTime, $this->VALID_notificationHandle, $this->VALID_notificationContent); $notification->insert($this->getPDO()); // grab the data from mySQL and enforce the fields match our expectations $pdoProductArray = Notification::getProductByAlertId($this->getPDO(), $notification->getAlertId()); for ($i = 0; $i < count($pdoProductArray); $i++) { if ($i === 0) { $this->assertSame($pdoProductArray[$i]->getAlertId(), $this->alertLevel->getAlertId()); $this->assertSame($pdoProductArray[$i]->getEmailStatus(), $this->VALID_emailStatus); $this->assertEquals($pdoProductArray[$i]->getNotificationDateTime(), $this->VALID_notificationDateTime); $this->assertSame($pdoProductArray[$i]->getNotificationHandle(), $this->VALID_notificationHandle); $this->assertSame($pdoProductArray[$i]->getNotificationContent(), $this->VALID_notificationContent); } else { $this->assertSame($pdoProductArray[$i]->getProductId(), $this->product->getProductId()); $this->assertSame($pdoProductArray[$i]->getVendorId(), $this->product->getVendorId()); $this->assertSame($pdoProductArray[$i]->getDescription(), $this->product->getDescription()); $this->assertSame($pdoProductArray[$i]->getSku(), $this->product->getSku()); $this->assertSame($pdoProductArray[$i]->getTitle(), $this->product->getTitle()); } } }
/** * test grabbing a Product by description **/ public function testGetValidProductByDescription() { // 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::getProductByDescription($this->getPDO(), $product->getDescription()); $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); } }
/** * Get cell value for Matahari catalog cell * @global Int $jng_sp_id * @global Array $sp_detail * @param String $column_key * @param Product $product * @param Int $aid * @return String */ function getMatahariCatalogCellValue($column_key, $product, $aid) { global $class_pb, $jng_sp_id, $sp_detail, $sp_values_brand, $sp_values_colors, $sp_values_navcat, $sp_values_navsubcat, $category_top_id; $lid = $sp_detail['languages_id']; if (!isset($sp_values_brand[$product->brand_id])) { $sp_brands = $class_pb->getSPbrands($product->brand_id); $sp_values_brand[$product->brand_id] = $sp_brands[$jng_sp_id]; } $product_old_function = $product->getOldProductFunction()->retrieveDetail($product->id, 'p,pd,pd2,pc,pnc,cat,pei,pci'); if ($category_top_id == '1') { if ($product_old_function['pci']['products_clear_image'] != '') { $main_image = substr($product_old_function['pci']['products_clear_image'], 23); } else { $main_image = substr($product_old_function['p']['products_image'], 23); } } else { $main_image = substr($product_old_function['p']['products_image'], 23); } $additional_images = array_values($product_old_function['pei']); $category_id = $product->category_id; $selling_points = $product->getSellingPointsAsArray($lid); switch ($column_key) { case 'Title*': if ($category_top_id == '1') { //JEWELRY $value = ucwords(strtolower($sp_values_brand[$product->brand_id])) . ' ' . $product_old_function['pd'][3]['products_name'] . ' ' . $product->getColors($lid); // $value = 'VON LORENZ' . ' ' . // $product_old_function['pd'][3]['products_name'] . ' ' . $product->getColors($lid); } else { $value = ucwords(strtolower($sp_values_brand[$product->brand_id])) . ' ' . $product->getName($lid) . ' ' . $product->getColors($lid); } break; case 'Brand': $value = $sp_values_brand[$product->brand_id]; // $value = 'VON LORENZ'; break; case 'Model': $value = ''; break; case 'Color*': $value = $product->getColors($lid); break; case 'Sale Price (Amount)*': $price = $product->getPriceSelling($jng_sp_id); $price_old = $product->getPriceSellingOld($jng_sp_id); if ($price_old <= $price) { //show blank if its not discounted $price = ''; } $value = $price; break; case 'Price (Amount)*': $price = $product->getPriceSelling($jng_sp_id); $price_old = $product->getPriceSellingOld($jng_sp_id); if ($price_old <= $price) { $price_old = $price; } $value = $price_old; break; case 'SKU*': $value = $product->getSKU($aid); break; case 'Size': //todo: translate ring sizes if ($category_top_id == '1') { if ($category_id == '29') { $value = $product->convertRingSizeToJapaneseSize($product->getLengthOrSizeAsText($aid)); } else { $value = 'One Size'; } } else { $value = $product->getLengthOrSizeAsText($aid); } break; case 'Model Number': $value = $product->getEAN($aid); break; case 'Stock': $value = $product->retrieveStockQuantity($aid); break; case 'Product Line': $value = 'Wanita'; break; case 'Normal Price (Amount)*': $value = $product->getPriceDefault(); break; case 'Normal Price (Currency)*': $value = 'IDR'; break; case 'Main Material': $value = ''; break; case 'Description*': $value = $product->getDescription($lid); break; case 'Youtube URL': $value = ''; break; case 'Highlight 1': $value = $selling_points[0]; break; case 'Highlight 2': $value = $selling_points[1]; break; case 'Highlight 3': $value = $selling_points[2]; break; case 'Highlight 4': $value = $selling_points[3]; break; case 'Highlight 5': $value = $selling_points[4]; break; case 'Highlight 6': $value = ''; break; case 'Highlight 7': $value = ''; break; case 'Highlight 8': $value = ''; break; case 'Highlight 9': $value = ''; break; case 'Highlight 10': $value = ''; break; case 'Highlight 11': $value = ''; break; case 'Highlight 12': $value = ''; break; case 'Insurance option': $value = '1'; break; case 'Handling fee (IDR)': $value = '0'; break; case 'Product Dimension': //Measurements is from Zalora Template $value = $product->displayMeasurement($lid); break; case 'Product Weight': $value = $product->displayWeight($lid); break; case 'Package Dimension (L x W x H cm)': //todo: use dynamic data $value = '40 x 35 x 3 cm'; break; case 'Certification': $value = ''; break; case 'Product Country': $value = ProductAttribute::displayAttributeName($product->id, ProductAttribute::GROUP_ID_ORIGIN, $lid); break; case 'Item Condition*': $value = 'new'; break; case 'Product Waranty': $value = ''; break; case 'Image 1*': //Currently Kristel will copy the link to this field manually. $value = $main_image; break; case 'Image 2': $value = $additional_images[0] == '' ? '' : substr($additional_images[0], 23); break; case 'Image 3': $value = $additional_images[1] == '' ? '' : substr($additional_images[1], 23); break; case 'Image 4': $value = $additional_images[2] == '' ? '' : substr($additional_images[2], 23); break; case 'Image 5': $value = $additional_images[3] == '' ? '' : substr($additional_images[3], 23); break; case 'Product Line': $value = ucfirst($product->getProductGender('1')); break; case 'Price (Currency)*': $value = 'IDR'; break; case 'Type': $value = ''; break; case 'Package Weight (Kg)': $value = 0.4; break; case 'product_id(MUST BE DELETED BEFORE UPLOAD)': $value = $product->id; break; default: $value = ''; } return $value; }