/**
  * 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());
         }
     }
 }
 /**
  * test grabbing a Product by sku
  **/
 public function testGetValidProductBySku()
 {
     // 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/?sku=' . $newProduct->getSku());
     $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());
         }
     }
 }
Example #5
0
 /**
  * The row with default value
  *
  * @param UDate   $lastUpdatedInDB
  * @param Product $product
  * @param string  $preFix
  * @param bool    $debug
  *
  * @return multitype:string number
  */
 private static function _getRowWithDefaultValues(UDate $lastUpdatedInDB, Product $product = null, $preFix = '', $debug = false)
 {
     $attributeSetDefault = 'Default';
     $attributeSetName = $attributeSetDefault;
     $enabled = true;
     $sku = $statusId = $productName = $rrpPrice = $weight = $shortDescription = $fullDecription = $supplierName = $supplierCode = $manufacturerName = $asNewFrom = $asNewTo = $specialPrice = $specialPriceFromDate = $specialPriceToDate = '';
     $categoryIds = array(2);
     //default category
     if ($product instanceof Product) {
         $sku = trim($product->getSku());
         $productName = trim($product->getName());
         $shortDescription = trim($product->getShortDescription());
         $asNewFrom = $product->getAsNewFromDate() instanceof UDate ? $product->getAsNewFromDate()->format('Y-m-d H:i:sP') : '';
         $asNewTo = $product->getAsNewToDate() instanceof UDate ? $product->getAsNewToDate()->format('Y-m-d H:i:sP') : '';
         $weight = trim($product->getWeight());
         if ($product->getAttributeSet() instanceof ProductAttributeSet) {
             $attributeSetName = $product->getAttributeSet()->getName();
             self::_log('-- attributeSetName ', __CLASS__ . '::' . __FUNCTION__ . "  attributeSetName={$attributeSetName}", $preFix);
         }
         //RRP
         if (($rrp = $product->getRRP()) instanceof ProductPrice) {
             $rrpPrice = StringUtilsAbstract::getValueFromCurrency($rrp->getPrice());
         }
         //special price
         if (($specialPriceObj = $product->getNearestSpecialPrice()) instanceof ProductPrice) {
             $specialPrice = StringUtilsAbstract::getValueFromCurrency($specialPriceObj->getPrice());
             $specialPriceFromDate = $specialPriceObj->getStart()->format('Y-m-d H:i:sP');
             $specialPriceToDate = $specialPriceObj->getEnd()->format('Y-m-d H:i:sP');
             if ($specialPrice == 0) {
                 $specialPrice = '';
                 $specialPriceFromDate = '1990-10-10';
                 $specialPriceToDate = '2009-10-10';
             }
         } else {
             // delete the special price
             //$specialPrice = StringUtilsAbstract::getValueFromCurrency('99999999');
             //$specialPrice = '9999999';
             $specialPrice = '';
             $specialPriceFromDate = '1990-10-10';
             $specialPriceToDate = '2009-10-10';
         }
         // if it is the daily promotion time then overwrite the special price with the daily special price
         $isDailyPromotionTime = intval(SystemSettings::getSettings(SystemSettings::TYP_ISDAILYPROMOTIONTIME));
         if ($isDailyPromotionTime === 1) {
             // get daily promotion price
             if (($specialPriceObj = $product->getDailySpecialPrice()) instanceof ProductPrice) {
                 $dailySpecialPrice = StringUtilsAbstract::getValueFromCurrency($specialPriceObj->getPrice());
                 if ($dailySpecialPrice != 0) {
                     $specialPrice = $dailySpecialPrice;
                     $specialPriceFromDate = $specialPriceObj->getStart()->format('Y-m-d H:i:sP');
                     $specialPriceToDate = $specialPriceObj->getEnd()->format('Y-m-d H:i:sP');
                 }
             }
         }
         // if it is the daily promotion time then overwrite the special price with the daily special price
         $isWeekendPromotionTime = intval(SystemSettings::getSettings(SystemSettings::TYP_ISWEEKENDPROMOTIONTIME));
         if ($isWeekendPromotionTime === 1) {
             // get weekend promotion price
             if (($specialPriceObj = $product->getWeekendSpecialPrice()) instanceof ProductPrice) {
                 $weekendSpecialPrice = StringUtilsAbstract::getValueFromCurrency($specialPriceObj->getPrice());
                 if ($weekendSpecialPrice != 0) {
                     $specialPrice = $weekendSpecialPrice;
                     $specialPriceFromDate = $specialPriceObj->getStart()->format('Y-m-d H:i:sP');
                     $specialPriceToDate = $specialPriceObj->getEnd()->format('Y-m-d H:i:sP');
                 }
             }
         }
         //full description
         if (($asset = Asset::getAsset($product->getFullDescAssetId())) instanceof Asset) {
             //$fullDecription = '"' . $asset->read() . '"';
             $fullDecription = $asset->read();
         }
         //supplier
         if (count($supplierCodes = SupplierCode::getAllByCriteria('productId = ?', array($product->getId()), true, 1, 1)) > 0) {
             $supplierName = ($supplier = $supplierCodes[0]->getSupplier()) instanceof Supplier ? $supplier->getName() : '';
             $supplierCode = trim($supplierCodes[0]->getCode());
         }
         //Manufacturer
         if ($product->getManufacturer() instanceof Manufacturer) {
             $manufacturerName = trim($product->getManufacturer()->getName());
         }
         //disable or enabled
         if (intval($product->getActive()) === 0 || intval($product->getSellOnWeb()) === 0) {
             $enabled = false;
         } else {
             if ($product->getStatus() instanceof ProductStatus && intval($product->getStatus()->getId()) === ProductStatus::ID_DISABLED) {
                 $enabled = false;
             }
         }
         //categories
         if (count($categories = Product_Category::getAllByCriteria('productId = ?', array($product->getId()))) > 0) {
             foreach ($categories as $category) {
                 if (!$category->getCategory() instanceof ProductCategory || ($mageCateId = trim($category->getCategory()->getMageId())) === '') {
                     continue;
                 }
                 if (trim($attributeSetName) === $attributeSetDefault && ($productAttributeSet = $category->getCategory()->getProductAttributeSet()) instanceof ProductAttributeSet) {
                     $attributeSetName = trim($productAttributeSet->getName());
                 }
                 $categoryIds[] = $mageCateId;
             }
         }
         //ProductStatus
         if ($product->getStatus() instanceof ProductStatus) {
             $statusId = $product->getStatus()->getName();
         }
     }
     $categoryIds = array_unique($categoryIds);
     return array("store" => 'default', "websites" => 'base', "attribute_set" => $attributeSetName, "type" => 'simple', "category_ids" => implode(',', $categoryIds), "sku" => $sku, "name" => $productName, "price" => $rrpPrice, "special_from_date" => $specialPriceFromDate, "special_to_date" => $specialPriceToDate, "special_price" => $specialPrice, "news_from_date" => $asNewFrom, "news_to_date" => $asNewTo, "status" => intval($enabled) === 1 ? 1 : 2, "visibility" => 4, "tax_class_id" => 2, "description" => $fullDecription, "short_description" => $shortDescription, "supplier" => $supplierName, "man_code" => '', "sup_code" => $supplierCode, "meta_title" => '', "meta_description" => '', "manufacturer" => $manufacturerName, "url_key" => '', "url_path" => '', "custom_design" => '', "page_layout" => '', "country_of_manufacture" => '', "msrp_enabled" => '', "msrp_display_actual_price_type" => '', "meta_keyword" => '', "custom_layout_update" => '', "custom_design_from" => '', "custom_design_to" => '', "weight" => $weight, "msrp" => 'Use config', "gift_wrapping_price" => '', "qty" => 99, "min_qty" => 99, "use_config_min_qty" => 99, "is_qty_decimal" => '', "backorders" => '', "use_config_backorders" => '', "min_sale_qty" => '', "use_config_min_sale_qty" => '', "max_sale_qty" => '', "use_config_max_sale_qty" => '', "all_ln_stock" => $statusId, "is_in_stock" => 1, "low_stock_date" => '', "notify_stock_qty" => '', "use_config_notify_stock_qty" => '', "manage_stock" => '', "use_config_manage_stock" => '', "stock_status_changed_auto" => '', "use_config_qty_increments" => '', "qty_increments" => '', "use_config_enable_qty_inc" => '', "enable_qty_increments" => '', "is_decimal_divided" => '', "stock_status_changed_automatically" => '', "use_config_enable_qty_increments" => '', "image" => '', "small_image" => '', "thumbnail" => '', "media_gallery" => '', "is_recurring" => '', "media_gallery_reset" => 0);
 }
Example #6
0
 /**
  * creating a PO Item
  * 
  * @param PurchaseOrder $po
  * @param Product       $product
  * @param double        $unitPrice
  * @param int           $qty
  * @param string        $supplierItemCode
  * @param string        $supplierId
  * @param string        $description
  * @param double        $totalPrice
  * 
  * @return PurchaseOrderItem
  */
 public static function create(PurchaseOrder $po, Product $product, $unitPrice = '0.0000', $qty = 1, $totalPrice = null, $receivedQty = 0)
 {
     $entity = new PurchaseOrderItem();
     $msg = 'created POI for PO(' . $po->getPurchaseOrderNo() . ') with Product(SKU=' . $product->getSku() . ') unitPrice=' . $unitPrice . ', qty=' . $qty;
     $entity->setPurchaseOrder($po)->setProduct($product)->setUnitPrice($unitPrice)->setQty($qty)->setReceivedQty($receivedQty)->setTotalPrice(trim($totalPrice) !== '' ? $totalPrice : $unitPrice * $qty)->save()->addLog($msg, Log::TYPE_SYSTEM, 'Auto Log', __CLASS__ . '::' . __FUNCTION__);
     $po->addLog($msg, Log::TYPE_SYSTEM, 'Auto Log', __CLASS__ . '::' . __FUNCTION__);
     return $entity;
 }
Example #7
0
 /**
  * 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);
     }
 }