Exemplo n.º 1
0
 /**
  * @param $item
  * @param $product
  */
 public function addPictures($item, Product $product)
 {
     $result = [];
     foreach ($product->getPictures() as $pictureUrl) {
         $result[] = $pictureUrl;
     }
     if (count($result) > 0) {
         $item->PictureDetails = new PictureDetailsType();
         $item->PictureDetails->GalleryType = GalleryTypeCodeType::C_GALLERY;
         $item->PictureDetails->PictureURL = $result;
     }
 }
Exemplo n.º 2
0
 public function __construct($data)
 {
     parent::__construct($data);
     $this->productType = $data['productType'];
     $this->msrp = $data['price'];
 }
Exemplo n.º 3
0
 /**
  * @param Product $product
  * @return \DTS\eBaySDK\Trading\Types\AddFixedPriceItemResponseType
  */
 public function post(Product $product)
 {
     $request = new AddFixedPriceItemRequestType();
     $request = $this->addAuthToRequest($request);
     $item = new ItemType();
     $item->ListingType = ListingTypeCodeType::C_FIXED_PRICE_ITEM;
     // Renew the item every 30 days until the user cancels it
     $item->ListingDuration = ListingDurationCodeType::C_GTC;
     $item->InventoryTrackingMethod = 'SKU';
     $item->Title = $product->getTitle();
     $item->Description = $product->getDescription();
     // Mandatory when InvntoryTrackingMethod is set to SKU
     $item->SKU = $product->getSku();
     $item->HitCounter = HitCounterCodeType::C_HIDDEN_STYLE;
     if ($product->hasVariations()) {
         $this->addVariationsData($item, $product);
     } else {
         $item->StartPrice = new AmountType(['value' => $product->getPrice()]);
         $item->Quantity = $product->getQuantity();
     }
     $item->Country = $this->store->getStoreData('country');
     $item->Location = $this->store->getStoreData('location');
     if ($this->store->hasStoreData('postCode')) {
         $item->PostalCode = $this->store->getStoreData('postCode');
     }
     $item->Currency = $product->getCurrency();
     $item->PrimaryCategory = new CategoryType();
     $item->PrimaryCategory->CategoryID = $product->getCategory();
     $item->CategoryMappingAllowed = true;
     // Condition (should be brand new)
     $item->ConditionID = 1000;
     // Add brand information as item specific information
     $item->ItemSpecifics = new NameValueListArrayType();
     if ($product->getBrand()) {
         $brand = new NameValueListType();
         $brand->Name = 'Brand';
         $brand->Value[] = $product->getBrand();
         $item->ItemSpecifics->NameValueList[] = $brand;
     }
     if ($product->getWeight()) {
         // Add details for the shipping
         // NOTE: doesn't seem to work
         $item->ShippingPackageDetails = new ShipPackageDetailsType();
         $item->ShippingPackageDetails->MeasurementUnit = MeasurementSystemCodeType::C_ENGLISH;
         $totalOz = $product->getWeight() * 0.035274;
         $weightMajor = intval(floor($totalOz / 16));
         $weightMinor = intval(floor($totalOz - $weightMajor * 16));
         $item->ShippingPackageDetails->WeightMajor = new MeasureType(['unit' => 'lbs', 'value' => $weightMajor]);
         $item->ShippingPackageDetails->WeightMinor = new MeasureType(['unit' => 'oz', 'value' => $weightMinor]);
     }
     // Add pictures
     $this->addPictures($item, $product);
     // Add payement
     $item->PaymentMethods = $this->store->getPaymentOptions();
     $item->PayPalEmailAddress = $this->store->getPaypalEmail();
     $item->DispatchTimeMax = $this->store->getStoreData('dispatchTime');
     // Add shipping options and return policy
     $this->addShippingOptions($item, $product->getShippingOptions());
     $this->addReturnPolicy($item, $product->getReturnPolicy());
     $request->Item = $item;
     $response = $this->service->addFixedPriceItem($request);
     if ($response->Ack == 'Failure') {
         $this->handleError($response);
     }
     return $response;
 }
 /**
  * @param $eBayProduct
  * @param Product $product
  * @return array
  */
 private function separateVariations($eBayProduct, Product $product)
 {
     $foundVariations = [];
     $newVariations = [];
     // Find variations that are to be updated and separate the new ones
     foreach ($product->getVariationOptions() as $option) {
         $found = false;
         foreach ($eBayProduct->Variations->Variation as $ebayVariation) {
             if ($ebayVariation->SKU === $option['sku']) {
                 $ebayVariation->Quantity = $option['quantity'];
                 if (array_key_exists('price', $option) && $ebayVariation->StartPrice->value != $option['price']) {
                     $ebayVariation->StartPrice = new AmountType(array('value' => doubleval($option['price'])));
                 }
                 $foundVariations[] = $ebayVariation;
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $newVariations[] = $option;
         }
     }
     return ['new' => $newVariations, 'found' => $foundVariations];
 }