Skip to content

Commit

Permalink
check pincode availability api for checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamJY committed Jun 25, 2024
1 parent ec11a98 commit 1b5eb48
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/Http/Controllers/Shop/BagistoShiprocketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Webkul\Checkout\Facades\Cart;

class BagistoShiprocketController extends Controller
{
Expand All @@ -27,7 +28,7 @@ public function tracking(Request $request)

if ($request->filled('awbCode')) {
$shiprocketApi = new Shiprocket;
$data = $shiprocketApi->trackAWB(56789009876);
$data = $shiprocketApi->trackAWB($request->awbCode);
// $data = [
// "tracking_data" => [
// "track_status" => 1,
Expand Down Expand Up @@ -153,4 +154,34 @@ public function getEstimatedDelivery(Request $request)
$data = $this->shiprocketApi->getEstimatedDelivery($request);
return response()->json($data);
}

public function checkPincodeAvailability(Request $request)
{
$request->validate([
'pickup_postcode' => 'sometimes|required|integer|digits:6',
'delivery_postcode' => 'required|integer|digits:6',
'weight' => 'sometimes|required|numeric',
'cod' => 'sometimes|required|boolean'
]);

$cart = Cart::getCart();
$pickUpAddress = app('Webkul\Inventory\Repositories\InventorySourceRepository')->getModel()->latest()->first();

$calculateTotalWeight = 0;

foreach ($cart->items as $item) {
if ($item->getTypeInstance()->isStockable()) {
$calculateTotalWeight += $item->total_weight;
}
}

$request->mergeIfMissing([
'pickup_postcode' => config('shiprocket.pickupPostcode') ?? $pickUpAddress->postcode,
'weight' => $request->weight ?? $calculateTotalWeight ?? 0.5,
'cod' => 0
]);

$data = $this->shiprocketApi->getEstimatedDelivery($request);
return response()->json($data);
}
}
3 changes: 2 additions & 1 deletion src/Routes/shop-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@

Route::group(['middleware' => ['web', 'theme', 'locale', 'currency'], 'prefix' => 'shiprocket'], function () {
Route::get('tracking', [BagistoShiprocketController::class, 'tracking'])->name('shop.bagistoshiprocket.tracking');
Route::get('estimated-delivery', [BagistoShiprocketController::class, 'tracking'])->name('shop.bagistoshiprocket.tracking');
Route::get('estimated-delivery', [BagistoShiprocketController::class, 'getEstimatedDelivery'])->name('shop.bagistoshiprocket.tracking');
Route::get('pincode-availability', [BagistoShiprocketController::class, 'checkPincodeAvailability'])->name('shop.bagistoshiprocket.pincode_availability');
});

0 comments on commit 1b5eb48

Please sign in to comment.