<?php

namespace App\Models;

use CodeIgniter\Model;

class CartModel extends Model
{
    protected $table = 'cart';
    protected $primaryKey = 'id';
    protected $allowedFields = ['session_id', 'product_id', 'variant_id', 'quantity'];

    public function getCartItems($sessionId)
    {
        return $this->select('cart.*, products.name, products.image, product_variants.sku_name, product_variants.unit, product_variants.price, product_variants.offer_price')
            ->join('products', 'products.id = cart.product_id')
            ->join('product_variants', 'product_variants.id = cart.variant_id')
            ->where('cart.session_id', $sessionId)
            ->findAll();
    }
}
