Added status change helper methods (setPaid / isPaid, etc)
This commit is contained in:
@@ -45,13 +45,14 @@ class Order extends BaseOrder
|
|||||||
return uniqid('ORD', true);
|
return uniqid('ORD', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* calculate the total amount
|
* Compute this order amount.
|
||||||
*
|
*
|
||||||
* @param int $tax
|
* @param float $tax (output only) returns the tax amount for this order
|
||||||
* @param bool $includePostage
|
* @param bool $includePostage if true, the postage cost is included to the total
|
||||||
*
|
* @param bool $includeDiscount if true, the discount will be included to the total
|
||||||
* @return float|int|string
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function getTotalAmount(&$tax = 0, $includePostage = true, $includeDiscount = true)
|
public function getTotalAmount(&$tax = 0, $includePostage = true, $includeDiscount = true)
|
||||||
{
|
{
|
||||||
@@ -93,4 +94,106 @@ class Order extends BaseOrder
|
|||||||
|
|
||||||
return $total;
|
return $total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the status of the current order to NOT PAID
|
||||||
|
*/
|
||||||
|
public function setNotPaid() {
|
||||||
|
$this->setStatusHelper(OrderStatus::CODE_NOT_PAID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current status of this order is NOT PAID
|
||||||
|
*
|
||||||
|
* @return bool true if this order is NOT PAID, false otherwise.
|
||||||
|
*/
|
||||||
|
public function isNotPaid() {
|
||||||
|
return $this->hasStatusHelper(OrderStatus::CODE_NOT_PAID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the status of the current order to PAID
|
||||||
|
*/
|
||||||
|
public function setPaid() {
|
||||||
|
$this->setStatusHelper(OrderStatus::CODE_PAID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current status of this order is PAID
|
||||||
|
*
|
||||||
|
* @return bool true if this order is PAID, false otherwise.
|
||||||
|
*/
|
||||||
|
public function isPaid() {
|
||||||
|
return $this->hasStatusHelper(OrderStatus::CODE_PAID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the status of the current order to PROCESSING
|
||||||
|
*/
|
||||||
|
public function setProcessing() {
|
||||||
|
$this->setStatusHelper(OrderStatus::CODE_PROCESSING);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current status of this order is PROCESSING
|
||||||
|
*
|
||||||
|
* @return bool true if this order is PROCESSING, false otherwise.
|
||||||
|
*/
|
||||||
|
public function isProcessing() {
|
||||||
|
return $this->hasStatusHelper(OrderStatus::CODE_PROCESSING);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the status of the current order to SENT
|
||||||
|
*/
|
||||||
|
public function setSent() {
|
||||||
|
$this->setStatusHelper(OrderStatus::CODE_SENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current status of this order is SENT
|
||||||
|
*
|
||||||
|
* @return bool true if this order is SENT, false otherwise.
|
||||||
|
*/
|
||||||
|
public function isSent() {
|
||||||
|
return $this->hasStatusHelper(OrderStatus::CODE_SENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the status of the current order to CANCELED
|
||||||
|
*/
|
||||||
|
public function setCancelled() {
|
||||||
|
$this->setStatusHelper(OrderStatus::CODE_CANCELED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current status of this order is CANCELED
|
||||||
|
*
|
||||||
|
* @return bool true if this order is CANCELED, false otherwise.
|
||||||
|
*/
|
||||||
|
public function isCancelled() {
|
||||||
|
return $this->hasStatusHelper(OrderStatus::CODE_CANCELED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the status of the current order to the provided status
|
||||||
|
*
|
||||||
|
* @param string $statusCode the status code, one of OrderStatus::CODE_xxx constants.
|
||||||
|
*/
|
||||||
|
public function setStatusHelper($statusCode) {
|
||||||
|
if (null !== $ordeStatus = OrderStatusQuery::create()->findOneByCode($statusCode)) {
|
||||||
|
$this->setOrderStatus($ordeStatus)->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current status of this order is $statusCode
|
||||||
|
*
|
||||||
|
* @param string $statusCode the status code, one of OrderStatus::CODE_xxx constants.
|
||||||
|
* @return bool true if this order have the provided status, false otherwise.
|
||||||
|
*/
|
||||||
|
public function hasStatusHelper($statusCode) {
|
||||||
|
return $this->getOrderStatus()->getCode() == $statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace Thelia\Tests\Action;
|
|||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||||
|
use Thelia\Action\Order;
|
||||||
use Thelia\Core\Event\Order\OrderAddressEvent;
|
use Thelia\Core\Event\Order\OrderAddressEvent;
|
||||||
use Thelia\Core\Event\Order\OrderEvent;
|
use Thelia\Core\Event\Order\OrderEvent;
|
||||||
use Thelia\Core\HttpFoundation\Request;
|
use Thelia\Core\HttpFoundation\Request;
|
||||||
@@ -37,18 +38,17 @@ use Thelia\Model\AddressQuery;
|
|||||||
use Thelia\Model\Base\OrderAddressQuery;
|
use Thelia\Model\Base\OrderAddressQuery;
|
||||||
use Thelia\Model\Base\OrderProductQuery;
|
use Thelia\Model\Base\OrderProductQuery;
|
||||||
use Thelia\Model\Base\OrderQuery;
|
use Thelia\Model\Base\OrderQuery;
|
||||||
|
|
||||||
use Thelia\Model\OrderStatus;
|
|
||||||
use Thelia\Model\ProductSaleElementsQuery;
|
|
||||||
use Thelia\Model\Cart;
|
use Thelia\Model\Cart;
|
||||||
use Thelia\Model\CartItem;
|
use Thelia\Model\CartItem;
|
||||||
use Thelia\Model\CurrencyQuery;
|
use Thelia\Model\CurrencyQuery;
|
||||||
|
use Thelia\Model\Customer as CustomerModel;
|
||||||
use Thelia\Model\CustomerQuery;
|
use Thelia\Model\CustomerQuery;
|
||||||
use Thelia\Model\ModuleQuery;
|
use Thelia\Model\ModuleQuery;
|
||||||
use Thelia\Model\Order as OrderModel;
|
use Thelia\Model\Order as OrderModel;
|
||||||
use Thelia\Model\Customer as CustomerModel;
|
use Thelia\Model\OrderStatus;
|
||||||
use Thelia\Action\Order;
|
use Thelia\Model\OrderStatusQuery;
|
||||||
use Thelia\Model\ProductQuery;
|
use Thelia\Model\ProductQuery;
|
||||||
|
use Thelia\Model\ProductSaleElementsQuery;
|
||||||
use Thelia\Module\BaseModule;
|
use Thelia\Module\BaseModule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -404,6 +404,101 @@ class OrderTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreate
|
||||||
|
*
|
||||||
|
* @param OrderModel $order
|
||||||
|
*/
|
||||||
|
public function testModelUpdateStatusPaidWithHelpers(OrderModel $order)
|
||||||
|
{
|
||||||
|
$order->setPaid();
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$order->getStatusId(),
|
||||||
|
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PAID)->getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$order->isPaid()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreate
|
||||||
|
*
|
||||||
|
* @param OrderModel $order
|
||||||
|
*/
|
||||||
|
public function testModelUpdateStatusNotPaidWithHelpers(OrderModel $order)
|
||||||
|
{
|
||||||
|
$order->setNotPaid();
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$order->getStatusId(),
|
||||||
|
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_NOT_PAID)->getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$order->isNotPaid()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreate
|
||||||
|
*
|
||||||
|
* @param OrderModel $order
|
||||||
|
*/
|
||||||
|
public function testModelUpdateStatusProcessedWithHelpers(OrderModel $order)
|
||||||
|
{
|
||||||
|
$order->setProcessing();
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$order->getStatusId(),
|
||||||
|
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PROCESSING)->getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$order->isProcessing()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreate
|
||||||
|
*
|
||||||
|
* @param OrderModel $order
|
||||||
|
*/
|
||||||
|
public function testModelUpdateStatusSentWithHelpers(OrderModel $order)
|
||||||
|
{
|
||||||
|
$order->setSent();
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$order->getStatusId(),
|
||||||
|
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_SENT)->getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$order->isSent()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testCreate
|
||||||
|
*
|
||||||
|
* @param OrderModel $order
|
||||||
|
*/
|
||||||
|
public function testModelUpdateStatusCanceledWithHelpers(OrderModel $order)
|
||||||
|
{
|
||||||
|
$order->setCancelled();
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$order->getStatusId(),
|
||||||
|
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_CANCELED)->getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$order->isCancelled()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testCreate
|
* @depends testCreate
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user