/** * Show the form for creating a new resource. * * @param Store $store * @return Response */ public function import(Store $store) { // return ['success' => rand(0,1), 'message' => Factory::create()->text(100)]; try { $customer = OsCustomer::findOrFail(Input::get('resource_id')); $result = $store->createCustomer($customer->toWooCommerce()); if (isset($result->customer)) { $imported = ImportedCustomer::create(['os_id' => $customer->customers_id, 'email' => $result->customer->email, 'wc_id' => $result->customer->id]); return ['success' => 1, 'message' => "Customer '{$imported['email']}' imported successfully"]; } } catch (Exception $e) { ErrorCustomer::create(['os_id' => $customer->customers_id, 'email' => $customer->customers_email_address, 'error' => $e->getMessage()]); return ['success' => 0, 'message' => $e->getMessage()]; } return $result; }
/** * 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; }