WIP
- Add Coupon Event - Customer Parameter
This commit is contained in:
@@ -43,6 +43,29 @@ use Propel\Runtime\Exception\PropelException;
|
||||
class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Disable a Coupon
|
||||
*
|
||||
* @param ActionEvent $event
|
||||
*/
|
||||
public function delete(CategoryDeleteEvent $event)
|
||||
{
|
||||
$this->checkAuth("ADMIN", "admin.category.delete");
|
||||
|
||||
$category = CategoryQuery::create()->findPk($event->getId());
|
||||
|
||||
if ($category !== null) {
|
||||
|
||||
$event->setDeletedCategory($category);
|
||||
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_DELETECATEGORY, $event);
|
||||
|
||||
$category->delete();
|
||||
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_DELETECATEGORY, $event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber listens to.
|
||||
*
|
||||
|
||||
82
core/lib/Thelia/Core/Event/Coupon/CouponCreateEvent.php
Normal file
82
core/lib/Thelia/Core/Event/Coupon/CouponCreateEvent.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Coupon;
|
||||
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
class CouponCreateEvent extends ActionEvent
|
||||
{
|
||||
protected $title;
|
||||
protected $parent;
|
||||
protected $locale;
|
||||
protected $created_category;
|
||||
|
||||
public function __construct($title, $parent, $locale)
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->parent = $parent;
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
public function setParent($parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
public function getCreatedCategory()
|
||||
{
|
||||
return $this->created_category;
|
||||
}
|
||||
|
||||
public function setCreatedCategory(Category $created_category)
|
||||
{
|
||||
$this->created_category = $created_category;
|
||||
var_dump($this->created_category);
|
||||
}
|
||||
}
|
||||
103
core/lib/Thelia/Core/Event/Coupon/CouponDisableEvent.php
Normal file
103
core/lib/Thelia/Core/Event/Coupon/CouponDisableEvent.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Coupon;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Occurring when a Coupon is disabled
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponDisableEvent extends ActionEvent
|
||||
{
|
||||
/** @var int Coupon id */
|
||||
protected $couponId;
|
||||
|
||||
/** @var Coupon Coupon being disabled */
|
||||
protected $disabledCoupon;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Coupon Id
|
||||
*/
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon id
|
||||
*
|
||||
* @param int $id Coupon id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon being disabled
|
||||
*
|
||||
* @return Coupon
|
||||
*/
|
||||
public function getDisabledCoupon()
|
||||
{
|
||||
return $this->disabledCoupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon to be disabled
|
||||
*
|
||||
* @param Coupon $disabledCoupon Coupon to disable
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDisabledCoupon(Coupon $disabledCoupon)
|
||||
{
|
||||
$this->disabledCoupon = $disabledCoupon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
103
core/lib/Thelia/Core/Event/Coupon/CouponEnableEvent.php
Normal file
103
core/lib/Thelia/Core/Event/Coupon/CouponEnableEvent.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Event\Coupon;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Occurring when a Coupon is enabled
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponEnableEvent extends ActionEvent
|
||||
{
|
||||
/** @var int Coupon id */
|
||||
protected $couponId;
|
||||
|
||||
/** @var Coupon Coupon being enabled */
|
||||
protected $enabledCoupon;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Coupon Id
|
||||
*/
|
||||
public function __construct($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon id
|
||||
*
|
||||
* @param int $id Coupon id
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon being enabled
|
||||
*
|
||||
* @return Coupon
|
||||
*/
|
||||
public function getEnabledCoupon()
|
||||
{
|
||||
return $this->enabledCoupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon to be enabled
|
||||
*
|
||||
* @param Coupon $enabledCoupon Coupon to enabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEnabledCoupon(Coupon $enabledCoupon)
|
||||
{
|
||||
$this->enabledCoupon = $enabledCoupon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -298,7 +298,7 @@ abstract class RewritingUrl implements ActiveRecordInterface
|
||||
*/
|
||||
public function hasVirtualColumn($name)
|
||||
{
|
||||
return array_key_exists($name, $this->virtualColumns);
|
||||
return isset($this->virtualColumns[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
161
core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php
Normal file
161
core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Constraint\Validator\CustomerParam;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\QuantityParam;
|
||||
use Thelia\Model\Customer;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test CustomerParam Class
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CustomerParamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
protected $stubTheliaAdapter = null;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate valid CouponBaseAdapter
|
||||
*
|
||||
* @param int $customerId Customer id
|
||||
*
|
||||
* @return CouponAdapterInterface
|
||||
*/
|
||||
protected function generateValidCouponBaseAdapterMock($customerId = 4521)
|
||||
{
|
||||
$customer = new Customer();
|
||||
$customer->setId($customerId);
|
||||
$customer->setFirstname('Firstname');
|
||||
$customer->setLastname('Lastname');
|
||||
$customer->setEmail('em@il.com');
|
||||
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->getMock(
|
||||
'Thelia\Coupon\CouponBaseAdapter',
|
||||
array('getCustomer'),
|
||||
array()
|
||||
);
|
||||
$stubTheliaAdapter->expects($this->any())
|
||||
->method('getCustomer')
|
||||
->will($this->returnValue($customer));
|
||||
|
||||
return $stubTheliaAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testCanUseCoupon()
|
||||
{
|
||||
$customerId = 4521;
|
||||
$couponValidForCustomerId = 4521;
|
||||
|
||||
$adapter = $this->generateValidCouponBaseAdapterMock($customerId);
|
||||
|
||||
$customerParam = new CustomerParam($adapter, $couponValidForCustomerId);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $customerParam->compareTo($customerId);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
|
||||
// *
|
||||
// */
|
||||
// public function testCanNotUseCouponTest()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
|
||||
// * @expectedException InvalidArgumentException
|
||||
// *
|
||||
// */
|
||||
// public function testCanNotUseCouponCustomerNotFoundTest()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * Test is the object is serializable
|
||||
// * If no data is lost during the process
|
||||
// */
|
||||
// public function isSerializableTest()
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $intValidator = 42;
|
||||
// $intToValidate = -1;
|
||||
//
|
||||
// $param = new QuantityParam($adapter, $intValidator);
|
||||
//
|
||||
// $serialized = base64_encode(serialize($param));
|
||||
// /** @var QuantityParam $unserialized */
|
||||
// $unserialized = base64_decode(serialize($serialized));
|
||||
//
|
||||
// $this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
// $this->assertEquals($param->getInteger(), $unserialized->getInteger());
|
||||
//
|
||||
// $new = new QuantityParam($adapter, $unserialized->getInteger());
|
||||
// $this->assertEquals($param->getInteger(), $new->getInteger());
|
||||
// }
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user