Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View File

@@ -3,6 +3,7 @@
namespace Thelia\Model;
use Thelia\Model\Base\OrderStatusQuery as BaseOrderStatusQuery;
use Thelia\Model\Exception\InvalidArgumentException;
/**
* Skeleton subclass for performing query and update operations on the 'order_status' table.
@@ -16,30 +17,158 @@ use Thelia\Model\Base\OrderStatusQuery as BaseOrderStatusQuery;
*/
class OrderStatusQuery extends BaseOrderStatusQuery
{
protected static $statusIdListsCache = [];
protected static $statusModelCache = [];
public static function getNotPaidStatus()
{
return OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_NOT_PAID);
return self::getStatusModelFromCode(OrderStatus::CODE_NOT_PAID);
}
public static function getPaidStatus()
{
return OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PAID);
return self::getStatusModelFromCode(OrderStatus::CODE_PAID);
}
public static function getProcessingStatus()
{
return OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PROCESSING);
return self::getStatusModelFromCode(OrderStatus::CODE_PROCESSING);
}
public static function getSentStatus()
{
return OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_SENT);
return self::getStatusModelFromCode(OrderStatus::CODE_SENT);
}
public static function getCancelledStatus()
{
return OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_CANCELED);
return self::getStatusModelFromCode(OrderStatus::CODE_CANCELED);
}
} // OrderStatusQuery
public static function getRefundedStatus()
{
return self::getStatusModelFromCode(OrderStatus::CODE_REFUNDED);
}
public static function getStatusModelFromCode($statusCode)
{
if (! isset(self::$statusModelCache[$statusCode])) {
self::$statusModelCache[$statusCode] = OrderStatusQuery::create()->findOneByCode($statusCode);
}
return self::$statusModelCache[$statusCode];
}
/**
* Return the list of order status IDs for which an order is considered as not paid
*
* @return array
*/
public static function getNotPaidStatusIdList()
{
return self::getStatusIdList(OrderStatus::CODE_NOT_PAID);
}
/**
* Return the list of order status IDs for which an order is considered as paid
*
* @return array
*/
public static function getPaidStatusIdList()
{
return self::getStatusIdList(OrderStatus::CODE_PAID);
}
/**
* Return the list of order status IDs for which an order is considered as in process
*
* @return array
*/
public static function getProcessingStatusIdList()
{
return self::getStatusIdList(OrderStatus::CODE_PROCESSING);
}
/**
* Return the list of order status IDs for which an order is considered as sent
*
* @return array
*/
public static function getSentStatusIdList()
{
return self::getStatusIdList(OrderStatus::CODE_SENT);
}
/**
* Return the list of order status IDs for which an order is considered as canceled
*
* @return array
*/
public static function getCanceledStatusIdList()
{
return self::getStatusIdList(OrderStatus::CODE_CANCELED);
}
/**
* Return the list of order status IDs for which an order is considered as refunded
*
* @return array
*/
public static function getRefundedStatusIdList()
{
return self::getStatusIdList(OrderStatus::CODE_REFUNDED);
}
/**
* Return a list of status IDs which match $statusCode value.
*
* @param string $statusCode the satus code
* @return array
*/
public static function getStatusIdList($statusCode)
{
if (! isset(self::$statusIdListsCache[$statusCode])) {
$statusIdList = [];
$statusList = OrderStatusQuery::create()->find();
/** @var OrderStatus $status */
foreach ($statusList as $status) {
switch ($statusCode) {
case OrderStatus::CODE_NOT_PAID:
$match = $status->isNotPaid(false);
break;
case OrderStatus::CODE_PAID:
$match = $status->isPaid(false);
break;
case OrderStatus::CODE_PROCESSING:
$match = $status->isProcessing(false);
break;
case OrderStatus::CODE_SENT:
$match = $status->isSent(false);
break;
case OrderStatus::CODE_CANCELED:
$match = $status->isCancelled(false);
break;
case OrderStatus::CODE_REFUNDED:
$match = $status->isRefunded(false);
break;
default:
throw new InvalidArgumentException("Status code '$statusCode' is not a valid value.");
}
if ($match) {
$statusIdList[] = $status->getId();
}
}
self::$statusIdListsCache[$statusCode] = $statusIdList;
}
return self::$statusIdListsCache[$statusCode];
}
}
// OrderStatusQuery