예제 #1
0
 /**
  * Show the form for creating a new resource_idurce.
  *
  * @param Store $store
  * @return Response
  */
 public function import(Store $store)
 {
     //        return ['success' => rand(0,1), 'message' => Factory::create()->text(100)];
     $product = OsProduct::findOrFail(Input::get('resource_id'));
     try {
         $result = $store->createProduct($product->toWooCommerce());
         // $result = $store->updateProduct($result->product->id, $product->toWooCommerce());
         if (isset($result->product)) {
             ImportedProduct::create(['os_id' => $product->products_id, 'name' => $result->product->title, 'wc_id' => $result->product->id]);
             return ['success' => 1, 'message' => "Product '{$result->product->title}',  os_id:'{$product->products_id}' imported successfully"];
         }
     } catch (Exception $e) {
         ErrorProduct::create(['os_id' => $product->products_id, 'name' => $product->description->products_name, 'error' => $e->getMessage()]);
         return ['success' => 0, 'message' => "Product '{$product->description->products_name}',  os_id:'{$product->products_id}'," . $e->getMessage()];
     }
     return $result;
 }