<?php
//src/Service/TwigGlobalVariables.php
namespace App\Service;
use App\Entity\Cart;
use App\Entity\City;
use App\Entity\DeliveryRoute;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Doctrine\ORM\EntityManagerInterface;
use App\Service\UserInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use App\Entity\Product;
use App\Entity\Category;
use App\Entity\Company;
use App\Entity\CartProduct;
use App\Entity\OmeloPage;
use App\Entity\ProductSponsored;
use App\Entity\CompanyAssociation;
use App\Entity\Variable;
use App\Entity\PickupLocations;
use App\Service\UserService;
use App\Service\MessageService;
use App\Service\DistributorService;
use App\Service\VariableService;
use App\Repository\NotificationRepository;
use DateTime;
use Symfony\Component\Routing\Route;
use function GuzzleHttp\Psr7\str;
class TwigGlobalVariables
{
private $userServ;
private $messageServ;
private $containerInter;
private $notificationRepo;
private $distribServ;
private $variableServ;
private $trackPodServ;
public function __construct(SessionInterface $session, EntityManagerInterface $em, ContainerInterface $container, NotificationRepository $notif, MessageService $messageServ, UserService $userServ, DistributorService $dist, VariableService $variableServ,TrackPodAPIService $trackPodAPIService){
$this->session = $session;
$this->em = $em;
$this->containerInter = $container;
$this->notificationRepo = $notif;
$this->messageServ = $messageServ;
$this->userServ = $userServ;
$this->distribServ = $dist;
$this->variableServ = $variableServ;
$this->trackPodServ= $trackPodAPIService;
}
/*
* Return the StarterKits for promo a bit everywhere
*/
public function getStarterKits(){
return $this->em->getRepository(ProductSponsored::class)->findInModal();
}
/*
* Return a boolean if we display the starter kits or no
*/
public function getDisplayStarterKits()
{
if ($this->session->get('DO_NOT_DISPLAY_STARTERKITS') == "TRUE") {
return false;
}
if($this->getStarterKits()){
//Not a loggued user we display
if(!$this->userServ->getUser()){
return true;
}
//If we don'T have the last 4 digits mean the user never bought anything
if(empty($this->userServ->getUser()->getPaymentLast4digits()))
return true;
}
return false;
}
public function getUser(){
return $this->userServ->getUser();
}
/*
* Notifications
*/
public function getNewNotifications(){
$newNotif = $this->notificationRepo->findNewNotifications();
return $newNotif;
}
/*
* Get Cart
*/
public function getCart(){
return $this->userServ->getCart();
}
/*
* Get Favorite
*/
public function getFavorites(){
return $this->userServ->getFavorites();
}
/*
* Check if product it favorite
*/
public function hasFavorite($product){
foreach($this->userServ->getFavorites() as $f){
if($f->getProduct() == $product)
return true;
}
return false;
}
/*
* New Message
*/
public function getNewMessages(){
$newMsg = $this->messageServ->getNewMessagesIn('inbox');
return $newMsg;
}
/*
* The frontend Menu
*/
public function menu(){
$menu = $this->em
->getRepository(Category::class)
->getTreeMenu();
// ->findBy(array(
// 'subCategory' => null
// ),
// array('placement' => 'ASC'))
// ;
return $menu;
}
/*
* The frontend Menu
*/
public function getHasProducts($category){
$hasProducts = $this->em
->getRepository(Product::class)
->countProductsInCategory($category);
return $hasProducts;
}
/*
* Return the footer
*/
public function footer(){
$data = array();
$footer = $this->em
->getRepository(OmeloPage::class)
->findBy(array(
'template' => 'footer.html.twig'
)
);
if($footer){
$footer = current($footer);
return json_decode($footer->getContent());
}else
return false;
}
/*
* Return the company Terms
*/
public function getCompanyTerms(){
$data = array();
$terms = $this->em
->getRepository(OmeloPage::class)
->findBy(array(
'url' => 'reglement-vendeurs'
)
);
if($terms){
$terms = current($terms);
return $terms->getMainContent();
}else
return false;
}
public function getTimeStamp(){
return mktime();
}
public function cssVersion(){
$date = new \DateTime();
return $date->format('YmdH');
}
public function getEstimationShipping(Product $product){
return $this->getEstimationShippingRoute($product)['date'];
}
public function getLastUsedShippingAddress() {
$shippingAddress = false;
$currentCart = $this->getCart();
if ($currentCart) {
$shippingAddress = $currentCart->getShippingAddress();
}
if (!$shippingAddress) {
// use last cart address if available
if (($lastCart = $this->em->getRepository(Cart::class)->lastUserPaidCart($this->getUser())) !== null){
$shippingAddress = $lastCart->getShippingAddress();
}
}
# else use user's last created address
if ($shippingAddress === null){
$addresses = $this->getUser()->getShippingAddresses();
if (count($addresses) > 0){
$shippingAddress = $addresses[count($addresses)-1];
}
}
return $shippingAddress;
}
public function getEstimationShippingRoute(Product $product){
$isFreshProduct = $product->getIsRefrigerated() || $product->getIsFroozen();
// define minimal departure date (time > 12P PM => after tomorrow, else tomorrow )
$productDepartureDate = new \DateTime();
$productDepartureDate = $productDepartureDate->modify('+1 day');
if ($productDepartureDate->format('H') >= 12){
$productDepartureDate = $productDepartureDate->modify('+1 day');
}
$productDepartureDate = $productDepartureDate->setTime(0,0,0);
// JIT and special offers can only be sent on next tuesday
if($product->getIsJustinTime()) {
$todaysDate = new \DateTime();
$productDepartureDate = !empty($product->getJustInTimeDeliveryDate()) ?
$product->getJustInTimeDeliveryDate() : $todaysDate->modify("next tuesday");
/*
if today is monday, add one week to the departure date
it will become next tuesday of next week
*/
if (
date("w") == 1 // 0=sunday,1=monday
) {
$dt = new \DateTime();
$dt->setTimestamp(strtotime("+1 week", $productDepartureDate->format("U")));
$productDepartureDate = $dt;
}
$productDepartureDate = $productDepartureDate->setTime(0,0,0);
}
else if($product->getCompany()->getId() == 181)
$productDepartureDate = new \DateTime("next tuesday");
// use cart shipping addresse if setted
$shippingAddress = $this->userServ->getCart()->getShippingAddress();
if ($shippingAddress == null && $this->getUser() !== null){
$lastShippingAddress = $this->getLastUsedShippingAddress();
if ($lastShippingAddress) {
$shippingAddress = $lastShippingAddress;
}
}
# estimation for city from cart address
$bestEstimation = null;
if ( $shippingAddress !== null){
$cityName = $shippingAddress->getCity();
$city = $this->em->getRepository(City::class)->findOneBy(['name' => $cityName]);
$routes = $city != null ? $city->getDeliveryRoutes() : $this->em->getRepository(DeliveryRoute::class)
->findBy(['type' => 'maturin']);
# get shipping address city
# get city's available delivery routes
$estimations = [];
foreach ($routes as $route){
// process only maturin routes
if ($route->getType() !== DeliveryRoute::MATURIN_TYPE)
continue;
if ($isFreshProduct && $route->getName() === 'Pas de frais')
break;
/*
* exclude route if not matching product requirements
*/
if ($product->getIsRefrigerated() && !$route->isRefrigeratedAllowed())
continue;
if ($product->getIsFroozen() && !$route->isFrozenAllowed())
continue;
if (!$product->getIsRefrigerated() && !$product->getIsFroozen() && !$route->isDryAllowed())
continue;
// add estimation to list
$estimations []= [
'date' => $route->getDeliveryDateEstimation(clone $productDepartureDate),
'route' => $route
];
}
# find best estimation from list
foreach ($estimations as $estimation){
if ($bestEstimation === null || $estimation['date'] < $bestEstimation['date']){
$bestEstimation = $estimation;
}
}
}
# compare best estimation against purolator and keep the best one
$puroEstimation = null;
if (($puro = $this->em->getRepository(DeliveryRoute::class)->findOneBy([
'type' => $isFreshProduct ? DeliveryRoute::PURO_FRAIS_TYPE : DeliveryRoute::PURO_SEC_TYPE
])) !== null)
{
$puroEstimation = [
'date' => $puro->getDeliveryDateEstimation(clone $productDepartureDate),
'route' => $puro
];
if ($bestEstimation === null)
return $puroEstimation;
if (is_bool($puroEstimation['date']) && $bestEstimation) {
return $bestEstimation;
}
if (is_bool($bestEstimation['date']) && $puroEstimation) {
return $puroEstimation;
}
return ($puroEstimation['date']->format('W') < $bestEstimation['date']->format('W')) ? $puroEstimation : $bestEstimation;
}
return [
'date' => $this->distribServ->getEstimationShippingForProduct($product),
'route' => null
];
}
public function getEstimationShippingForMaturinProducts($cart){
$late = new \DateTime();
foreach($cart->getProducts() as $p){
$est = $this->getEstimationShipping($p->getProduct());
if($est > $late)
$late = $est;
}
return $late;
}
public function getEstimationShippingRouteForMaturinProducts($cart, $city = null){
$late = ['date' => new \DateTime(), 'route' => null];
$datePayment = new \DateTime();
if ($cart->getDatePayment()) {
$datePayment = clone $cart->getDatePayment();
}
foreach($cart->getProducts() as $p){
$est = $this->getMaintenanceEstimationShippingRoute($p->getProduct(), $datePayment, $city);
if($est['date'] > $late['date'])
$late = $est;
}
return $late;
}
public function getShippingEstimateDate($cart){
return $this->getMaintenanceEstimationShippingForMaturinProducts($cart);
}
public function isAllowedToModify(Product $product){
//We use the admin bundle for now, for our own staff only
return $this->userServ->isAllowedToMakeBundles();
}
public function getGlobalPickUpLocations() {
$returnedLocations = [];
$pickupLocations = $this->em->getRepository(PickupLocations::class)->findBy(array('locationStatus' => 'ACTIVE'));
foreach($pickupLocations as $location) {
$getRoutes = $this->em->getRepository(City::class)->findBy(['name' => trim($location->getLocationCity())]);
$returnedLocations[] = [
"value" => $location->getId(),
"text" => $location->getLocationName()." - ".$location->getLocationAddress(),
];
}
return $returnedLocations;
}
public function getGlobalPickUpLocation() {
$returnedLocation = false;
$pickupLocations = $this->em->getRepository(PickupLocations::class)->findBy(array('locationStatus' => 'ACTIVE'));
if ($pickupLocations) {
$pickupLocation = current($pickupLocations);
$pickupLocationAddress = $pickupLocation->getLocationAddress();
$pickupLocationName = $pickupLocation->getLocationName();
if ($pickupLocationAddress) {
$returnedLocation = $pickupLocationName." - ".$pickupLocationAddress;
}
}
return $returnedLocation;
}
public function getGlobalPickUpSchedule() {
$returnedSchedule = false;
$pickupLocations = $this->em->getRepository(PickupLocations::class)->findBy(array('locationStatus' => 'ACTIVE'));
if ($pickupLocations) {
$pickupLocation = current($pickupLocations);
$pickupLocationSchedule = $pickupLocation->getLocationSchedule();
if ($pickupLocationSchedule) {
$pickupLocationSchedule = json_decode($pickupLocationSchedule, true);
$returnedSchedule = json_encode($pickupLocationSchedule["pickUpSchedule"]);
}
}
return $returnedSchedule;
}
public function getGlobalPickUpSchedules() {
$returnedSchedules = [];
$pickupLocations = $this->em->getRepository(PickupLocations::class)->findBy(array('locationStatus' => 'ACTIVE'));
foreach($pickupLocations as $pickupLocation) {
$pickupLocationSchedule = $pickupLocation->getLocationSchedule();
if ($pickupLocationSchedule) {
$pickupLocationSchedule = json_decode($pickupLocationSchedule, true);
$returnedSchedules[$pickupLocation->getId()] = $pickupLocationSchedule["pickUpSchedule"];
}
}
return $returnedSchedules;
}
public function hasGlobalPickUpEnabled() {
$pickupLocations = $this->em->getRepository(PickupLocations::class)->findBy(array('locationStatus' => 'ACTIVE'));
if (!empty($pickupLocations)) {
return true;
}
return false;
}
/*
* For the association tell if the user is staying inside a association
*/
public function getAssociationUserIsBrowsing(){
return $this->userServ->getAssociationUserIsBrowsing();
}
public function getVariableValueByCodeName($codeName, Company $company=null){
return $this->variableServ->getValueByCodeName($codeName, $company);
}
public function getPickupChoiceForCurrentAssociation(): array {
$association = $this->getAssociationUserIsBrowsing();
$available = [];
if ($association){
$pickupScheduleVar = $association->getVariableByCodeName('orders.pickUpSchedule');
if ($pickupScheduleVar && $pickupScheduleVar->getValueType() == 3) {
$choices = $pickupScheduleVar->getJsonValueAsArray();
$delay = $association->getVariableByCodeName('orders.prepareDelay');
if ($delay)
$delay = (int)$delay->getValue();
else
$delay = 2; // default 2
$currentDayOfWeek = date("N");
$dayMap = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday'];
$notBefore = new \DateTime('today');
$notBefore->modify("+ $delay day");
foreach ($choices as $dayInt => $periods) {
$next = new \DateTime('next ' . $dayMap[((int)$dayInt) - 1]);
if ($next < $notBefore) {
$next->modify('+ 1 week');
}
foreach ($periods as $period) {
$available [] = [
'day' => $next,
'start' => $period[0],
'end' => $period[1],
];
}
}
}
}
return $available;
}
public function getIsDev(){
return $_ENV['APP_ENV'] !== 'prod';
}
public function getStripeAPIPKey(){
return $_ENV['STRIPE_API_PKEY'];
}
/**
* Check if order pack up is possible for cart product
* It looks into product association options
*
* @param Cart $cart
* @return bool
*/
public function canPackup(Cart $cart):int{
foreach ($cart->getProducts() as $cartProduct){
if ($cartProduct->getAddedWhenBeingInAssociation()){
return $cartProduct->getAddedWhenBeingInAssociation()->canPackUp();
}
}
return 0;
}
public function isAllowedToMakeBundles(){
return $this->userServ->isAllowedToMakeBundles();
}
public function getDeliveryBreadCrumpText(){
$textParts = [];
// check for delivery
if ($this->getCart()->hasMaturinShipping() || $this->getCart()->getHasCustomShipping()){
$textParts []= 'Livraison';
}
// check for pickup
if ($this->getCart()->hasPickup()){
$textParts []= 'Cueillette';
}
return count($textParts) > 0 ? implode(' / ', $textParts) : 'Livraison';
}
public function getAssociationNames($cart){
$associationNames = [];
foreach ($cart->getProducts() as $cartProduct) {
if (($association = $cartProduct->getAddedWhenBeingInAssociation()) != null)
{
$name = $association->getName();
$name = str_replace('le ', '', $name);
$name = str_replace('Le ', '', $name);
$name = str_replace('la ', '', $name);
$name = str_replace('La ', '', $name);
if (!in_array($name, $associationNames))
$associationNames[]=$name;
}
}
return implode(', ', $associationNames);
}
/**
* Check if user is admin of association that contains company
*
* @param Company $company
* @return bool
*/
public function userIsAssociationAdmin(Company $company): bool{
$user = $this->getUser();
if ($user){
$association = $user->getMakeCompanyForAssociation();
if ($association){
return $association->getCompanies()->contains($company);
}
}
return false;
}
/**
* Check if user as Maturin Admin Role or is Super User
* @return bool
*/
public function userIsMaturinAdmin(): bool{
$user = $this->getUser();
return $user && (
$user->isGranted('ROLE_SUPER_ADMIN')
|| $user->isGranted('ROLE_ADMIN_MATURIN')
);
}
public function add48hToDate(\DateTime $startDate): \DateTime{
$endDate = clone $startDate;
$endDate = $endDate->modify('+ 2 days');
if ($endDate->format('N') >= 6)
$endDate = $endDate->modify('+ 2 days');
return $endDate ;
}
public function getMaintenanceEstimationShippingRoute(Product $product,\DateTime $date, $city = null){
$todaysDate = clone $date;
$isFreshProduct = $product->getIsRefrigerated() || $product->getIsFroozen();
// define minimal departure date (time > 12P PM => after tomorrow, else tomorrow )
$productDepartureDate = clone $todaysDate;
$productDepartureDate = $productDepartureDate->modify('+1 day');
if ($productDepartureDate->format('H') >= 12) {
$productDepartureDate = $productDepartureDate->modify('+1 day');
}
$productDepartureDate = $productDepartureDate->setTime(0,0,0);
// JIT and special offers can only be sent on next tuesday
if($product->getIsJustinTime()) {
if (!empty($product->getJustInTimeDeliveryDate())) {
$productDepartureDate = $product->getJustInTimeDeliveryDate();
} else {
$productDepartureDate = clone $todaysDate;
$productDepartureDate->modify("next tuesday");
}
/*
if today is monday, add one week to the departure date
it will become next tuesday of next week
*/
if (
date("w", $todaysDate->getTimestamp()) == 1 // 0=sunday,1=monday
) {
$productDepartureDate->modify("+1 week");
}
} else {
if ($product->getCompany()->getId() == 181) {
$productDepartureDate = $todaysDate->modify("next tuesday");
}
}
// use cart shipping addresse if setted
$shippingAddress = $this->userServ->getCart()->getShippingAddress();
if ($shippingAddress == null && $this->getUser() !== null){
// use last cart address if available
if (($lastCart = $this->em->getRepository(Cart::class)->lastUserPaidCart($this->getUser())) !== null){
$shippingAddress = $lastCart->getShippingAddress();
}
# else use user's last created address
if ($shippingAddress === null){
$addresses = $this->getUser()->getShippingAddresses();
if (count($addresses) > 0){
$shippingAddress = $addresses[count($addresses)-1];
}
}
}
$cityName=null;
if ($city != null){
$cityName = $city;
}
if ($city == null && $shippingAddress !== null){
$cityName = $shippingAddress->getCity();
}
# estimation for city from cart address
$bestEstimation = null;
if ( $shippingAddress !== null){
$city = $this->em->getRepository(City::class)->findOneBy(['name' => $cityName]);
$routes = $city != null ? $city->getDeliveryRoutes() : $this->em->getRepository(DeliveryRoute::class)
->findBy(['type' => 'maturin']);
# get shipping address city
# get city's available delivery routes
$estimations = [];
foreach ($routes as $route){
// process only maturin routes
if ($route->getType() !== DeliveryRoute::MATURIN_TYPE)
continue;
if ($isFreshProduct && $route->getName() === 'Pas de frais')
break;
/*
* exclude route if not matching product requirements
*/
if ($product->getIsRefrigerated() && !$route->isRefrigeratedAllowed())
continue;
if ($product->getIsFroozen() && !$route->isFrozenAllowed())
continue;
if (!$product->getIsRefrigerated() && !$product->getIsFroozen() && !$route->isDryAllowed())
continue;
// add estimation to list
$estimations = [
'date' => $route->getDeliveryDateEstimation(clone $productDepartureDate),
'route' => $route
];
return $estimations;
}
# find best estimation from list
foreach ($estimations as $estimation){
if ($bestEstimation === null || $estimation['date'] < $bestEstimation['date']){
$bestEstimation = $estimation;
}
}
}
# compare best estimation against purolator and keep the best one
$puroEstimation = null;
if (($puro = $this->em->getRepository(DeliveryRoute::class)->findOneBy([
'type' => $isFreshProduct ? DeliveryRoute::PURO_FRAIS_TYPE : DeliveryRoute::PURO_SEC_TYPE
])) !== null)
{
$puroEstimation = [
'date' => $puro->getDeliveryDateEstimation(clone $productDepartureDate),
'route' => $puro
];
if ($bestEstimation === null)
return $puroEstimation;
if (is_bool($puroEstimation['date']) && $bestEstimation) {
return $bestEstimation;
}
if (is_bool($bestEstimation['date']) && $puroEstimation) {
return $puroEstimation;
}
return ($puroEstimation['date']->format('W') < $bestEstimation['date']->format('W')) ? $puroEstimation : $bestEstimation;
}
return [
'date' => $this->getDistrubutorMaintenanceEstimationShippingForProduct($product,$todaysDate),
'route' => null
];
}
public function getYMDFromDateObject($deliveryDate) {
return $deliveryDate->format("Y-m-d");
}
public function getIsDeliveredByDeliveryDate($deliveryDate) {
$delivery_stop = new \DateTime($deliveryDate->format("Y-m-d 21:00:00"), new \DateTimeZone("America/New_York"));
$timestamp_delivery_stop = $delivery_stop->format("U");
$now = time();
if (
$now >= $timestamp_delivery_stop
) {
return true;
} else {
return false;
}
}
public function getMaintenanceEstimationShippingForMaturinProducts($cart){
if ($cart->getDatePayment()) {
$late = clone $cart->getDatePayment();
$cartPaymentDate = clone $late;
foreach($cart->getProducts() as $p){
$est = $this->getMaintenanceEstimationShippingRoute($p->getProduct(),$cartPaymentDate)['date'];
if($est > $late)
$late = $est;
}}
return $late;
}
public function getDistrubutorMaintenanceEstimationShippingForProduct(Product $product,\DateTime $date)
{
//@Notes reminder of weekday per PHP doc just easier to read
$weekDayLabel = [
'Sunday' => 0,
'Monday' => 1,
'Tuesday' => 2,
'Wednesday' => 3,
'Thursday' => 4,
'Friday' => 5,
'Saturday' => 6
];
$now = $date;
$weekDay = $now->format('w');
$hour = $now->format('G');
//JIT product with past delivery time
if($product->getIsJustinTime() && !empty($product->getJustInTimeDeliveryDate())){
return $product->getJustInTimeDeliveryDate();
}
//if($product->getCompany()->getId() == 181 || $product->getIsJustInTime()){
if($product->getCompany()->getId() == 181 ){
return $date->modify("next week friday");
}
if($product->getIsJustinTime())
return $date->modify("next week friday");
//return new \DateTime("+6 weekdays");
//If it's a froozen product we ship until wednesday only
$froozenDays = array($weekDayLabel['Thursday'], $weekDayLabel['Friday'], $weekDayLabel['Saturday'], $weekDayLabel['Sunday']);
if($product->getIsFroozen() && in_array($weekDay,$froozenDays)){
return $date->modify("next thursday");
}
//We manage and overwrite Solex Estimation date
if($product->getIsJustinTime()){
//If we tuesday or past tuesday, order should be received next thursday
if($weekDay > $weekDayLabel['Monday']){
if($weekDay <= $weekDayLabel['Thursday'])
$estimationDate = $date->modify("thursday next week");
else
$estimationDate = $date->modify("next thursday");
return $estimationDate;
}else
return $date->modify("thursday");
}
if($weekDay == $weekDayLabel['Friday'])
return $date->modify("next tuesday");
if($hour <= 11 )
return $date->modify("+48 hours");
return $date->modify("+72 hours");
}
public function getReusableBoxProduct(){
$reusableBoxId=6472;
return $this->em->getRepository(Product::class)->findOneBy(['id' => $reusableBoxId]);
}
//fecth and update track pod order status
public function updateGoColisOrderStatus($order){
//dont call the APi service if order has been delivered
if($order->getTrackPodStatusId()== 4 || $order->isShippedLegacy()){
return true;
}
$this->trackPodServ->updateOrder($order);
return true;
}
/*
* Return a boolean if we display the survey or no
*/
public function getDisplaySurvey()
{
if($this->getStarterKits()){
$user=$this->userServ->getUser();
//Not a loggued user we dont display
if(!$user){
return false;
}
if($user->getDontShowSurvey()){
return false;
}
//If the user do not have the survey filled we display
if(empty($this->userServ->getUser()->getUserSurvey())){
if($user->getNextUserSurveyTime()){
$date = new DateTime();
if($date < $user->getNextUserSurveyTime() ){
return false;
}
}
return true;
}
}
return false;
}
public function getCountProduct($category)
{
$countProduct = $this->em->getRepository(Product::class)->getcategoriesByPlacement($category, null, null);
return count($countProduct);
}
public function getTheProduct($id)
{
$product = $this->em->getRepository(Product::class)->findOneBy(["id" => $id]);
return $product;
}
public function getTheCategoryProduct($id)
{
$category = $this->em->getRepository(Category::class)->findOneBy(["id" => $id]);
return $category;
}
public function getQuantityJitThisWeek($id)
{
$product = $this->em->getRepository(Product::class)->findOneBy(["id" => $id]);
$qtyWeeklySoldForProduct = $this->em->getRepository(CartProduct::class)->findWeeklyAlreadySoldForProductJit($id);
if (!$qtyWeeklySoldForProduct) {$qtyWeeklySoldForProduct = 0;}
$getQtyReadyToShip = $product->getQtyReadyToShip();
if ($getQtyReadyToShip) {
if($qtyWeeklySoldForProduct > $getQtyReadyToShip ) {
return false;
}else{
return true;
}
}
}
}