/**
  * Synchronization categories from ebay
  * @param int $site_id
  * @param int $category_id
  * @throws \Exception
  */
 public static function synchronization($site_id, $category_id)
 {
     $client = Client::instance();
     $client->setSiteId($site_id);
     $features_list = array('PayPalRequired', 'VariationsEnabled', 'MinimumReservePrice', 'ReturnPolicyEnabled', 'PaymentMethods', 'StoreInventoryEnabled', 'ListingDurations', 'ConditionEnabled', 'ConditionValues', 'HandlingTimeEnabled', 'StoreOwnerExtendedListingDurations');
     $result = $client->getCategoryFeatures($category_id, $features_list);
     if ($result) {
         if (!$result->isSuccess()) {
             throw new \Exception(implode("\n", $result->getErrorMessages()));
         }
         $features = array('payment_methods' => $result->getPaymentMethods(), 'paypal_required' => $result->isPayPalRequired(), 'condition_enabled' => $result->isConditionEnabled(), 'conditions' => $result->getConditions(), 'listing_duration' => $result->getListingDurations('FixedPriceItem'));
         $data = array('features' => json_encode($features), 'feature_update_time' => time());
         Category::update($site_id, $category_id, $data);
     } else {
         throw new \Exception(implode("\n", $client->getErrors()));
     }
 }
Beispiel #2
0
 /**
  * Synchronization categories from ebay
  * @param int $site_id
  * @throws \Exception
  */
 public static function synchronization($site_id)
 {
     $client = Client::instance();
     $client->setSiteId($site_id);
     $result = $client->getCategories();
     if ($result) {
         if (!$result->isSuccess()) {
             throw new \Exception(implode("\n", $result->getErrorMessages()));
         }
         $category_version = $result->getCategoryVersion();
     } else {
         throw new \Exception(implode("\n", $client->getErrors()));
     }
     $versions = static::getCategoryVersions();
     if (empty($versions[$site_id]) || $versions[$site_id] != $category_version) {
         $result = $client->getCategories(array(), null, 'ReturnAll');
         if ($result) {
             if (!$result->isSuccess()) {
                 throw new \Exception(implode("\n", $result->getErrorMessages()));
             }
             $categories = $result->getCategories();
             $data = array();
             foreach ($categories as $item) {
                 $path = $item['CategoryParentIds'];
                 $path[] = $item['CategoryID'];
                 $data[] = array('category_id' => $item['CategoryID'], 'parent_id' => $item['CategoryParentID'], 'leaf' => $item['LeafCategory'] ? 'Y' : 'N', 'name' => $item['CategoryName'], 'level' => $item['CategoryLevel'], 'id_path' => implode(',', $path), 'full_name' => implode(' > ', $item['CategoryNames']), 'site_id' => $site_id, 'features' => '');
             }
             db_query('DELETE FROM ?:ebay_categories WHERE site_id = ?i', $site_id);
             $limit = 60;
             $part_count = (int) ceil(count($data) / $limit);
             for ($i = 0; $i < $part_count; $i++) {
                 $part_data = array_slice($data, $limit * $i, $limit);
                 db_query('INSERT INTO ?:ebay_categories ?m', $part_data);
             }
             static::setCategoryVersion($site_id, $category_version);
             static::setLastSynchronizationTime($site_id, time());
         } else {
             throw new \Exception(implode("\n", $client->getErrors()));
         }
     } elseif ($versions[$site_id] == $category_version) {
         static::setLastSynchronizationTime($site_id, time());
     }
 }
Beispiel #3
0
 /**
  * Update sites from ebay
  * @throws \Exception
  */
 public static function synchronization()
 {
     $client = Client::instance();
     $result = $client->getEbayDetails('SiteDetails');
     if ($result) {
         if (!$result->isSuccess()) {
             throw new \Exception(implode("\n", $result->getErrorMessages()));
         }
         $sites = $result->getSiteDetails();
         if (!empty($sites)) {
             $data = array();
             foreach ($sites as $item) {
                 $data[] = array('site_id' => $item->site_id, 'site' => $item->site);
             }
             db_query('DELETE FROM ?:ebay_sites WHERE 1');
             db_query('INSERT INTO ?:ebay_sites ?m', $data);
             static::setLastSynchronizationTime(time());
         }
     } else {
         throw new \Exception(implode("\n", $client->getErrors()));
     }
 }
Beispiel #4
0
 /**
  * Synchronization shipping services from ebay
  * @param int $site_id
  * @throws \Exception
  */
 public static function synchronization($site_id)
 {
     $client = Client::instance();
     $client->setSiteId($site_id);
     $result = $client->getEbayDetails('ShippingServiceDetails');
     if ($result) {
         if (!$result->isSuccess()) {
             throw new \Exception(implode("\n", $result->getErrorMessages()));
         }
         $services = $result->getShippingServiceDetails();
         $data = array();
         foreach ($services as $item) {
             if ($item->valid_for_selling_flow) {
                 $data[] = array('service_id' => $item->shipping_service_id, 'name' => $item->shipping_service, 'description' => $item->description, 'service_type' => implode(',', $item->service_type), 'is_international' => $item->international_service ? 'Y' : 'N', 'category' => $item->shipping_category, 'ship_days_max' => $item->shipping_time_max, 'ship_days_min' => $item->shipping_time_min, 'package' => implode(',', $item->shipping_package), 'carrier' => implode(',', $item->shipping_carrier), 'weight_required' => $item->weight_required ? 'Y' : 'N', 'selling_flow' => 'Y', 'dimensions_required' => $item->dimensions_required ? 'Y' : 'N', 'surcharge_applicable' => $item->surcharge_applicable ? 'Y' : 'N', 'expedited_service' => $item->expedited_service ? 'Y' : 'N', 'detail_version' => $item->detail_version, 'update_timestamp' => $item->update_time, 'site_id' => $site_id);
             }
         }
         db_query('DELETE FROM ?:ebay_shippings WHERE site_id = ?i', $site_id);
         db_query('INSERT INTO ?:ebay_shippings ?m', $data);
         static::setLastSynchronizationTime($site_id, time());
     } else {
         throw new \Exception(implode("\n", $client->getErrors()));
     }
 }
Beispiel #5
0
 /**
  * @param Template  $template
  * @param Product[] $products
  */
 protected static function endGroupProducts(Template $template, array $products)
 {
     $api = Client::instance($template);
     $names = array_map(function (Product $product) {
         return htmlspecialchars($product->original_title);
     }, $products);
     fn_set_progress('echo', __('ebay_end_products', array('[product]' => implode('", "', $names))), false);
     $result = $api->endItems($products);
     if ($result) {
         foreach ($products as $product) {
             $productResult = $result->getItem($product->id);
             if ($productResult) {
                 if ($productResult->isSuccess()) {
                     static::$count_success++;
                     $product->setStatusClosed();
                     ProductLogger::info(ProductLogger::ACTION_END_PRODUCT, $product, __('ebay_success_close_product_notice'));
                 } else {
                     static::$count_fail++;
                 }
                 static::checkResponse($product, $productResult, ProductLogger::ACTION_END_PRODUCT);
             }
         }
     } else {
         static::checkInternalErrors($products, $api, ProductLogger::ACTION_END_PRODUCT);
     }
     foreach ($products as $product) {
         fn_set_progress('echo', '.');
     }
 }