public function dt1ProductsConnect() { set_time_limit(18000); $product_index_ppn = 1; $product_index_min_ppn = 1; $product_index_max_ppn = 1.1; $ppn_prods_skus = Product::where('category', 'ppn')->get()->pluck('sku'); $ppnProducts = PrepaynationProduct::whereNotIn('id_new', $ppn_prods_skus)-> // where('id','>',5250)-> get(); foreach ($ppnProducts as $key => $ppn_product) { //check whether there is a connection or not $ppn_product_connector = Connector::getConnections('Product', 'ppn', $ppn_product->id); // if no connection found then if ($ppn_product_connector) { } // check if there is any product with same name else { // if product already there then skip $product = Product::where('sku', $ppn_product['skuId'])->get()->first(); // $product = Product::firstOrNew(['sku' => $ppn_product['skuId']]); // if there is no product then create an product if ($product) { } // if there is no product then create an product else { // create a product $operator_ppn = ($ppn_product->operatorName); $country_ppn = ($ppn_product->countryCode); $country = CountryCurrency::where('iso_alpha2', $country_ppn)->get()->first(); $country_id = 0; if ($country) { $country_id = $country->id; } $operator = Operator::where('name', $operator_ppn)->get()->first(); $operator_id = 0; if ($operator) { $operator_id = $operator->id; } $prices = json_decode($ppn_product->prices); $wholesale_prices = $prices->wholesale; $json_dest = json_decode($ppn_product['destination'], true); $destination_amount = $json_dest['amount'] ?? 0; $destination_amount_min = $destination_amount; $destination_amount_max = $destination_amount; $product_reference = 'fixed_price'; $fixed_cost = $wholesale_prices->amount ?? 0; $ranged_cost_min = $fixed_cost; $ranged_cost_max = $fixed_cost; if ($ppn_product->type == '"RANGED_VALUE_RECHARGE"') { $ranged_cost_min = $wholesale_prices->amount->min ?? $fixed_cost; $ranged_cost_max = $wholesale_prices->amount->max ?? $fixed_cost; $fixed_cost = $ranged_cost_max ?? 0; $product_reference = 'ranged_price'; $destination_amount_min = $json_dest['amount']['min']; $destination_amount_max = $json_dest['amount']['max']; $destination_amount = $destination_amount_max ?? 0; } else { $fixed_cost = $wholesale_prices->amount ?? 0; $ranged_cost_min = $fixed_cost; $ranged_cost_max = $fixed_cost; $product_reference = 'fixed_price'; $destination_amount = $json_dest['amount'] ?? 0; $destination_amount_min = $destination_amount; $destination_amount_max = $destination_amount; } $provider_country_currency = CountryCurrency::where('code', $wholesale_prices->unit)->get()->first(); $my_basic_currency = Auth::user()->myBasicCurrency(); $cnvrt_to_bsc_crnc_price_amount = Auth::user()->toBasicCurrency($fixed_cost, $provider_country_currency); $cnvrt_to_wlt_crnc_price_amount = Auth::user()->convertCurrencyBtwn($fixed_cost, $provider_country_currency, $my_basic_currency); $euroCurrency = CountryCurrency::where('code', 'EUR')->get()->first(); $cnvrt_to_wlt_crnc_price_amount = Auth::user()->convertCurrencyBtwn($fixed_cost, $provider_country_currency, $euroCurrency); $price = $cnvrt_to_wlt_crnc_price_amount; $price_min = Auth::user()->convertCurrencyBtwn($ranged_cost_min, $provider_country_currency, $my_basic_currency); $price_max = Auth::user()->convertCurrencyBtwn($ranged_cost_max, $provider_country_currency, $my_basic_currency); // $json_dest = json_decode($ppn_product['destination'], true); // return $json_dest['unit']; // return $json_dest['amount']; $destination_amount; $product = Product::create([ 'vivape_id' => 'VPPRDT' . $ppn_product['id'] ?? 0, 'sku' => $ppn_product['id_new'] ?? 0, 'routes' => $ppn_product['routes'] ?? '', 'priority_routes' => $ppn_product['priority_routes'] ?? '', 'hold_routes' => $ppn_product['hold_routes'] ?? '', 'cost' => $cnvrt_to_wlt_crnc_price_amount ?? 0, 'price' => Auth::user()->cosToprice($price, $product_index_dt1) ?? 0, 'price_min' => Auth::user()->cosToprice($price_min, $product_index_dt1) ?? 0, 'price_max' => Auth::user()->cosToprice($price_max, $product_index_dt1) ?? 0, 'price_index' => $product_index_dt1, 'price_index_min' => $product_index_min_dt1, 'price_index_max' => $product_index_max_dt1, 'profit_index' => 1, 'profit_index_min' => 0.10, 'profit_index_max' => 0.35, 'commission_amount' => 3, 'commission_index' => 0.2, 'commission_index_min' => 0.1, 'commission_index_max' => 0.3, 'commission_type' => 'percentage', 'discount_amount' => 0, 'discount_index' => 0, 'discount_type' => 0, 'discount_media' => $ppn_product['discount_media'] ?? 0, 'discount_code' => $ppn_product['discount_code'] ?? 0, 'starts_from' => '2023-01-01', 'ends_on' => '2024-12-31', // 'inactivity_starts' => '', // 'inactivity_ends' => '', 'date_of_joining' => date('Y-m-d'), 'user_id' => Auth::user()->id, 'operator_id' => $operator_id, 'api_provider_id' => $ppn_product['api_provider_id'] ?? 0, 'country_id' => $country_id, 'state_id' => $ppn_product['state_id'] ?? 0, 'city_id' => $ppn_product['city_id'] ?? 0, 'area_id' => $ppn_product['area_id'] ?? 0, 'address' => $ppn_product['address'] ?? 0, 'identity' => $ppn_product['identity'] ?? 0, 'identity_type' => $ppn_product['identity_type'] ?? 0, 'identity_attachment' => $ppn_product['identity_attachment'] ?? 0, 'parent_type_id' => $ppn_product['parent_type_id'] ?? 0, 'parent_category_id' => $ppn_product['parent_category_id'] ?? 0, 'parent_status_id' => $ppn_product['parent_status_id'] ?? 0, 'referance' => $product_reference ?? 'reference', 'code' => $ppn_product['id_new'] ?? 0, 'title' => $ppn_product->name, 'name' => $ppn_product->name, 'level' => $ppn_product['level'] ?? 0, 'index' => $ppn_product['index'] ?? 0, 'index_min' => $ppn_product['index_min'] ?? 0, 'index_max' => $ppn_product['index_max'] ?? 0, 'status' => $ppn_product['status'] ?? 'Active', 'type' => $ppn_product['type'] ?? 0, 'category' => $ppn_product['category'] ?? 'ppn', 'ranking' => $destination_amount_min ?? 0, 'priority' => $destination_amount_max ?? 0, 'details' => json_encode($ppn_product->benefits), 'note' => $json_dest['unit'] ?? '', 'description' => json_encode($ppn_product->destination), 'paremeters' => $destination_amount ?? 0, 'attachment' => $ppn_product['tags'] ?? 0, 'image' => '', 'created_by' => Auth::user()->id ?? 0, 'updated_by' => Auth::user()->id ?? 0, ]); } // create the connection here // if no connection found then if (true) { $connection = Connector::create([ 'type' => 'Product', 'status' => 'active', 'start_point' => $product->id ?? 0, 'end_point' => $ppn_product->id ?? 0, 'start_snap' => json_encode($product) ?? '', 'end_snap' => json_encode($ppn_product) ?? '', 'parameters' => json_encode(['connection_api' => 'ppn']), 'priority' => 1, 'note' => 'ppn', 'created_by' => Auth::user()->id, 'updated_by' => Auth::user()->id, ]); } } } // foreach dt1Product // foreach dt1Product return (['message' => 'PrePayNation Products fetched and updated successfully.']); }