HOME


Mini Shell 1.0
La Pieza.DO | Todo lo que buscas!

Bienvenido de nuevo!

Acceso Cuenta Delivery
DIR: /var/www/devs.lapieza.net/app/View/Components/Delivery/Deliveryinfo/Product/
Upload File :
Current File : /var/www/devs.lapieza.net/app/View/Components/Delivery/Deliveryinfo/Product/DeliveryOption.php
<?php
namespace App\View\Components\Delivery\Deliveryinfo\Product;
use App\Models\Product;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\Component;
class DeliveryOption extends Component
{
    public string $icon;
    public string $deliveryName;
    public string $estimatedTime;
    public string $deliveryCheckoutInfo;
    public Carbon $deliveryTime;
    public array $data;
    public function __construct($icon, $deliveryName, $data)
    {
        $this->icon = $icon;
        $this->deliveryName = $deliveryName;
        $this->data = $data;
        $this->estimatedTime = $this->getDeliveryEstimatedTime();
        if($deliveryName == 'PedidosYa'){
            $this->deliveryTime = Carbon::parse($this->data['storeAvailability']['delivery_available_on'], 'America/Santo_Domingo')->locale('es');
        } else {
            $this->deliveryTime = Carbon::now('America/Santo_Domingo');
            $this->data['storeAvailability']['delivery_now_available'] = true;
            $this->data['dropOffPoint'] = Auth::user()->addresses()->where('set_default', true)->first();
        }
        $this->buildDeliveryCheckoutInfo();
    }
    public function render()
    {
        return view('components.delivery.deliveryinfo.product.delivery-option', ['data' => $this->data]);
    }
    private function buildDeliveryCheckoutInfo(){
        $info = [
            'deliveryCost' => $this->data['delivery']['starter_price'],
            'shippingCostId' => $this->data['shippingCostId'] ?? null,
        ];
        $this->deliveryCheckoutInfo = json_encode($info);
    }
    public function getDeliveryEstimatedTime(){
        if($this->deliveryName == "Transporte Blanco"){
            $date = Carbon::parse($this->data['delivery']['estimated_pickup_time'], 'America/Santo_Domingo')->locale('es')->addDay();
            $dropOffTime = Carbon::parse($this->data['delivery']['estimated_dropoff_time'], 'America/Santo_Domingo')->locale('es');
            return $dropOffTime->dayName . ' ' . $dropOffTime->day . ' de ' . $dropOffTime->monthName . ' de ' . $dropOffTime->year;
        }
        $duration = $this->data['route']['duration'];
        $now = Carbon::now('America/Santo_Domingo');
        $initialTime = $now->copy()->addMinutes(20);
        $finalTime = $initialTime->copy()->addMinutes($duration + 20);
        return $initialTime->format('h:i A') . ' - ' . $finalTime->format('h:i A');
    }
}