예제 #1
0
 public function map($okProduct)
 {
     $bfProduct = BfObjectFactory::getInstance("BfProduct", $this->bfVersion);
     $bfProductFieldsValidators = BfObjectFactory::getValidators("BfProduct", $this->bfVersion);
     $bfObjectFiller = new BfObjectFiller($bfProduct, $bfProductFieldsValidators, $this->logger);
     $productAvailability = new OkProductAvailability();
     $productAvailability->setLeadtimeToShip($okProduct->leadtime_to_ship);
     $productAvailability->setQuantity($okProduct->quantity);
     $bfObjectFiller->putIntoIfValid("MasterProductId", BfDataFormatter::prefixKey($okProduct->sku, $this->idPrefix));
     $bfObjectFiller->putIntoIfValid("InternalName", $okProduct->products_products_model);
     $bfObjectFiller->putIntoIfValid("ProductName", BfDataFormatter::formatName($okProduct->products_description_products_name));
     $bfObjectFiller->putIntoIfValid("SalesPitch", $okProduct->products_description_products_informations);
     if ($okProduct->products_description_products_description == "") {
         $longDescription = _("No description available");
     } else {
         $longDescription = $okProduct->products_description_products_description;
     }
     $bfObjectFiller->putIntoIfValid("LongDescription", $longDescription);
     $bfObjectFiller->putIntoIfValid("DeliveryInfo", $productAvailability->getStatus());
     $discoDate = $productAvailability->getDiscoDate();
     if ($discoDate != "") {
         $bfObjectFiller->putIntoIfValid("DiscoDate", $discoDate);
     }
     $bfObjectFiller->putIntoIfValid("PlpLabel", $okProduct->products_products_model);
     $bfObjectFiller->putIntoIfValid("PdpLabel", $okProduct->products_products_model);
     $bfObjectFiller->putIntoIfValid("ProductWeight", $okProduct->products_products_weight);
     $bfObjectFiller->putIntoIfValid("Returnable", "Y");
     $bfObjectFiller->putIntoIfValid("Taxable", "Y");
     $bfObjectFiller->putIntoIfValid("ChargeShipping", "Y");
     $bfObjectFiller->putIntoIfValid("ManufacturerId", BfDataFormatter::prefixKey($okProduct->products_manufacturers_id, $this->idPrefix));
     $bfObjectFiller->putIntoIfValid("ProductPrice->ListPrice->Price", BfDataFormatter::formatToDecimal3($okProduct->regular_price));
     $bfObjectFiller->putIntoIfValid("ProductPrice->ListPrice->Currency", "EUR");
     $bfObjectFiller->putIntoIfValid("ProductPrice->SalesPrice->Price", BfDataFormatter::formatToDecimal3($okProduct->final_price));
     $bfObjectFiller->putIntoIfValid("ProductPrice->SalesPrice->Currency", "EUR");
     // On prend seulement le premier id de catégorie pour l'instant
     $okCategoryTree = explode(",", $okProduct->categories_categories_id);
     $bfObjectFiller->putIntoIfValid("ProductCategoryMember->Category[0]->CategoryId", $okCategoryTree[0]);
     $bfObjectFiller->putIntoIfValid("ProductCategoryMember->Category[1]->CategoryId", $this->taxCategory);
     $bfObjectFiller->putIntoIfValid("ProductCategoryMember->Category[2]->CategoryId", $this->viewAllowCategory);
     $viewAllowTruDate = $productAvailability->getViewAllowThruDate();
     if ($viewAllowTruDate != "") {
         $bfObjectFiller->putIntoIfValid("ProductCategoryMember->Category[2]->ThruDate", $viewAllowTruDate);
     }
     $imageUrl = new ImageUrl($okProduct->products_products_image);
     $bfObjectFiller->putIntoIfValid("ProductImage->PlpSmallImage->Url", $imageUrl->getSquareUrl());
     $bfObjectFiller->putIntoIfValid("ProductImage->PdpThumbnailImage->Url", $imageUrl->getThumbnailUrl());
     $bfObjectFiller->putIntoIfValid("ProductImage->PdpLargeImage->Url", $imageUrl->getSquareUrl());
     $bfObjectFiller->putIntoIfValid("ProductImage->PdpDetailImage->Url", $imageUrl->getHiResUrl());
     $bfObjectFiller->putIntoIfValid("ProductGoodIdentification->Sku", $okProduct->sku);
     $bfObjectFiller->putIntoIfValid("ProductGoodIdentification->Isbn", $okProduct->products_help_ean);
     $bfObjectFiller->putIntoIfValid("ProductGoodIdentification->ManuId", $okProduct->products_help_marque_ref);
     $bfObjectFiller->putIntoIfValid("ProductInventory->BigfishInventoryTotal", $okProduct->gros_products_info_gros_products_stock);
     $bfObjectFiller->putIntoIfValid("ProductInventory->BigfishInventoryWarehouse", $okProduct->gros_products_info_gros_products_stock);
     $bfProductValidator = new BfProductValidator($this->logger);
     if (false == $bfProductValidator->isComplete($bfProduct)) {
         throw new XmlItemMapperException(sprintf("Incomplete product <%s>", $okProduct->sku));
     }
     return $bfProduct;
 }
예제 #2
0
 public function testMapSuccess()
 {
     $okProductsArray = $this->getOkProducts(__DIR__ . "/Data/okProducts.csv", 50);
     $productAvailability = new OkProductAvailability();
     // Create special case for coverage
     $okProductsArray[1]->products_description_products_description = "";
     foreach ($okProductsArray as $index => $okProduct) {
         $bfProduct = $this->xmlItemMapper->map($okProduct);
         $productAvailability->setLeadtimeToShip($okProduct->leadtime_to_ship);
         $productAvailability->setQuantity($okProduct->quantity);
         $this->assertEquals($productAvailability->getStatus(), $bfProduct->DeliveryInfo);
         if ($productAvailability->getDiscoDate() != "") {
             $this->assertEquals(date(OkProductAvailability::DISCO_DATE_FORMAT), $bfProduct->DiscoDate);
         } else {
             $this->assertEquals("", $bfProduct->DiscoDate);
         }
         $this->assertEquals(BfDataFormatter::prefixKey($okProduct->sku, $this->idPrefix), $bfProduct->MasterProductId);
         $this->assertEquals($okProduct->products_products_model, $bfProduct->InternalName);
         $this->assertEquals(BfDataFormatter::formatName($okProduct->products_description_products_name), $bfProduct->ProductName);
         $this->assertEquals($okProduct->products_description_products_informations, $bfProduct->SalesPitch);
         if ($okProduct->products_description_products_description == "") {
             $this->assertEquals(_("No description available"), $bfProduct->LongDescription);
         } else {
             $this->assertEquals($okProduct->products_description_products_description, $bfProduct->LongDescription);
         }
         $this->assertEquals($okProduct->products_products_model, $bfProduct->PlpLabel);
         $this->assertEquals($okProduct->products_products_model, $bfProduct->PdpLabel);
         $this->assertEquals($okProduct->products_products_weight, $bfProduct->ProductWeight);
         $this->assertEquals("Y", $bfProduct->Returnable);
         $this->assertEquals("Y", $bfProduct->Taxable);
         $this->assertEquals("Y", $bfProduct->ChargeShipping);
         $this->assertEquals(BfDataFormatter::prefixKey($okProduct->products_manufacturers_id, $this->idPrefix), $bfProduct->ManufacturerId);
         $this->assertEquals(BfDataFormatter::formatToDecimal3($okProduct->regular_price), (double) $bfProduct->ProductPrice->ListPrice->Price);
         $this->assertEquals("EUR", $bfProduct->ProductPrice->ListPrice->Currency);
         $this->assertEquals(BfDataFormatter::formatToDecimal3($okProduct->final_price), (double) $bfProduct->ProductPrice->SalesPrice->Price);
         $this->assertEquals("EUR", $bfProduct->ProductPrice->SalesPrice->Currency);
         $okCategoryTree = explode(",", $okProduct->categories_categories_id);
         $this->assertEquals($okCategoryTree[0], $bfProduct->ProductCategoryMember->Category[0]->CategoryId);
         $this->assertEquals($this->taxCategory, $bfProduct->ProductCategoryMember->Category[1]->CategoryId);
         $this->assertEquals($this->viewAllowCategory, $bfProduct->ProductCategoryMember->Category[2]->CategoryId);
         if ($productAvailability->getViewAllowThruDate() != "") {
             $this->assertEquals(OkProductAvailability::VIEW_ALLOW_EXPIRE_DATE, $bfProduct->ProductCategoryMember->Category[2]->ThruDate);
         } else {
             $this->assertEquals("", $bfProduct->ProductCategoryMember->Category[2]->ThruDate);
         }
         $imageUrl = new ImageUrl($okProduct->products_products_image);
         $this->assertEquals($imageUrl->getSquareUrl(), $bfProduct->ProductImage->PlpSmallImage->Url);
         $this->assertEquals($imageUrl->getThumbnailUrl(), $bfProduct->ProductImage->PdpThumbnailImage->Url);
         $this->assertEquals($imageUrl->getSquareUrl(), $bfProduct->ProductImage->PdpLargeImage->Url);
         $this->assertEquals($imageUrl->getHiResUrl(), $bfProduct->ProductImage->PdpDetailImage->Url);
         $this->assertEquals($okProduct->sku, $bfProduct->ProductGoodIdentification->Sku);
         $this->assertEquals($okProduct->products_help_ean, $bfProduct->ProductGoodIdentification->Isbn);
         $this->assertEquals($okProduct->products_help_marque_ref, $bfProduct->ProductGoodIdentification->ManuId);
         $this->assertEquals($okProduct->quantity, $bfProduct->ProductInventory->BigfishInventoryTotal);
         $this->assertEquals($okProduct->quantity, $bfProduct->ProductInventory->BigfishInventoryWarehouse);
     }
 }
예제 #3
0
 private function _testExportManufacturers($xpath)
 {
     $xPathSearchResults = $xpath->query("ProductManufacturer/Manufacturer");
     $bfManufacturersArray = array();
     foreach ($xPathSearchResults as $manufacturer) {
         $bfManufacturersArray[] = simplexml_import_dom($manufacturer);
     }
     $this->assertEquals(count($this->okManufacturersArray), count($bfManufacturersArray));
     foreach ($this->okManufacturersArray as $index => $okManufacturer) {
         $this->assertEquals(BfDataFormatter::prefixKey($okManufacturer->manufacturers_id, $this->idPrefix), $bfManufacturersArray[$index]->ManufacturerId);
     }
 }
예제 #4
0
 public function testMapSuccess()
 {
     $okCategoriesArray = $this->getOkCategories();
     foreach ($okCategoriesArray as $index => $okCategory) {
         $bfCategory = $this->xmlItemMapper->map($okCategory);
         $this->assertEquals(BfDataFormatter::prefixKey($okCategory->categories_id, $this->idPrefix), $bfCategory->CategoryId);
         $this->assertEquals(BfDataFormatter::prefixKey($okCategory->parent_id, $this->idPrefix), $bfCategory->ParentCategoryId);
         $this->assertEquals(BfDataFormatter::formatName(strip_tags($okCategory->categories_name)), $bfCategory->CategoryName);
         $this->assertEquals($okCategory->categories_name, $bfCategory->Description);
         if ($okCategory->categories_text != '') {
             $this->assertEquals($okCategory->categories_text, $bfCategory->LongDescription);
         } else {
             $this->assertEquals("-", $bfCategory->LongDescription);
         }
     }
 }
예제 #5
0
 public function testMapSuccess()
 {
     $okManufacturersArray = $this->getOkManufacturers(50);
     foreach ($okManufacturersArray as $index => $okManufacturer) {
         $bfManufacturer = $this->xmlItemMapper->map($okManufacturer);
         $this->assertEquals(BfDataFormatter::prefixKey($okManufacturer->manufacturers_id, $this->idPrefix), $bfManufacturer->ManufacturerId);
         $this->assertEquals(BfDataFormatter::formatName($okManufacturer->manufacturers_name), $bfManufacturer->ManufacturerName);
         $this->assertEquals($okManufacturer->manufacturers_abr, $bfManufacturer->Description);
         $this->assertEquals($okManufacturer->manufacturers_url, $bfManufacturer->LongDescription);
         if ($okManufacturer->manufacturers_image != '') {
             $this->assertEquals("http://images.client.com/images/" . $okManufacturer->manufacturers_image, $bfManufacturer->ManufacturerImage->Url);
         } else {
             $this->assertEquals('', $bfManufacturer->ManufacturerImage->Url);
         }
     }
 }
예제 #6
0
 public function testExportAllValues()
 {
     $this->xmlExporter->generateXml($this->fileName);
     $xmlDocument = new \DOMDocument();
     $xmlDocument->load($this->fileName);
     $xpath = new \DOMXpath($xmlDocument);
     $xPathSearchResults = $xpath->query("Products/Product");
     $bfProductsUpdatesArray = array();
     foreach ($xPathSearchResults as $product) {
         $bfProductsUpdatesArray[] = simplexml_import_dom($product);
     }
     $this->assertEquals(count($this->okProductsUpdatesArray), count($bfProductsUpdatesArray));
     foreach ($this->okProductsUpdatesArray as $index => $okProductUpdate) {
         $this->assertEquals(BfDataFormatter::prefixKey($okProductUpdate->sku, $this->idPrefix), $bfProductsUpdatesArray[$index]->MasterProductId);
         $this->assertEquals("", $bfProductsUpdatesArray[$index]->ProductId);
     }
 }
 public function testMapSuccess()
 {
     $okProductsUpdatesArray = $this->getOkProductsUpdates(50);
     $productAvailability = new OkProductAvailability();
     // Create specials cases for coverage
     $okProductsUpdatesArray[1]->products_description_products_description = "";
     $okProductsUpdatesArray[2]->leadtime_to_ship = 0;
     $okProductsUpdatesArray[2]->quantity = 0;
     foreach ($okProductsUpdatesArray as $index => $okProductUpdate) {
         $bfProductsUpdate = $this->xmlItemMapper->map($okProductUpdate);
         $productAvailability->setLeadtimeToShip($okProductUpdate->leadtime_to_ship);
         $productAvailability->setQuantity($okProductUpdate->quantity);
         $this->assertEquals($productAvailability->getStatus(), $bfProductsUpdate->DeliveryInfo);
         if ($productAvailability->getDiscoDate() != "") {
             $this->assertEquals(date(OkProductAvailability::DISCO_DATE_FORMAT), $bfProductsUpdate->DiscoDate);
         } else {
             $this->assertEquals("", $bfProductsUpdate->DiscoDate);
         }
         $this->assertEquals(BfDataFormatter::prefixKey($okProductUpdate->sku, $this->idPrefix), $bfProductsUpdate->MasterProductId);
         $this->assertEquals("", $bfProductsUpdate->ProductId);
         if ($okProductUpdate->products_description_products_description == "") {
             $this->assertEquals(_("No description available"), $bfProductsUpdate->LongDescription);
         } else {
             $this->assertEquals($okProductUpdate->products_description_products_description, $bfProductsUpdate->LongDescription);
         }
         $this->assertEquals(BfDataFormatter::formatToDecimal3($okProductUpdate->regular_price), (double) $bfProductsUpdate->ProductPrice->ListPrice->Price);
         $this->assertEquals("EUR", $bfProductsUpdate->ProductPrice->ListPrice->Currency);
         $this->assertEquals(BfDataFormatter::formatToDecimal3($okProductUpdate->final_price), (double) $bfProductsUpdate->ProductPrice->SalesPrice->Price);
         $this->assertEquals("EUR", $bfProductsUpdate->ProductPrice->SalesPrice->Currency);
         $okCategoryTree = explode(",", $okProductUpdate->categories_categories_id);
         $this->assertEquals($okCategoryTree[0], $bfProductsUpdate->ProductCategoryMember->Category[0]->CategoryId);
         $this->assertEquals($this->taxCategory, $bfProductsUpdate->ProductCategoryMember->Category[1]->CategoryId);
         $this->assertEquals($this->viewAllowCategory, $bfProductsUpdate->ProductCategoryMember->Category[2]->CategoryId);
         if ($productAvailability->getViewAllowThruDate() != "") {
             $this->assertEquals(OkProductAvailability::VIEW_ALLOW_EXPIRE_DATE, $bfProductsUpdate->ProductCategoryMember->Category[2]->ThruDate);
         } else {
             $this->assertEquals("", $bfProductsUpdate->ProductCategoryMember->Category[2]->ThruDate);
         }
         $stockValue = str_pad($okProductUpdate->quantity, 10, "0", STR_PAD_LEFT);
         $this->assertEquals($stockValue, $bfProductsUpdate->ProductInventory->BigfishInventoryTotal);
         $this->assertEquals($stockValue, $bfProductsUpdate->ProductInventory->BigfishInventoryWarehouse);
     }
 }
예제 #8
0
 public function map($okProductUpdate)
 {
     $bfProductUpdate = BfObjectFactory::getInstance("BfProductUpdate", $this->bfVersion);
     $bfProductUpdateFieldsValidators = BfObjectFactory::getValidators("BfProductUpdate", $this->bfVersion);
     $bfObjectFiller = new BfObjectFiller($bfProductUpdate, $bfProductUpdateFieldsValidators, $this->logger);
     $productAvailability = new OkProductAvailability();
     $productAvailability->setLeadtimeToShip($okProductUpdate->leadtime_to_ship);
     $productAvailability->setQuantity($okProductUpdate->quantity);
     $bfObjectFiller->putIntoIfValid("MasterProductId", BfDataFormatter::prefixKey($okProductUpdate->sku, $this->idPrefix));
     if ($okProductUpdate->products_description_products_description == "") {
         $longDescription = _("No description available");
     } else {
         $longDescription = $okProductUpdate->products_description_products_description;
     }
     $bfObjectFiller->putIntoIfValid("LongDescription", $longDescription);
     $bfObjectFiller->putIntoIfValid("DeliveryInfo", $productAvailability->getStatus());
     $discoDate = $productAvailability->getDiscoDate();
     if ($discoDate != "") {
         $bfObjectFiller->putIntoIfValid("DiscoDate", $discoDate);
     }
     $bfObjectFiller->putIntoIfValid("ProductPrice->ListPrice->Price", BfDataFormatter::formatToDecimal3($okProductUpdate->regular_price));
     $bfObjectFiller->putIntoIfValid("ProductPrice->ListPrice->Currency", "EUR");
     $bfObjectFiller->putIntoIfValid("ProductPrice->SalesPrice->Price", BfDataFormatter::formatToDecimal3($okProductUpdate->final_price));
     $bfObjectFiller->putIntoIfValid("ProductPrice->SalesPrice->Currency", "EUR");
     // On prend seulement le premier id de catégorie pour l'instant
     $okCategoryTree = explode(",", $okProductUpdate->categories_categories_id);
     $bfObjectFiller->putIntoIfValid("ProductCategoryMember->Category[0]->CategoryId", $okCategoryTree[0]);
     $bfObjectFiller->putIntoIfValid("ProductCategoryMember->Category[1]->CategoryId", $this->taxCategory);
     $bfObjectFiller->putIntoIfValid("ProductCategoryMember->Category[2]->CategoryId", $this->viewAllowCategory);
     $viewAllowTruDate = $productAvailability->getViewAllowThruDate();
     if ($viewAllowTruDate != "") {
         $bfObjectFiller->putIntoIfValid("ProductCategoryMember->Category[2]->ThruDate", $viewAllowTruDate);
     }
     $bfObjectFiller->putIntoIfValid("ProductInventory->BigfishInventoryTotal", $okProductUpdate->quantity);
     $bfObjectFiller->putIntoIfValid("ProductInventory->BigfishInventoryWarehouse", $okProductUpdate->quantity);
     $bfProductValidator = new BfProductValidator($this->logger);
     if (false == $bfProductValidator->isComplete($bfProductUpdate)) {
         throw new XmlItemMapperException(sprintf("Incomplete product update <%s>", $okProductUpdate->sku));
     }
     return $bfProductUpdate;
 }
예제 #9
0
 public function map($okManufacturer)
 {
     $bfManufacturer = BfObjectFactory::getInstance("BfManufacturer", $this->bfVersion);
     $bfManufacturerFieldsValidators = BfObjectFactory::getValidators("BfManufacturer", $this->bfVersion);
     $bfObjectFiller = new BfObjectFiller($bfManufacturer, $bfManufacturerFieldsValidators, $this->logger);
     $bfObjectFiller->putIntoIfValid("ManufacturerId", BfDataFormatter::prefixKey($okManufacturer->manufacturers_id, $this->idPrefix));
     $bfObjectFiller->putIntoIfValid("ManufacturerName", BfDataFormatter::formatName($okManufacturer->manufacturers_name));
     $bfObjectFiller->putIntoIfValid("Description", $okManufacturer->manufacturers_abr);
     $bfObjectFiller->putIntoIfValid("LongDescription", $okManufacturer->manufacturers_url);
     $manufacturerImageUrl = $okManufacturer->manufacturers_image != '' ? "http://images.client.com/images/" . $okManufacturer->manufacturers_image : '';
     $bfObjectFiller->putIntoIfValid("ManufacturerImage->Url", $manufacturerImageUrl);
     // $bfObjectFiller->putIntoIfValid( "ManufacturerImage->ThruDate", '' );
     // $bfObjectFiller->putIntoIfValid( "Address->Address1", 			'' );
     // $bfObjectFiller->putIntoIfValid( "Address->CityTown", 			'' );
     // $bfObjectFiller->putIntoIfValid( "Address->StateProvince", 		'' );
     // $bfObjectFiller->putIntoIfValid( "Address->ZipPostCode", 		'' );
     // $bfObjectFiller->putIntoIfValid( "Address->Country", 			'' );
     $bfManufacturerValidator = new BfManufacturerValidator($this->logger);
     if (false == $bfManufacturerValidator->isComplete($bfManufacturer)) {
         throw new XmlItemMapperException(sprintf("Incomplete manufacturer <%s>", $okManufacturer->manufacturers_name));
     }
     return $bfManufacturer;
 }
예제 #10
0
 public function map($okCategory)
 {
     $bfCategory = BfObjectFactory::getInstance("BfCategory", $this->bfVersion);
     $bfCategoryFieldsValidators = BfObjectFactory::getValidators("BfCategory", $this->bfVersion);
     $bfObjectFiller = new BfObjectFiller($bfCategory, $bfCategoryFieldsValidators, $this->logger);
     $bfObjectFiller->putIntoIfValid("CategoryId", BfDataFormatter::prefixKey($okCategory->categories_id, $this->idPrefix));
     $bfObjectFiller->putIntoIfValid("ParentCategoryId", BfDataFormatter::prefixKey($okCategory->parent_id, $this->idPrefix));
     $bfObjectFiller->putIntoIfValid("CategoryName", BfDataFormatter::formatName(strip_tags($okCategory->categories_name)));
     $bfObjectFiller->putIntoIfValid("Description", $okCategory->categories_name);
     // dans OfBiz, description est un varchar(255), on ne peut donc pas mettre le champ cd.categories_text qui est trop long
     $longDescription = $okCategory->categories_text != '' ? $okCategory->categories_text : "-";
     $bfObjectFiller->putIntoIfValid("LongDescription", $longDescription);
     $bfObjectFiller->putIntoIfValid("AdditionalPlpText", $okCategory->categories_abr);
     $bfObjectFiller->putIntoIfValid("AdditionalPdpText", $okCategory->categories_abr);
     $plpImageUrl = $okCategory->categories_image != '' ? "http://images.client.com/images/" . $okCategory->categories_image : '';
     $bfObjectFiller->putIntoIfValid("PlpImage->Url", $plpImageUrl);
     //$bfObjectFiller->putIntoIfValid( "FromDate",			"");
     //$bfObjectFiller->putIntoIfValid( "ThruDate", 			"");
     $bfCategoryValidator = new BfCategoryValidator($this->logger);
     if (false == $bfCategoryValidator->isComplete($bfCategory)) {
         throw new XmlItemMapperException(sprintf("Incomplete category <%s>", $okCategory->categories_name));
     }
     return $bfCategory;
 }
예제 #11
0
 public function testUnPrefixKeyPrefixNotFound()
 {
     $key = "000client123456";
     $prefix = "client";
     $this->assertEquals($key, BfDataFormatter::unPrefixKey($key, $prefix));
 }