<?php

namespace TPS\Shop\Repositories;

use Carbon\Carbon;
use Webkul\Product\Repositories\ProductFlatRepository as WPFRepository;
/**
 * Product Flat Reposotory
 *
 * @copyright 2019 Webkul Software Pvt Ltd (http://www.webkul.com)
 */
class ProductFlatRepository extends WPFRepository
{

    public function getDiscountedProducts($count = 4){
        return $this->where('locale', app()->getLocale())
            ->where('channel', core()->getCurrentChannelCode())
            ->whereNotNull('product_flat.special_price')
            ->whereNotNull('product_flat.special_price_to')
            ->limit($count)
            ->inRandomOrder()
            ->get();
    }

    public function weeklyOffers($count = 8){
        return $this->where('locale', app()->getLocale())
            ->where('channel', core()->getCurrentChannelCode())
            ->whereNotNull('product_flat.special_price')
            ->whereNotNull('product_flat.special_price_to')
            ->whereNotNull('product_flat.special_price_from')
            ->whereDate('product_flat.special_price_from','<=',Carbon::today())
            ->whereDate('product_flat.special_price_to','>=',Carbon::today())
            ->limit($count)
            ->inRandomOrder()
            ->get();
    }

}