HEX
Server: LiteSpeed
System: Linux sv4.hami.host 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64
User: armgroup (1008)
PHP: 8.2.32
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open, mail, socket_create, socket_create_listen, socket_create_pair, link, dl, openlog, syslog, stream_socket_server, curl_multi_init
Upload Files
File: /home/armgroup/libs/app/Http/Livewire/Frontend/Cart/Index.php
<?php

namespace App\Http\Livewire\Frontend\Cart;

use App\Http\Livewire\ConvertEmptyStringsToNull;
use App\Http\Livewire\General;
use App\Models\Product;
use Gloudemans\Shoppingcart\Facades\Cart;
use Livewire\Component;

class Index extends Component
{
    use ConvertEmptyStringsToNull, General;

    public $rowId;

    public $qty;

    public $price;

    public $withoutSpecial;

    public function render()
    {
        return view('livewire.frontend.cart.index');
    }

    public function remove()
    {
        Cart::remove($this->rowId);
        $this->doneMessage('با موفقیت حذف شد');

        return redirect()->route(Cart::count() ? 'cart.index' : 'search.index');
    }

    public function increment()
    {
        $cart = Cart::get($this->rowId);
        if (! $cart) {
            return redirect()->route('search.index');
        }

        $cartBuyStatus = Product::find($cart->id)->canBuy($this->qty + 1, $cart->options, $this->price);
        if ($cartBuyStatus === 'OK') {
            $this->qty++;
            $this->updateCartQuantity();
        } else {
            $this->ajaxDoneMessage($cartBuyStatus, 'error');
        }
    }

    public function decrement()
    {
        if ($this->qty == 1) {
            $this->ajaxDoneMessage('تعداد محصول نمی‌تواند کمتر از یک باشد!', 'error');

            return;
        }
        $this->qty--;
        $this->updateCartQuantity();
    }

    private function updateCartQuantity()
    {
        Cart::update($this->rowId, $this->qty);
        $this->emit('updateTotalCartPrice', Cart::subtotal(0), Cart::count());
        $this->emit('cartChanged');
        $this->ajaxDoneMessage('سبد خرید با موفقیت بروزرسانی شد');
    }
}