Merge branch 'master' into frontend

Conflicts:
	templates/default/layout.tpl
This commit is contained in:
Manuel Raynaud
2013-10-25 14:51:34 +02:00
141 changed files with 3772 additions and 2614 deletions

12
CONTRIBUTORS.txt Normal file
View File

@@ -0,0 +1,12 @@
If you contributes or contributed to this project and do not appear in this list below,
please email us (info@thelia.net) or fork this file on Github and send a pull-request.
Manuel Raynaud - mraynaud@openstudio.fr
Etienne Roudeix - eroudeix@openstudio.fr
Franck Allimant - franck@allimant.org
Guillaume Morel - gmorel@openstudio.fr
Michael Espeche - mespeche@openstudio.fr
Christophe Laffont - claffont@openstudio.fr
Bruno Goléo - bgoleo@openstudio.fr
Stéphanie Pinet - spinet@openstudio.fr
Cédric Sibaud - csibaud@openstudio.fr

View File

@@ -1,5 +1,4 @@
THELIA
Copyright (C) 2005-2013 par OpenStudio
If you contribute to THELIA and you are not in the contributor list, please contact us.
Copyright (C) 2005 OpenStudio
THELIA application uses externals components and libraries which are released under their own GPL compatible license terms.

View File

@@ -1,165 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@@ -2,7 +2,7 @@
"name" : "thelia/thelia",
"description" : "Thelia is an ecommerce CMS.",
"license" : "GPL-3.0+",
"homepage" : "http://thelia.net",
"homepage" : "http://thelia.net/v2",
"support" : {
"forum" : "http://thelia.net/forum",
"wiki" : "http://thelia.net/wiki"

2
composer.lock generated
View File

@@ -3,7 +3,7 @@
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "4f3fabbb795a71df45ae9f6ccb6df355",
"hash": "009aced8b279e1c14558460fff2cc993",
"packages": [
{
"name": "ensepar/html2pdf",

View File

@@ -23,11 +23,9 @@
namespace Thelia\Action;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Administrator\AdministratorEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Security\AccessManager;
use Thelia\Model\Admin as AdminModel;
use Thelia\Model\AdminQuery;
@@ -69,7 +67,7 @@ class Administrator extends BaseAction implements EventSubscriberInterface
->setProfileId($event->getProfile())
;
if('' !== $event->getPassword()) {
if ('' !== $event->getPassword()) {
$administrator->setPassword($event->getPassword());
}

View File

@@ -124,11 +124,17 @@ class Coupon extends BaseAction implements EventSubscriberInterface
// @todo insert false product in cart with the name of the coupon and the discount as negative price
// Decrement coupon quantity
// @todo move this part in after order event
$couponQuery = CouponQuery::create();
$couponModel = $couponQuery->findOneByCode($coupon->getCode());
$couponManager->decrementeQuantity($couponModel);
$request->getSession()->getCart()->setDiscount($totalDiscount);
$request
->getSession()
->getCart()
->setDiscount($totalDiscount)
->save()
;
}

View File

@@ -34,7 +34,6 @@ use Thelia\Model\ConfigQuery;
use Thelia\Model\LangQuery;
use Thelia\Model\Lang as LangModel;
/**
* Class Lang
* @package Thelia\Action
@@ -105,7 +104,7 @@ class Lang extends BaseAction implements EventSubscriberInterface
public function langUrl(LangUrlEvent $event)
{
foreach($event->getUrl() as $id => $url){
foreach ($event->getUrl() as $id => $url) {
LangQuery::create()
->filterById($id)
->update(array('Url' => $url));
@@ -143,4 +142,4 @@ class Lang extends BaseAction implements EventSubscriberInterface
TheliaEvents::LANG_URL => array('langUrl', 128)
);
}
}
}

View File

@@ -70,7 +70,7 @@ class Module extends BaseAction implements EventSubscriberInterface
$con->beginTransaction();
try {
if(null === $module->getFullNamespace()) {
if (null === $module->getFullNamespace()) {
throw new \LogicException('can not instanciante this module if namespace is null. Maybe the model is not loaded ?');
}

View File

@@ -29,7 +29,6 @@ use Thelia\Action\BaseAction;
use Thelia\Model\NewsletterQuery;
use Thelia\Model\Newsletter as NewsletterModel;
/**
* Class Newsletter
* @package Thelia\Action
@@ -52,14 +51,14 @@ class Newsletter extends BaseAction implements EventSubscriberInterface
public function unsubscribe(NewsletterEvent $event)
{
if(null !== $nl = NewsletterQuery::create()->findPk($event->getId())) {
if (null !== $nl = NewsletterQuery::create()->findPk($event->getId())) {
$nl->delete();
}
}
public function update(NewsletterEvent $event)
{
if(null !== $nl = NewsletterQuery::create()->findPk($event->getId())) {
if (null !== $nl = NewsletterQuery::create()->findPk($event->getId())) {
$nl->setEmail($event->getEmail())
->setFirstname($event->getFirstname())
->setLastname($event->getLastname())
@@ -96,4 +95,4 @@ class Newsletter extends BaseAction implements EventSubscriberInterface
TheliaEvents::NEWSLETTER_UNSUBSCRIBE => array('unsubscribe', 128)
);
}
}
}

View File

@@ -32,6 +32,8 @@ use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Exception\TheliaProcessException;
use Thelia\Model\AddressQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\MessageQuery;
use Thelia\Model\OrderProductAttributeCombination;
use Thelia\Model\ModuleQuery;
use Thelia\Model\OrderProduct;
@@ -291,7 +293,50 @@ class Order extends BaseAction implements EventSubscriberInterface
*/
public function sendOrderEmail(OrderEvent $event)
{
/* @todo */
$contact_email = ConfigQuery::read('contact_email');
if($contact_email) {
$order = $event->getOrder();
$customer = $order->getCustomer();
$parser = $this->container->get("thelia.parser");
$parser->assign('order_id', $order->getId());
$parser->assign('order_ref', $order->getRef());
$message = MessageQuery::create()
->filterByName('order_confirmation')
->findOne();
$message
->setLocale($order->getLang()->getLocale());
$subject = $parser->fetch(sprintf("string:%s", $message->getSubject()));
$htmlMessage = $parser->fetch(sprintf("string:%s", $message->getHtmlMessage()));
$textMessage = $parser->fetch(sprintf("string:%s", $message->getTextMessage()));
$instance = \Swift_Message::newInstance($subject)
->addTo($customer->getEmail(), $customer->getFirstname()." ".$customer->getLastname())
->addFrom(ConfigQuery::read('contact_email'), ConfigQuery::read('company_name'))
;
$instance
->setBody($htmlMessage, 'text/html')
->addPart($textMessage, 'text/plain');
$mail = $this->getMailer()->send($instance);
}
}
/**
*
* return an instance of \Swift_Mailer with good Transporter configured.
*
* @return \Swift_Mailer
*/
public function getMailer()
{
$mailer = $this->container->get('mailer');
return $mailer->getSwiftMailer();
}
/**

View File

@@ -52,14 +52,6 @@ use Thelia\Core\Event\Product\ProductSetTemplateEvent;
use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Core\Event\Product\ProductDeleteCategoryEvent;
use Thelia\Core\Event\Product\ProductAddCategoryEvent;
use Thelia\Model\AttributeAvQuery;
use Thelia\Model\AttributeCombination;
use Thelia\Core\Event\Product\ProductSaleElementCreateEvent;
use Propel\Runtime\Propel;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Core\Event\Product\ProductSaleElementDeleteEvent;
use Thelia\Model\ProductPrice;
use Thelia\Model\ProductSaleElements;
use Thelia\Core\Event\Product\ProductAddAccessoryEvent;
use Thelia\Core\Event\Product\ProductDeleteAccessoryEvent;

View File

@@ -25,9 +25,6 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Model\ProductQuery;
use Thelia\Model\Product as ProductModel;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Event\ProductSaleElement\ProductSaleElementCreateEvent;
use Thelia\Model\Map\ProductSaleElementsTableMap;
@@ -49,7 +46,7 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
/**
* Create a new product sale element, with or without combination
*
* @param ProductSaleElementCreateEvent $event
* @param ProductSaleElementCreateEvent $event
* @throws Exception
*/
public function create(ProductSaleElementCreateEvent $event)
@@ -67,11 +64,10 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
->findOne($con);
if ($salesElement == null) {
// Create a new product sale element
// Create a new default product sale element
$salesElement = $event->getProduct()->createDefaultProductSaleElement($con, 0, 0, $event->getCurrencyId(), true);
}
else {
// This one is the default
} else {
// This (new) one is the default
$salesElement->setIsDefault(true)->save($con);
}
@@ -98,8 +94,7 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
// Store all the stuff !
$con->commit();
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
$con->rollback();
@@ -122,6 +117,9 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
try {
// Update the product's tax rule
$event->getProduct()->setTaxRuleId($event->getTaxRuleId())->save($con);
// If product sale element is not defined, create it.
if ($salesElement == null) {
$salesElement = new ProductSaleElements();
@@ -158,16 +156,28 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
;
}
$productPrice
->setPromoPrice($event->getSalePrice())
->setPrice($event->getPrice())
->save($con)
;
// Check if we have to store the price
$productPrice->setFromDefaultCurrency($event->getFromDefaultCurrency());
if ($event->getFromDefaultCurrency() == 0) {
// Store the price
$productPrice
->setPromoPrice($event->getSalePrice())
->setPrice($event->getPrice())
;
} else {
// Do not store the price.
$productPrice
->setPromoPrice(0)
->setPrice(0)
;
}
$productPrice->save($con);
// Store all the stuff !
$con->commit();
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
$con->rollback();
@@ -197,19 +207,21 @@ class ProductSaleElement extends BaseAction implements EventSubscriberInterface
if ($product->countSaleElements() <= 0) {
// If we just deleted the last PSE, create a default one
$product->createDefaultProductSaleElement($con, 0, 0, $event->getCurrencyId(), true);
}
else if ($product->getDefaultSaleElements() == null) {
} elseif ($pse->getIsDefault()) {
// If we deleted the default PSE, make the last created one the default
$pse = ProductSaleElementsQuery::create()->filterByProductId($this->id)->orderByCreatedAt(Criteria::DESC)->findOne($con);
$pse = ProductSaleElementsQuery::create()
->filterByProductId($product->getId())
->orderByCreatedAt(Criteria::DESC)
->findOne($con)
;
$pse->setIsDefault(true)->save($con);
}
// Store all the stuff !
$con->commit();
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
$con->rollback();

View File

@@ -23,7 +23,6 @@
namespace Thelia\Action;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Profile\ProfileEvent;
use Thelia\Core\Event\TheliaEvents;
@@ -90,7 +89,7 @@ class Profile extends BaseAction implements EventSubscriberInterface
{
if (null !== $profile = ProfileQuery::create()->findPk($event->getId())) {
ProfileResourceQuery::create()->filterByProfileId($event->getId())->delete();
foreach($event->getResourceAccess() as $resourceCode => $accesses) {
foreach ($event->getResourceAccess() as $resourceCode => $accesses) {
$manager = new AccessManager(0);
$manager->build($accesses);
@@ -114,7 +113,7 @@ class Profile extends BaseAction implements EventSubscriberInterface
{
if (null !== $profile = ProfileQuery::create()->findPk($event->getId())) {
ProfileModuleQuery::create()->filterByProfileId($event->getId())->delete();
foreach($event->getModuleAccess() as $moduleCode => $accesses) {
foreach ($event->getModuleAccess() as $moduleCode => $accesses) {
$manager = new AccessManager(0);
$manager->build($accesses);

View File

@@ -23,7 +23,6 @@
namespace Thelia\Action;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Tax\TaxEvent;
use Thelia\Core\Event\TheliaEvents;

View File

@@ -27,7 +27,6 @@ use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Thelia\Core\Event\Tax\TaxRuleEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Map\TaxRuleTableMap;
use Thelia\Model\TaxRuleCountry;
use Thelia\Model\TaxRuleCountryQuery;
use Thelia\Model\TaxRule as TaxRuleModel;

View File

@@ -61,19 +61,19 @@ class GenerateResources extends ContainerAwareCommand
$constants = $class->getConstants();
if(count($constants) == 0) {
if (count($constants) == 0) {
$output->writeln('No resources found');
exit;
}
switch($input->getOption("output")) {
switch ($input->getOption("output")) {
case 'sql':
$output->writeln(
'INSERT INTO ' . ResourceTableMap::TABLE_NAME . ' (`id`, `code`, `created_at`, `updated_at`) VALUES '
);
$compteur = 0;
foreach($constants as $constant => $value) {
if($constant == AdminResources::SUPERADMINISTRATOR) {
foreach ($constants as $constant => $value) {
if ($constant == AdminResources::SUPERADMINISTRATOR) {
continue;
}
$compteur++;
@@ -87,8 +87,8 @@ class GenerateResources extends ContainerAwareCommand
'INSERT INTO ' . ResourceI18nTableMap::TABLE_NAME . ' (`id`, `locale`, `title`) VALUES '
);
$compteur = 0;
foreach($constants as $constant => $value) {
if($constant == AdminResources::SUPERADMINISTRATOR) {
foreach ($constants as $constant => $value) {
if ($constant == AdminResources::SUPERADMINISTRATOR) {
continue;
}
@@ -105,8 +105,8 @@ class GenerateResources extends ContainerAwareCommand
}
break;
default :
foreach($constants as $constant => $value) {
if($constant == AdminResources::SUPERADMINISTRATOR) {
foreach ($constants as $constant => $value) {
if ($constant == AdminResources::SUPERADMINISTRATOR) {
continue;
}
$output->writeln('[' . $constant . "] => " . $value);

View File

@@ -174,7 +174,7 @@
<requirement key="order_id">\d+</requirement>
</route>
<route id="admin.order.pdf.invoice" path="/admin/order/pdf/delivery/{order_id}">
<route id="admin.order.pdf.delivery" path="/admin/order/pdf/delivery/{order_id}">
<default key="_controller">Thelia\Controller\Admin\OrderController::generateDeliveryPdf</default>
<requirement key="order_id">\d+</requirement>
</route>
@@ -303,10 +303,14 @@
<default key="_controller">Thelia\Controller\Admin\ProductController::updateContentPositionAction</default>
</route>
<route id="admin.product.update-content-position" path="/admin/product/calculate-price">
<route id="admin.product.calculate-price" path="/admin/product/calculate-price">
<default key="_controller">Thelia\Controller\Admin\ProductController::priceCaclulator</default>
</route>
<route id="admin.product.load-converted-prices" path="/admin/product/load-converted-prices">
<default key="_controller">Thelia\Controller\Admin\ProductController::loadConvertedPrices</default>
</route>
<!-- accessories -->
<route id="admin.products.accessories.add" path="/admin/products/accessory/add">
@@ -360,8 +364,8 @@
<default key="_controller">Thelia\Controller\Admin\ProductController::deleteProductSaleElementAction</default>
</route>
<route id="admin.product.combination.update" path="/admin/product/combination/update">
<default key="_controller">Thelia\Controller\Admin\ProductController::updateProductSaleElementAction</default>
<route id="admin.product.combination.update" path="/admin/product/combinations/update">
<default key="_controller">Thelia\Controller\Admin\ProductController::updateProductSaleElementsAction</default>
</route>
<route id="admin.product.combination.defaut-price.update" path="/admin/product/default-price/update">

View File

@@ -56,7 +56,7 @@ abstract class AbstractCrudController extends BaseAdminController
* @param string $defaultListOrder the default object list order, or null if list is not sortable. Example: manual
* @param string $orderRequestParameterName Name of the request parameter that set the list order (null if list is not sortable)
*
* @param string $resourceCode the 'resource' code. Example: "admin.configuration.message"
* @param string $resourceCode the 'resource' code. Example: "admin.configuration.message"
*
* @param string $createEventIdentifier the dispatched create TheliaEvent identifier. Example: TheliaEvents::MESSAGE_CREATE
* @param string $updateEventIdentifier the dispatched update TheliaEvent identifier. Example: TheliaEvents::MESSAGE_UPDATE

View File

@@ -23,7 +23,6 @@
namespace Thelia\Controller\Admin;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Event\Administrator\AdministratorEvent;
use Thelia\Core\Event\TheliaEvents;
@@ -31,7 +30,6 @@ use Thelia\Form\AdministratorCreationForm;
use Thelia\Form\AdministratorModificationForm;
use Thelia\Model\AdminQuery;
class AdministratorController extends AbstractCrudController
{
public function __construct()
@@ -158,7 +156,6 @@ class AdministratorController extends AbstractCrudController
return $object->getId();
}
protected function renderListTemplate($currentOrder)
{
// We always return to the feature edition form
@@ -198,4 +195,4 @@ class AdministratorController extends AbstractCrudController
"admin.configuration.administrators.view"
);
}
}
}

View File

@@ -47,10 +47,7 @@ class AttributeAvController extends AbstractCrudController
'manual',
'order',
AdminResources::ATTRIBUTE_VIEW,
AdminResources::ATTRIBUTE_CREATE,
AdminResources::ATTRIBUTE_UPDATE,
AdminResources::ATTRIBUTE_DELETE,
AdminResources::ATTRIBUTE,
TheliaEvents::ATTRIBUTE_AV_CREATE,
TheliaEvents::ATTRIBUTE_AV_UPDATE,

View File

@@ -115,7 +115,7 @@ class BaseAdminController extends BaseController
* Check current admin user authorisations. An ADMIN role is assumed.
*
* @param mixed $resources a single resource or an array of resources.
* @param mixed $accesses a single access or an array of accesses.
* @param mixed $accesses a single access or an array of accesses.
*
* @return mixed null if authorization is granted, or a Response object which contains the error page otherwise
*
@@ -369,8 +369,8 @@ class BaseAdminController extends BaseController
* Render the given template, and returns the result as an Http Response.
*
* @param $templateName the complete template name, with extension
* @param array $args the template arguments
* @param int $status http code status
* @param array $args the template arguments
* @param int $status http code status
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function render($templateName, $args = array(), $status = 200)

View File

@@ -522,7 +522,7 @@ class CouponController extends BaseAdminController
$condition = array();
$condition['serviceId'] = $availableCondition->getServiceId();
$condition['name'] = $availableCondition->getName();
$condition['toolTip'] = $availableCondition->getToolTip();
// $condition['toolTip'] = $availableCondition->getToolTip();
$cleanedConditions[] = $condition;
}

View File

@@ -32,6 +32,7 @@ use Thelia\Model\CurrencyQuery;
use Thelia\Form\CurrencyModificationForm;
use Thelia\Form\CurrencyCreationForm;
use Thelia\Core\Event\UpdatePositionEvent;
use Thelia\Core\Security\AccessManager;
/**
* Manages currencies

View File

@@ -25,7 +25,6 @@ namespace Thelia\Controller\Admin;
use Propel\Runtime\Exception\PropelException;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Event\Customer\CustomerAddressEvent;
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\Customer\CustomerEvent;
use Thelia\Core\Event\TheliaEvents;

View File

@@ -47,10 +47,7 @@ class FeatureAvController extends AbstractCrudController
'manual',
'order',
AdminResources::FEATURE_VIEW,
AdminResources::FEATURE_CREATE,
AdminResources::FEATURE_UPDATE,
AdminResources::FEATURE_DELETE,
AdminResources::FEATURE,
TheliaEvents::FEATURE_AV_CREATE,
TheliaEvents::FEATURE_AV_UPDATE,

View File

@@ -41,7 +41,6 @@ use Thelia\Form\Lang\LangUrlForm;
use Thelia\Model\ConfigQuery;
use Thelia\Model\LangQuery;
/**
* Class LangController
* @package Thelia\Controller\Admin
@@ -53,7 +52,6 @@ class LangController extends BaseAdminController
public function defaultAction()
{
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::VIEW)) return $response;
return $this->renderDefault();
}
@@ -120,7 +118,7 @@ class LangController extends BaseAdminController
$changedObject = $event->getLang();
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", 'Lang', $changedObject->getTitle(), $changedObject->getId()));
$this->redirectToRoute('/admin/configuration/languages');
} catch(\Exception $e) {
} catch (\Exception $e) {
$error_msg = $e->getMessage();
}
@@ -162,7 +160,7 @@ class LangController extends BaseAdminController
$error = $e->getMessage();
}
if($error) {
if ($error) {
return $this->nullResponse(500);
} else {
return $this->nullResponse();
@@ -281,7 +279,7 @@ class LangController extends BaseAdminController
$event = new LangUrlEvent();
foreach ($data as $key => $value) {
$pos= strpos($key, LangUrlForm::LANG_PREFIX);
if(false !== strpos($key, LangUrlForm::LANG_PREFIX)) {
if (false !== strpos($key, LangUrlForm::LANG_PREFIX)) {
$event->addUrl(substr($key,strlen(LangUrlForm::LANG_PREFIX)), $value);
}
}
@@ -326,4 +324,4 @@ class LangController extends BaseAdminController
$this->redirectToRoute('admin.configuration.languages');
}
}
}

View File

@@ -38,5 +38,5 @@ class LanguageController extends BaseAdminController
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::VIEW)) return $response;
return $this->render("languages");
}
}
}

View File

@@ -38,5 +38,5 @@ class MailingSystemController extends BaseAdminController
if (null !== $response = $this->checkAuth(AdminResources::MAILING_SYSTEM, AccessManager::VIEW)) return $response;
return $this->render("mailing-system");
}
}
}

View File

@@ -45,10 +45,7 @@ class MessageController extends AbstractCrudController
null, // no sort order change
null, // no sort order change
AdminResources::MESSAGE_VIEW,
AdminResources::MESSAGE_CREATE,
AdminResources::MESSAGE_UPDATE,
AdminResources::MESSAGE_DELETE,
AdminResources::MESSAGE,
TheliaEvents::MESSAGE_CREATE,
TheliaEvents::MESSAGE_UPDATE,

View File

@@ -41,7 +41,7 @@ class ModuleController extends BaseAdminController
public function indexAction()
{
if (null !== $response = $this->checkAuth(AdminResources::MODULE, AccessManager::VIEW)) return $response;
$modulemanagement = new ModuleManagement();
$modulemanagement->updateModules();
@@ -100,7 +100,7 @@ class ModuleController extends BaseAdminController
$this->dispatch(TheliaEvents::MODULE_DELETE, $deleteEvent);
if($deleteEvent->hasModule() === false) {
if ($deleteEvent->hasModule() === false) {
throw new \LogicException(
$this->getTranslator()->trans("No %obj was updated.", array('%obj' => 'Module')));
}
@@ -110,7 +110,7 @@ class ModuleController extends BaseAdminController
$message = $e->getMessage();
}
if($message) {
if ($message) {
return $this->render("modules", array(
"error_message" => $message
));

View File

@@ -54,7 +54,6 @@ use Thelia\Core\Event\ProductSaleElement\ProductSaleElementCreateEvent;
use Thelia\Model\AttributeQuery;
use Thelia\Model\AttributeAvQuery;
use Thelia\Form\ProductSaleElementUpdateForm;
use Thelia\Model\ProductSaleElements;
use Thelia\Model\ProductPriceQuery;
use Thelia\Form\ProductDefaultSaleElementUpdateForm;
use Thelia\Model\ProductPrice;
@@ -62,9 +61,9 @@ use Thelia\Model\Currency;
use Symfony\Component\HttpFoundation\JsonResponse;
use Thelia\TaxEngine\Calculator;
use Thelia\Model\Country;
use Thelia\Model\CountryQuery;
use Thelia\Model\TaxRuleQuery;
use Thelia\Tools\NumberFormat;
use Thelia\Model\Product;
use Thelia\Model\CurrencyQuery;
/**
* Manages products
@@ -187,52 +186,115 @@ class ProductController extends AbstractCrudController
return $event->hasProduct();
}
protected function updatePriceFromDefaultCurrency($productPrice, $saleElement, $defaultCurrency, $currentCurrency)
{
// Get price for default currency
$priceForDefaultCurrency = ProductPriceQuery::create()
->filterByCurrency($defaultCurrency)
->filterByProductSaleElements($saleElement)
->findOne()
;
if ($priceForDefaultCurrency !== null) {
$productPrice
->setPrice($priceForDefaultCurrency->getPrice() * $currentCurrency->getRate())
->setPromoPrice($priceForDefaultCurrency->getPromoPrice() * $currentCurrency->getRate())
;
}
}
protected function appendValue(&$array, $key, $value)
{
if (! isset($array[$key])) $array[$key] = array();
$array[$key][] = $value;
}
protected function hydrateObjectForm($object)
{
$defaultPseData = $combinationPseData = array();
// Find product's sale elements
$saleElements = ProductSaleElementsQuery::create()
->filterByProduct($object)
->find();
foreach($saleElements as $saleElement) {
$defaultCurrency = Currency::getDefaultCurrency();
$currentCurrency = $this->getCurrentEditionCurrency();
// Common parts
$defaultPseData = $combinationPseData = array(
"product_id" => $object->getId(),
"tax_rule" => $object->getTaxRuleId()
);
foreach ($saleElements as $saleElement) {
// Get the product price for the current currency
$productPrice = ProductPriceQuery::create()
->filterByCurrency($this->getCurrentEditionCurrency())
->filterByCurrency($currentCurrency)
->filterByProductSaleElements($saleElement)
->findOne()
;
if ($productPrice == null) $productPrice = new ProductPrice();
// No one exists ?
if ($productPrice === null) {
$productPrice = new ProductPrice();
// If the current currency is not the default one, calculate the price
// using default currency price and current currency rate
if ($currentCurrency->getId() != $defaultCurrency->getId()) {
$productPrice->setFromDefaultCurrency(true);
$this->updatePriceFromDefaultCurrency($productPrice, $saleElement, $defaultCurrency, $currentCurrency);
}
}
// Caclulate prices if we have to use the rate * defaulkt currency price
if ($productPrice->getFromDefaultCurrency() == true) {
$this->updatePriceFromDefaultCurrency($productPrice, $saleElement, $defaultCurrency, $currentCurrency);
}
$isDefaultPse = count($saleElement->getAttributeCombinations()) == 0;
// If this PSE has no combination -> this is the default one
// affect it to the thelia.admin.product_sale_element.update form
if ($isDefaultPse) {
$defaultPseData = array(
"product_id" => $object->getId(),
"product_sale_element_id" => $saleElement->getId(),
"reference" => $saleElement->getRef(),
"price" => $productPrice->getPrice(),
"price_with_tax" => $this->computePrice($productPrice->getPrice(), 'without_tax', $object),
"use_exchange_rate" => $productPrice->getFromDefaultCurrency() ? 1 : 0,
"tax_rule" => $object->getTaxRuleId(),
"currency" => $productPrice->getCurrencyId(),
"weight" => $saleElement->getWeight(),
"quantity" => $saleElement->getQuantity(),
"sale_price" => $productPrice->getPromoPrice(),
"sale_price_with_tax" => $this->computePrice($productPrice->getPromoPrice(), 'without_tax', $object),
"onsale" => $saleElement->getPromo() > 0 ? 1 : 0,
"isnew" => $saleElement->getNewness() > 0 ? 1 : 0,
"isdefault" => $saleElement->getIsDefault() > 0 ? 1 : 0,
"ean_code" => $saleElement->getEanCode()
);
} else {
}
else {
if ($saleElement->getIsDefault()) {
$combinationPseData['default_pse'] = $saleElement->getId();
$combinationPseData['currency'] = $currentCurrency->getId();
$combinationPseData['use_exchange_rate'] = $productPrice->getFromDefaultCurrency() ? 1 : 0;
}
$this->appendValue($combinationPseData, "product_sale_element_id" , $saleElement->getId());
$this->appendValue($combinationPseData, "reference" , $saleElement->getRef());
$this->appendValue($combinationPseData, "price" , $productPrice->getPrice());
$this->appendValue($combinationPseData, "price_with_tax" , $this->computePrice($productPrice->getPrice(), 'without_tax', $object));
$this->appendValue($combinationPseData, "weight" , $saleElement->getWeight());
$this->appendValue($combinationPseData, "quantity" , $saleElement->getQuantity());
$this->appendValue($combinationPseData, "sale_price" , $productPrice->getPromoPrice());
$this->appendValue($combinationPseData, "sale_price_with_tax" , $this->computePrice($productPrice->getPromoPrice(), 'without_tax', $object));
$this->appendValue($combinationPseData, "onsale" , $saleElement->getPromo() > 0 ? 1 : 0);
$this->appendValue($combinationPseData, "isnew" , $saleElement->getNewness() > 0 ? 1 : 0);
$this->appendValue($combinationPseData, "isdefault" , $saleElement->getIsDefault() > 0 ? 1 : 0);
$this->appendValue($combinationPseData, "ean_code" , $saleElement->getEanCode());
}
$defaultPseForm = new ProductDefaultSaleElementUpdateForm($this->getRequest(), "form", $defaultPseData);
@@ -242,7 +304,7 @@ class ProductController extends AbstractCrudController
$this->getParserContext()->addForm($combinationPseForm);
}
// Prepare the data that will hydrate the form
// The "General" tab form
$data = array(
'id' => $object->getId(),
'ref' => $object->getRef(),
@@ -254,8 +316,6 @@ class ProductController extends AbstractCrudController
'visible' => $object->getVisible(),
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
'default_category' => $object->getDefaultCategoryId()
// A terminer pour les prix
);
// Setup the object form
@@ -808,8 +868,7 @@ class ProductController extends AbstractCrudController
try {
$this->dispatch(TheliaEvents::PRODUCT_ADD_PRODUCT_SALE_ELEMENT, $event);
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
@@ -832,8 +891,7 @@ class ProductController extends AbstractCrudController
try {
$this->dispatch(TheliaEvents::PRODUCT_DELETE_PRODUCT_SALE_ELEMENT, $event);
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
@@ -841,13 +899,49 @@ class ProductController extends AbstractCrudController
$this->redirectToEditionTemplate();
}
/**
* Process a single PSE update, using form data array.
*
* @param array $data the form data
* @throws Exception is someting goes wrong.
*/
protected function processSingleProductSaleElementUpdate($data)
{
$event = new ProductSaleElementUpdateEvent(
$this->getExistingObject(),
$data['product_sale_element_id']
);
$event
->setReference($data['reference'])
->setPrice($data['price'])
->setCurrencyId($data['currency'])
->setWeight($data['weight'])
->setQuantity($data['quantity'])
->setSalePrice($data['sale_price'])
->setOnsale($data['onsale'])
->setIsnew($data['isnew'])
->setIsdefault($data['isdefault'])
->setEanCode($data['ean_code'])
->setTaxRuleId($data['tax_rule'])
->setFromDefaultCurrency($data['use_exchange_rate'])
;
$this->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $event);
// Log object modification
if (null !== $changedObject = $event->getProductSaleElement()) {
$this->adminLogAppend(sprintf("Product Sale Element (ID %s) for product reference %s modified", $changedObject->getId(), $event->getProduct()->getRef()));
}
}
/**
* Change a product sale element
*/
protected function processProductSaleElementUpdate($changeForm) {
protected function processProductSaleElementUpdate($changeForm)
{
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
if (null !== $response = $this->checkAuth($this->resourceCode, AccessManager::UPDATE)) return $response;
$error_msg = false;
@@ -859,30 +953,34 @@ class ProductController extends AbstractCrudController
// Get the form field values
$data = $form->getData();
$event = new ProductSaleElementUpdateEvent(
$this->getExistingObject(),
$data['product_sale_element_id']
);
if (is_array($data['product_sale_element_id'])) {
$event
->setReference($data['reference'])
->setPrice($data['price'])
->setCurrencyId($data['currency'])
->setWeight($data['weight'])
->setQuantity($data['quantity'])
->setSalePrice($data['sale_price'])
->setOnsale($data['onsale'])
->setIsnew($data['isnew'])
->setIsdefault($data['isdefault'])
->setEanCode($data['ean_code'])
->setTaxrule($data['tax_rule'])
;
// Common fields
$tmp_data = array(
'tax_rule' => $data['tax_rule'],
'currency' => $data['currency'],
'use_exchange_rate' => $data['use_exchange_rate'],
);
$this->dispatch(TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT, $event);
$count = count($data['product_sale_element_id']);
// Log object modification
if (null !== $changedObject = $event->getProductSaleElement()) {
$this->adminLogAppend(sprintf("Product Sale Element (ID %s) for product reference %s modified", $changedObject->getId(), $event->getProduct()->getRef()));
for ($idx = 0; $idx < $count; $idx++) {
$tmp_data['product_sale_element_id'] = $pse_id = $data['product_sale_element_id'][$idx];
$tmp_data['reference'] = $data['reference'][$idx];
$tmp_data['price'] = $data['price'][$idx];
$tmp_data['weight'] = $data['weight'][$idx];
$tmp_data['quantity'] = $data['quantity'][$idx];
$tmp_data['sale_price'] = $data['sale_price'][$idx];
$tmp_data['onsale'] = isset($data['onsale'][$idx]) ? 1 : 0;
$tmp_data['isnew'] = isset($data['isnew'][$idx]) ? 1 : 0;
$tmp_data['isdefault'] = $data['default_pse'] == $pse_id;
$tmp_data['ean_code'] = $data['ean_code'][$idx];
$this->processSingleProductSaleElementUpdate($tmp_data);
}
} else {
// No need to preprocess data
$this->processSingleProductSaleElementUpdate($data);
}
// If we have to stay on the same page, do not redirect to the succesUrl, just redirect to the edit page again.
@@ -892,12 +990,10 @@ class ProductController extends AbstractCrudController
// Redirect to the success URL
$this->redirect($changeForm->getSuccessUrl());
}
catch (FormValidationException $ex) {
} catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
}
catch (\Exception $ex) {
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
@@ -910,9 +1006,10 @@ class ProductController extends AbstractCrudController
}
/**
* Change a product sale element attached to a combination
* Process the change of product's PSE list.
*/
public function updateProductSaleElementAction() {
public function updateProductSaleElementsAction()
{
return $this->processProductSaleElementUpdate(
new ProductSaleElementUpdateForm($this->getRequest())
);
@@ -921,44 +1018,120 @@ class ProductController extends AbstractCrudController
/**
* Update default product sale element (not attached to any combination)
*/
public function updateProductDefaultSaleElementAction() {
public function updateProductDefaultSaleElementAction()
{
return $this->processProductSaleElementUpdate(
new ProductDefaultSaleElementUpdateForm($this->getRequest())
);
}
public function priceCaclulator() {
/**
* Invoked through Ajax; this method calculates the taxed price from the unaxed price, and
* vice versa.
*/
public function priceCaclulator()
{
$return_price = 0;
$price = floatval($this->getRequest()->get('price', 0));
$tax_rule = intval($this->getRequest()->get('tax_rule_id', 0)); // The tax rule ID
$action = $this->getRequest()->get('action', ''); // With ot without tax
$convert = intval($this->getRequest()->get('convert_from_default_currency', 0));
$price = floatval($this->getRequest()->get('price', 0));
$product_id = intval($this->getRequest()->get('product_id', 0));
$action = $this->getRequest()->get('action', ''); // With ot without tax
$convert = intval($this->getRequest()->get('convert_from_default_currency', 0));
if (null !== $product = ProductQuery::create()->findPk($product_id)) {
if ($action == 'to_tax') {
$return_price = $this->computePrice($price, 'without_tax', $product);
} elseif ($action == 'from_tax') {
$return_price = $this->computePrice($price, 'with_tax', $product);
} else {
$return_price = $price;
}
if ($convert != 0) {
$return_price = $prix * Currency::getDefaultCurrency()->getRate();
}
}
return new JsonResponse(array('result' => $return_price));
}
/**
* Calculate all prices
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function loadConvertedPrices()
{
$product_sale_element_id = intval($this->getRequest()->get('product_sale_element_id', 0));
$currency_id = intval($this->getRequest()->get('currency_id', 0));
$price_with_tax = $price_without_tax = $sale_price_with_tax = $sale_price_without_tax = 0;
if (null !== $pse = ProductSaleElementsQuery::create()->findPk($product_sale_element_id)) {
if ($currency_id > 0
&&
$currency_id != Currency::getDefaultCurrency()->getId()
&&
null !== $currency = CurrencyQuery::create()->findPk($currency_id)) {
// Get the default currency price
$productPrice = ProductPriceQuery::create()
->filterByCurrency(Currency::getDefaultCurrency())
->filterByProductSaleElementsId($product_sale_element_id)
->findOne()
;
// Calculate the converted price
if (null !== $productPrice) {
$price_without_tax = $productPrice->getPrice() * $currency->getRate();
$sale_price_without_tax = $productPrice->getPromoPrice() * $currency->getRate();
}
}
if (null !== $product = $pse->getProduct()) {
$price_with_tax = $this->computePrice($price_without_tax, 'with_tax', $product);
$sale_price_with_tax = $this->computePrice($sale_price_without_tax, 'with_tax', $product);
}
}
return new JsonResponse(array(
'price_with_tax' => NumberFormat::getInstance($this->getRequest())->format($price_with_tax, null, '.'),
'price_without_tax' => NumberFormat::getInstance($this->getRequest())->format($price_without_tax, null, '.'),
'sale_price_with_tax' => NumberFormat::getInstance($this->getRequest())->format($sale_price_with_tax, null, '.'),
'sale_price_without_tax' => NumberFormat::getInstance($this->getRequest())->format($sale_price_without_tax, null, '.')
));
}
/**
* Calculate taxed/untexted price for a product
*
* @param unknown $price
* @param unknown $price_type
* @param Product $product
* @return Ambigous <unknown, number>
*/
protected function computePrice($price, $price_type, Product $product, $convert = false)
{
$calc = new Calculator();
$calc->loadTaxRule(
TaxRuleQuery::create()->findPk($tax_rule),
$calc->load(
$product,
Country::getShopLocation()
);
if ($action == 'to_tax') {
if ($price_type == 'without_tax') {
$return_price = $calc->getTaxedPrice($price);
}
else if ($action == 'from_tax') {
} elseif ($price_type == 'with_tax') {
$return_price = $calc->getUntaxedPrice($price);
}
else {
} else {
$return_price = $price;
}
if ($convert != 0) {
$return_price = $prix * Currency::getDefaultCurrency()->getRate();
}
// Format the number using '.', to perform further calculation
$return_price = NumberFormat::getInstance($this->getRequest())->format($return_price, null, '.');
return new JsonResponse(array('result' => $return_price));
return NumberFormat::getInstance($this->getRequest())->format($return_price, null, '.');
}
}

View File

@@ -29,7 +29,6 @@ use Thelia\Core\Event\Profile\ProfileEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\ProfileCreationForm;
use Thelia\Form\ProfileModificationForm;
use Thelia\Form\ProfileProfileListUpdateForm;
use Thelia\Form\ProfileUpdateModuleAccessForm;
use Thelia\Form\ProfileUpdateResourceAccessForm;
use Thelia\Model\ProfileQuery;
@@ -201,8 +200,8 @@ class ProfileController extends AbstractCrudController
/**
* Put in this method post object creation processing if required.
*
* @param ProfileEvent $createEvent the create event
* @return Response a response, or null to continue normal processing
* @param ProfileEvent $createEvent the create event
* @return Response a response, or null to continue normal processing
*/
protected function performAdditionalCreateAction($createEvent)
{
@@ -263,8 +262,8 @@ class ProfileController extends AbstractCrudController
protected function getResourceAccess($formData)
{
$requirements = array();
foreach($formData as $data => $value) {
if(!strstr($data, ':')) {
foreach ($formData as $data => $value) {
if (!strstr($data, ':')) {
continue;
}
@@ -272,7 +271,7 @@ class ProfileController extends AbstractCrudController
$prefix = array_shift ( $explosion );
if($prefix != ProfileUpdateResourceAccessForm::RESOURCE_ACCESS_FIELD_PREFIX) {
if ($prefix != ProfileUpdateResourceAccessForm::RESOURCE_ACCESS_FIELD_PREFIX) {
continue;
}
@@ -285,8 +284,8 @@ class ProfileController extends AbstractCrudController
protected function getModuleAccess($formData)
{
$requirements = array();
foreach($formData as $data => $value) {
if(!strstr($data, ':')) {
foreach ($formData as $data => $value) {
if (!strstr($data, ':')) {
continue;
}
@@ -294,7 +293,7 @@ class ProfileController extends AbstractCrudController
$prefix = array_shift ( $explosion );
if($prefix != ProfileUpdateModuleAccessForm::MODULE_ACCESS_FIELD_PREFIX) {
if ($prefix != ProfileUpdateModuleAccessForm::MODULE_ACCESS_FIELD_PREFIX) {
continue;
}
@@ -401,4 +400,4 @@ class ProfileController extends AbstractCrudController
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
}
}
}

View File

@@ -28,7 +28,6 @@ use Thelia\Core\Event\Tax\TaxEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\TaxCreationForm;
use Thelia\Form\TaxModificationForm;
use Thelia\Form\TaxTaxListUpdateForm;
use Thelia\Model\TaxQuery;
class TaxController extends AbstractCrudController
@@ -40,10 +39,7 @@ class TaxController extends AbstractCrudController
'manual',
'order',
AdminResources::TAX_VIEW,
AdminResources::TAX_CREATE,
AdminResources::TAX_UPDATE,
AdminResources::TAX_DELETE,
AdminResources::TAX,
TheliaEvents::TAX_CREATE,
TheliaEvents::TAX_UPDATE,
@@ -180,7 +176,7 @@ class TaxController extends AbstractCrudController
/**
* Put in this method post object creation processing if required.
*
* @param TaxEvent $createEvent the create event
* @param TaxEvent $createEvent the create event
* @return Response a response, or null to continue normal processing
*/
protected function performAdditionalCreateAction($createEvent)
@@ -203,20 +199,19 @@ class TaxController extends AbstractCrudController
{
$type = $formData['type'];
}
protected function getRequirements($type, $formData)
{
$requirements = array();
foreach($formData as $data => $value) {
if(!strstr($data, ':')) {
foreach ($formData as $data => $value) {
if (!strstr($data, ':')) {
continue;
}
$couple = explode(':', $data);
if(count($couple) != 2 || $couple[0] != $type) {
if (count($couple) != 2 || $couple[0] != $type) {
continue;
}
@@ -225,4 +220,4 @@ class TaxController extends AbstractCrudController
return $requirements;
}
}
}

View File

@@ -1,93 +0,0 @@
<?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\Controller\Admin;
use Thelia\Form\TestForm;
/**
* Manages variables
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
class TestController extends BaseAdminController
{
/**
* Load a object for modification, and display the edit template.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function updateAction()
{
// Prepare the data that will hydrate the form
$data = array(
'title' => "test title",
'test' => array('a', 'b', 'toto' => 'c')
);
// Setup the object form
$changeForm = new TestForm($this->getRequest(), "form", $data);
// Pass it to the parser
$this->getParserContext()->addForm($changeForm);
return $this->render('test-form');
}
/**
* Save changes on a modified object, and either go back to the object list, or stay on the edition page.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
public function processUpdateAction()
{
$error_msg = false;
// Create the form from the request
$changeForm = new TestForm($this->getRequest());
try {
// Check the form against constraints violations
$form = $this->validateForm($changeForm, "POST");
// Get the form field values
$data = $form->getData();
echo "data=";
var_dump($data);
}
catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
}
catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
echo "Error = $error_msg";
exit;
}
}

View File

@@ -57,7 +57,7 @@ class BaseController extends ContainerAware
/**
* Return an empty response (after an ajax request, for example)
* @param int $status
* @param int $status
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function nullResponse($status = 200)
@@ -196,15 +196,13 @@ class BaseController extends ContainerAware
$errorMessage = null;
if ($form->get("error_message")->getData() != null) {
$errorMessage = $form->get("error_message")->getData();
}
else {
} else {
$errorMessage = sprintf("Missing or invalid data: %s", $this->getErrorMessages($form));
}
throw new FormValidationException($errorMessage);
}
}
else {
} else {
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
}
}
@@ -229,8 +227,7 @@ class BaseController extends ContainerAware
{
if ($form != null) {
$url = $form->getSuccessUrl();
}
else {
} else {
$url = $this->getRequest()->get("success_url");
}

View File

@@ -67,7 +67,6 @@ class CartController extends BaseFrontController
$request->attributes->set('_view', "includes/mini-cart");
}
if ($message) {
$cartAdd->setErrorMessage($message);
$this->getParserContext()->addForm($cartAdd);

View File

@@ -26,7 +26,6 @@ use Thelia\Form\ContactForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Model\ConfigQuery;
/**
* Class ContactController
* @package Thelia\Controller\Front
@@ -53,7 +52,7 @@ class ContactController extends BaseFrontController
$this->getMailer()->send($message);
} catch(FormValidationException $e) {
} catch (FormValidationException $e) {
$error_message = $e->getMessage();
}
@@ -70,4 +69,4 @@ class ContactController extends BaseFrontController
$this->redirectToRoute('contact.success');
}
}
}
}

View File

@@ -24,21 +24,11 @@ namespace Thelia\Controller\Front;
use Propel\Runtime\Exception\PropelException;
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
use Thelia\Exception\TheliaProcessException;
use Thelia\Form\CouponCode;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Symfony\Component\HttpFoundation\Request;
use Thelia\Form\OrderDelivery;
use Thelia\Form\OrderPayment;
use Thelia\Log\Tlog;
use Thelia\Model\AddressQuery;
use Thelia\Model\AreaDeliveryModuleQuery;
use Thelia\Model\Base\OrderQuery;
use Thelia\Model\ModuleQuery;
use Thelia\Model\Order;
use Thelia\Tools\URL;
/**
* Class CouponController

View File

@@ -51,7 +51,6 @@ class CustomerController extends BaseFrontController
{
use \Thelia\Cart\CartTrait;
public function newPasswordAction()
{
if (! $this->getSecurityContext()->hasCustomerUser()) {
@@ -156,7 +155,6 @@ class CustomerController extends BaseFrontController
$this->getParserContext()->addForm($customerProfilUpdateForm);
}
public function updatePasswordAction()
{
if ($this->getSecurityContext()->hasCustomerUser()) {
@@ -220,14 +218,14 @@ class CustomerController extends BaseFrontController
$nlEvent->setFirstname($updatedCustomer->getFirstname());
$nlEvent->setLastname($updatedCustomer->getLastname());
if(null !== $newsletter = NewsletterQuery::create()->findOneByEmail($newsletterOldEmail)) {
if (null !== $newsletter = NewsletterQuery::create()->findOneByEmail($newsletterOldEmail)) {
$nlEvent->setId($newsletter->getId());
$this->dispatch(TheliaEvents::NEWSLETTER_UPDATE, $nlEvent);
} else {
$this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $nlEvent);
}
} else {
if(null !== $newsletter = NewsletterQuery::create()->findOneByEmail($newsletterOldEmail)) {
if (null !== $newsletter = NewsletterQuery::create()->findOneByEmail($newsletterOldEmail)) {
$nlEvent = new NewsletterEvent($updatedCustomer->getEmail(), $this->getRequest()->getSession()->getLang()->getLocale());
$nlEvent->setId($newsletter->getId());
$this->dispatch(TheliaEvents::NEWSLETTER_UNSUBSCRIBE, $nlEvent);

View File

@@ -23,7 +23,6 @@
namespace Thelia\Controller\Front;
/**
* Class Mail
* @package Thelia\Controller\Front
@@ -46,4 +45,4 @@ class Mail extends BaseFrontController
exit;
}
}
}

View File

@@ -27,7 +27,6 @@ use Thelia\Core\Event\Newsletter\NewsletterEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Form\NewsletterForm;
/**
* Class NewsletterController
* @package Thelia\Controller\Front
@@ -50,15 +49,14 @@ class NewsletterController extends BaseFrontController
$this->getRequest()->getSession()->getLang()->getLocale()
);
if (null !== $customer = $this->getSecurityContext()->getCustomerUser())
{
if (null !== $customer = $this->getSecurityContext()->getCustomerUser()) {
$event->setFirstname($customer->getFirstname());
$event->setLastname($customer->getLastname());
}
$this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $event);
} catch(\Exception $e) {
} catch (\Exception $e) {
$error_message = $e->getMessage();
}
@@ -90,4 +88,4 @@ class NewsletterController extends BaseFrontController
}
}
}
}

View File

@@ -23,7 +23,6 @@
namespace Thelia\Core\Event\Lang;
/**
* Class LangCreateEvent
* @package Thelia\Core\Event\Lang
@@ -137,5 +136,4 @@ class LangCreateEvent extends LangEvent
return $this->title;
}
}
}

View File

@@ -24,7 +24,6 @@
namespace Thelia\Core\Event\Lang;
use Thelia\Core\Event\ActionEvent;
/**
* Class LangDefaultBehaviorEvent
* @package Thelia\Core\Event\Lang
@@ -37,7 +36,7 @@ class LangDefaultBehaviorEvent extends ActionEvent
*/
protected $defaultBehavior;
function __construct($defaultBehavior)
public function __construct($defaultBehavior)
{
$this->defaultBehavior = $defaultBehavior;
}
@@ -58,7 +57,4 @@ class LangDefaultBehaviorEvent extends ActionEvent
return $this->defaultBehavior;
}
}
}

View File

@@ -23,7 +23,6 @@
namespace Thelia\Core\Event\Lang;
/**
* Class LangDeleteEvent
* @package Thelia\Core\Event\Lang
@@ -39,7 +38,7 @@ class LangDeleteEvent extends LangEvent
/**
* @param int $lang_id
*/
function __construct($lang_id)
public function __construct($lang_id)
{
$this->lang_id = $lang_id;
}
@@ -64,4 +63,4 @@ class LangDeleteEvent extends LangEvent
return $this->lang_id;
}
}
}

View File

@@ -25,7 +25,6 @@ namespace Thelia\Core\Event\Lang;
use Thelia\Core\Event\ActionEvent;
use Thelia\Model\Lang;
/**
* Class LangEvent
* @package Thelia\Core\Event\Lang
@@ -38,7 +37,7 @@ class LangEvent extends ActionEvent
*/
protected $lang;
function __construct(Lang $lang = null)
public function __construct(Lang $lang = null)
{
$this->lang = $lang;
}
@@ -70,7 +69,4 @@ class LangEvent extends ActionEvent
return null !== $this->lang;
}
}
}

View File

@@ -23,7 +23,6 @@
namespace Thelia\Core\Event\Lang;
/**
* Class LangToggleDefaultEvent
* @package Thelia\Core\Event\Lang
@@ -39,7 +38,7 @@ class LangToggleDefaultEvent extends LangEvent
/**
* @param int $lang_id
*/
function __construct($lang_id)
public function __construct($lang_id)
{
$this->lang_id = $lang_id;
}
@@ -64,6 +63,4 @@ class LangToggleDefaultEvent extends LangEvent
return $this->lang_id;
}
}
}

View File

@@ -23,7 +23,6 @@
namespace Thelia\Core\Event\Lang;
/**
* Class LangUpdateEvent
* @package Thelia\Core\Event\Lang
@@ -39,12 +38,11 @@ class LangUpdateEvent extends LangCreateEvent
/**
* @param int $id
*/
function __construct($id)
public function __construct($id)
{
$this->id = $id;
}
/**
* @param int $id
*
@@ -65,5 +63,4 @@ class LangUpdateEvent extends LangCreateEvent
return $this->id;
}
}
}

View File

@@ -23,7 +23,6 @@
namespace Thelia\Core\Event\Module;
/**
* Class ModuleDeleteEvent
* @package Thelia\Core\Event\Module
@@ -36,7 +35,7 @@ class ModuleDeleteEvent extends ModuleEvent
*/
protected $module_id;
function __construct($module_id)
public function __construct($module_id)
{
$this->module_id = $module_id;
}
@@ -57,5 +56,4 @@ class ModuleDeleteEvent extends ModuleEvent
return $this->module_id;
}
}
}

View File

@@ -24,7 +24,6 @@
namespace Thelia\Core\Event\Newsletter;
use Thelia\Core\Event\ActionEvent;
/**
* Class NewsletterEvent
* @package Thelia\Core\Event\Newsletter
@@ -57,7 +56,7 @@ class NewsletterEvent extends ActionEvent
*/
protected $locale;
function __construct($email, $locale)
public function __construct($email, $locale)
{
$this->email = $email;
$this->locale = $locale;
@@ -159,8 +158,4 @@ class NewsletterEvent extends ActionEvent
return $this->id;
}
}
}

View File

@@ -24,7 +24,6 @@
namespace Thelia\Core\Event\ProductSaleElement;
use Thelia\Model\Product;
use Thelia\Core\Event\Product\ProductEvent;
class ProductSaleElementCreateEvent extends ProductSaleElementEvent
{
@@ -65,15 +64,16 @@ class ProductSaleElementCreateEvent extends ProductSaleElementEvent
return $this;
}
public function getProduct() {
public function getProduct()
{
return $this->product;
}
public function setProduct($product) {
public function setProduct($product)
{
$this->product = $product;
return $this;
}
}

View File

@@ -23,7 +23,6 @@
namespace Thelia\Core\Event\ProductSaleElement;
use Thelia\Model\Product;
use Thelia\Core\Event\Product\ProductEvent;
class ProductSaleElementDeleteEvent extends ProductSaleElementEvent
{
@@ -58,6 +57,7 @@ class ProductSaleElementDeleteEvent extends ProductSaleElementEvent
public function setCurrencyId($currency_id)
{
$this->currency_id = $currency_id;
return $this;
}

View File

@@ -22,9 +22,7 @@
/*************************************************************************************/
namespace Thelia\Core\Event\ProductSaleElement;
use Thelia\Core\Event\Product\ProductCreateEvent;
use Thelia\Model\Product;
use Thelia\Core\Event\Product\ProductEvent;
class ProductSaleElementUpdateEvent extends ProductSaleElementEvent
{
@@ -41,7 +39,8 @@ class ProductSaleElementUpdateEvent extends ProductSaleElementEvent
protected $isnew;
protected $isdefault;
protected $ean_code;
protected $taxrule;
protected $tax_rule_id;
protected $from_default_currency;
public function __construct(Product $product, $product_sale_element_id)
{
@@ -196,14 +195,26 @@ class ProductSaleElementUpdateEvent extends ProductSaleElementEvent
return $this;
}
public function getTaxrule()
public function getTaxRuleId()
{
return $this->taxrule;
return $this->tax_rule_id;
}
public function setTaxrule($taxrule)
public function setTaxRuleId($tax_rule_id)
{
$this->taxrule = $taxrule;
$this->tax_rule_id = $tax_rule_id;
return $this;
}
public function getFromDefaultCurrency()
{
return $this->from_default_currency;
}
public function setFromDefaultCurrency($from_default_currency)
{
$this->from_default_currency = $from_default_currency;
return $this;
}

View File

@@ -552,7 +552,6 @@ final class TheliaEvents
const TAX_UPDATE = "action.updateTax";
const TAX_DELETE = "action.deleteTax";
// -- Profile management ---------------------------------------------
const PROFILE_CREATE = "action.createProfile";

View File

@@ -84,13 +84,13 @@ class ViewListener implements EventSubscriberInterface
$response = new Response($content, $parser->getStatus() ?: 200);
}
$response->setCache(array(
/* $response->setCache(array(
'last_modified' => new \DateTime(),
'max_age' => 600,
's_maxage' => 600,
'private' => false,
'public' => true,
));
));*/
$event->setResponse($response);
} catch (ResourceNotFoundException $e) {

View File

@@ -46,4 +46,4 @@ class TheliaType extends AbstractType
{
return 'thelia_type';
}
}
}

View File

@@ -23,13 +23,6 @@
namespace Thelia\Core\Security;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Security\User\UserInterface;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Model\ProfileQuery;
use Thelia\Model\ProfileResourceQuery;
/**
* A simple security manager, in charge of checking user
*
@@ -49,7 +42,7 @@ class AccessManager
self::DELETE => false,
);
static protected $accessPows = array(
protected static $accessPows = array(
self::VIEW => 3,
self::CREATE => 2,
self::UPDATE => 1,
@@ -67,7 +60,7 @@ class AccessManager
public function can($type)
{
if(!array_key_exists($type, $this->accessGranted)) {
if (!array_key_exists($type, $this->accessGranted)) {
return false;
}
@@ -75,7 +68,7 @@ class AccessManager
}
static public function getMaxAccessValue()
public static function getMaxAccessValue()
{
return pow(2, current(array_slice( self::$accessPows, -1, 1, true ))) - 1;
}
@@ -83,8 +76,8 @@ class AccessManager
public function build($accesses)
{
$this->accessValue = 0;
foreach($accesses as $access) {
if(array_key_exists($access, self::$accessPows)) {
foreach ($accesses as $access) {
if (array_key_exists($access, self::$accessPows)) {
$this->accessValue += pow(2, self::$accessPows[$access]);
}
}
@@ -95,9 +88,9 @@ class AccessManager
protected function fillGrantedAccess()
{
$accessValue = $this->accessValue;
foreach(self::$accessPows as $type => $value) {
foreach (self::$accessPows as $type => $value) {
$pow = pow(2, $value);
if($accessValue >= $pow) {
if ($accessValue >= $pow) {
$accessValue -= $pow;
$this->accessGranted[$type] = true;
} else {
@@ -106,7 +99,6 @@ class AccessManager
}
}
public function getAccessValue()
{
return $this->accessValue;

View File

@@ -23,7 +23,7 @@
namespace Thelia\Core\Security\Exception;
class ResourceException extends \RuntimeException
class RessourceException extends \RuntimeException
{
const UNKNOWN_EXCEPTION = 0;

View File

@@ -33,17 +33,17 @@ use Thelia\Core\Security\Exception\ResourceException;
*/
final class AdminResources
{
static private $selfReflection = null;
private static $selfReflection = null;
static public function retrieve($name)
public static function retrieve($name)
{
$constantName = strtoupper($name);
if(null === self::$selfReflection) {
if (null === self::$selfReflection) {
self::$selfReflection = new \ReflectionClass(__CLASS__);
}
if(self::$selfReflection->hasConstant($constantName)) {
if (self::$selfReflection->hasConstant($constantName)) {
return self::$selfReflection->getConstant($constantName);
} else {
throw new ResourceException(sprintf('Resource `%s` not found', $constantName), ResourceException::RESOURCE_NOT_FOUND);

View File

@@ -23,12 +23,9 @@
namespace Thelia\Core\Security;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Security\User\UserInterface;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Model\ProfileQuery;
use Thelia\Model\ProfileResourceQuery;
/**
* A simple security manager, in charge of checking user
@@ -147,29 +144,29 @@ class SecurityContext
return true;
}
if( !method_exists($user, 'getPermissions') ) {
if ( !method_exists($user, 'getPermissions') ) {
return false;
}
$userPermissions = $user->getPermissions();
if($userPermissions === AdminResources::SUPERADMINISTRATOR) {
if ($userPermissions === AdminResources::SUPERADMINISTRATOR) {
return true;
}
foreach($resources as $resource) {
if($resource === '') {
foreach ($resources as $resource) {
if ($resource === '') {
continue;
}
$resource = strtolower($resource);
if(!array_key_exists($resource, $userPermissions)) {
if (!array_key_exists($resource, $userPermissions)) {
return false;
}
foreach($accesses as $access) {
if(!$userPermissions[$resource]->can($access)) {
foreach ($accesses as $access) {
if (!$userPermissions[$resource]->can($access)) {
return false;
}
}

View File

@@ -23,12 +23,17 @@
namespace Thelia\Core\Template\Element;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Thelia\Core\Security\SecurityContext;
use Thelia\Type\AlphaNumStringListType;
use Thelia\Type\EnumListType;
use Thelia\Type\EnumType;
use Thelia\Type\TypeCollection;
/**
*
@@ -84,13 +89,43 @@ abstract class BaseLoop
*/
protected function getDefaultArgs()
{
return array(
Argument::createIntTypeArgument('offset', 0),
Argument::createIntTypeArgument('page'),
Argument::createIntTypeArgument('limit', PHP_INT_MAX),
$defaultArgs = array(
Argument::createBooleanTypeArgument('backend_context', false),
Argument::createBooleanTypeArgument('force_return', false),
);
if (true === $this->countable) {
$defaultArgs = array_merge($defaultArgs, array(
Argument::createIntTypeArgument('offset', 0),
Argument::createIntTypeArgument('page'),
Argument::createIntTypeArgument('limit', PHP_INT_MAX),
));
}
if ($this instanceof SearchLoopInterface) {
$defaultArgs = array_merge($defaultArgs, array(
Argument::createAnyTypeArgument('search_term'),
new Argument(
'search_in',
new TypeCollection(
new EnumListType($this->getSearchIn())
)
),
new Argument(
'search_mode',
new TypeCollection(
new EnumType(array(
SearchLoopInterface::MODE_ANY_WORD,
SearchLoopInterface::MODE_SENTENCE,
SearchLoopInterface::MODE_STRICT_SENTENCE,
))
),
SearchLoopInterface::MODE_STRICT_SENTENCE
)
));
}
return $defaultArgs;
}
/**
@@ -205,6 +240,30 @@ abstract class BaseLoop
*/
protected function search(ModelCriteria $search, &$pagination = null)
{
if ($this instanceof SearchLoopInterface) {
$searchTerm = $this->getSearch_term();
$searchIn = $this->getSearch_in();
$searchMode = $this->getSearch_mode();
if (null !== $searchTerm && null !== $searchIn) {
switch ($searchMode) {
case SearchLoopInterface::MODE_ANY_WORD:
$searchCriteria = Criteria::IN;
$searchTerm = explode(' ', $searchTerm);
break;
case SearchLoopInterface::MODE_SENTENCE:
$searchCriteria = Criteria::LIKE;
$searchTerm = '%' . $searchTerm . '%';
break;
case SearchLoopInterface::MODE_STRICT_SENTENCE:
$searchCriteria = Criteria::EQUAL;
break;
}
$this->doSearch($search, $searchTerm, $searchIn, $searchCriteria);
}
}
if ($this->getArgValue('page') !== null) {
return $this->searchWithPagination($search, $pagination);
} else {

View File

@@ -1,47 +1,40 @@
<?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/>. */
/* */
/**********************************************************************************/
/*************************************************************************************/
/* */
/* 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;
namespace Thelia\Core\Template\Element\Exception;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test BaseFacade Class
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase
class SearchLoopException extends \RuntimeException
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
const UNKNOWN_EXCEPTION = 0;
public function __construct($message, $code = null, $arguments = array(), $previous = null)
{
if (is_array($arguments)) {
$this->arguments = $arguments;
}
if ($code === null) {
$code = self::UNKNOWN_EXCEPTION;
}
parent::__construct($message, $code, $previous);
}
}

View File

@@ -1,48 +1,42 @@
<?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;
/*************************************************************************************/
/* */
/* 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\Template\Element;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test CouponManager Class
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class CouponManagerTest extends \PHPUnit_Framework_TestCase
interface SearchLoopInterface
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
const MODE_ANY_WORD = 'any_word';
const MODE_SENTENCE = 'sentence';
const MODE_STRICT_SENTENCE = 'strict_sentence';
/**
* @return array of available field to search in
*/
public function getSearchIn();
public function doSearch(&$search, $searchTerm, $searchIn, $searchCriteria);
}

View File

@@ -24,7 +24,6 @@
namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
@@ -34,7 +33,6 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\AdminQuery;
use Thelia\Type;
use Thelia\Type\BooleanOrBothType;
/**
*

View File

@@ -16,7 +16,6 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\CountryQuery;
use Thelia\Type;
use Thelia\Type\TypeCollection;
class Cart extends BaseLoop
{
@@ -90,17 +89,17 @@ class Cart extends BaseLoop
$countCartItems = count($cartItems);
if($limit <= 0 || $limit >= $countCartItems){
if ($limit <= 0 || $limit >= $countCartItems) {
$limit = $countCartItems;
}
$position = $this->getPosition();
if(isset($position)){
if($position == "first"){
if (isset($position)) {
if ($position == "first") {
$limit = 1;
$cartItems = array($cartItems[0]);
}else if($position == "last"){
} elseif ($position == "last") {
$limit = 1;
$cartItems = array(end($cartItems));
}

View File

@@ -128,8 +128,9 @@ class Category extends BaseI18nLoop
$search->filterById($exclude, Criteria::NOT_IN);
}
if ($this->getVisible() != BooleanOrBothType::ANY)
$search->filterByVisible($this->getVisible() ? 1 : 0);
$visible = $this->getVisible();
if ($visible !== BooleanOrBothType::ANY) $search->filterByVisible($visible ? 1 : 0);
$product = $this->getProduct();

View File

@@ -33,7 +33,6 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\FolderQuery;
use Thelia\Model\Map\ContentTableMap;
use Thelia\Model\ContentFolderQuery;
use Thelia\Model\ContentQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
@@ -152,7 +151,8 @@ class Content extends BaseI18nLoop
$visible = $this->getVisible();
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible);
if ($visible !== BooleanOrBothType::ANY) $search->filterByVisible($visible ? 1 : 0);
$orders = $this->getOrder();

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\SearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
@@ -44,7 +45,7 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class Customer extends BaseLoop
class Customer extends BaseLoop implements SearchLoopInterface
{
public $timestampable = true;
@@ -67,6 +68,47 @@ class Customer extends BaseLoop
);
}
public function getSearchIn()
{
return array(
"ref",
"firstname",
"lastname",
"email",
);
}
/**
* @param CustomerQuery $search
* @param $searchTerm
* @param $searchIn
* @param $searchCriteria
*/
public function doSearch(&$search, $searchTerm, $searchIn, $searchCriteria)
{
$search->_and();
foreach ($searchIn as $index => $searchInElement) {
if ($index > 0) {
$search->_or();
}
switch ($searchInElement) {
case "ref":
$search->filterByRef($searchTerm, $searchCriteria);
break;
case "firstname":
$search->filterByFirstname($searchTerm, $searchCriteria);
break;
case "lastname":
$search->filterByLastname($searchTerm, $searchCriteria);
break;
case "email":
$search->filterByEmail($searchTerm, $searchCriteria);
break;
}
}
}
/**
* @param $pagination
*

View File

@@ -121,7 +121,8 @@ class Folder extends BaseI18nLoop
$visible = $this->getVisible();
if ($visible != BooleanOrBothType::ANY) $search->filterByVisible($visible ? 1 : 0);
if ($visible !== BooleanOrBothType::ANY) $search->filterByVisible($visible ? 1 : 0);
$orders = $this->getOrder();

View File

@@ -107,7 +107,7 @@ class Module extends BaseI18nLoop
$code = $this->getCode();
if(null !== $code) {
if (null !== $code) {
$search->filterByCode($code, Criteria::IN);
}

View File

@@ -28,8 +28,11 @@ use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\SearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\CustomerQuery;
use Thelia\Model\OrderAddressQuery;
use Thelia\Model\OrderQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
@@ -38,8 +41,9 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop
*
* @author Franck Allimant <franck@cqfdev.fr>
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class Order extends BaseLoop
class Order extends BaseLoop implements SearchLoopInterface
{
public $countable = true;
public $timestampable = true;
@@ -74,6 +78,59 @@ class Order extends BaseLoop
);
}
public function getSearchIn()
{
return array(
"ref",
"customer_ref",
"customer_firstname",
"customer_lastname",
"customer_email",
);
}
/**
* @param OrderQuery $search
* @param $searchTerm
* @param $searchIn
* @param $searchCriteria
*/
public function doSearch(&$search, $searchTerm, $searchIn, $searchCriteria)
{
$search->_and();
foreach ($searchIn as $index => $searchInElement) {
if ($index > 0) {
$search->_or();
}
switch ($searchInElement) {
case "ref":
$search->filterByRef($searchTerm, $searchCriteria);
break;
case "customer_ref":
$search->filterByCustomer(
CustomerQuery::create()->filterByRef($searchTerm, $searchCriteria)->find()
);
break;
case "customer_firstname":
$search->filterByOrderAddressRelatedByInvoiceOrderAddressId(
OrderAddressQuery::create()->filterByFirstname($searchTerm, $searchCriteria)->find()
);
break;
case "customer_lastname":
$search->filterByOrderAddressRelatedByInvoiceOrderAddressId(
OrderAddressQuery::create()->filterByLastname($searchTerm, $searchCriteria)->find()
);
break;
case "customer_email":
$search->filterByCustomer(
CustomerQuery::create()->filterByEmail($searchTerm, $searchCriteria)->find()
);
break;
}
}
}
/**
* @param $pagination
*

View File

@@ -29,6 +29,7 @@ use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\SearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
@@ -39,23 +40,19 @@ use Thelia\Model\CurrencyQuery;
use Thelia\Model\Map\ProductPriceTableMap;
use Thelia\Model\Map\ProductSaleElementsTableMap;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\ProductCategoryQuery;
use Thelia\Model\ProductQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Type\TypeCollection;
use Thelia\Type;
use Thelia\Type\BooleanOrBothType;
/**
*
* Product loop
*
*
* Class Product
* @package Thelia\Core\Template\Loop
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class Product extends BaseI18nLoop
class Product extends BaseI18nLoop implements SearchLoopInterface
{
public $timestampable = true;
public $versionable = true;
@@ -66,6 +63,7 @@ class Product extends BaseI18nLoop
protected function getArgDefinitions()
{
return new ArgumentCollection(
Argument::createBooleanTypeArgument('complex', false),
Argument::createIntListTypeArgument('id'),
new Argument(
'ref',
@@ -130,6 +128,39 @@ class Product extends BaseI18nLoop
);
}
public function getSearchIn()
{
return array(
"ref",
"title",
);
}
/**
* @param ProductQuery $search
* @param $searchTerm
* @param $searchIn
* @param $searchCriteria
*/
public function doSearch(&$search, $searchTerm, $searchIn, $searchCriteria)
{
$search->_and();
foreach ($searchIn as $index => $searchInElement) {
if ($index > 0) {
$search->_or();
}
switch ($searchInElement) {
case "ref":
$search->filterByRef($searchTerm, $searchCriteria);
break;
case "title":
$search->where("CASE WHEN NOT ISNULL(`requested_locale_i18n`.ID) THEN `requested_locale_i18n`.`TITLE` ELSE `default_locale_i18n`.`TITLE` END ".$searchCriteria." ?", $searchTerm, \PDO::PARAM_STR);
break;
}
}
}
/**
* @param $pagination
*
@@ -137,6 +168,396 @@ class Product extends BaseI18nLoop
* @throws \InvalidArgumentException
*/
public function exec(&$pagination)
{
$complex = $this->getComplex();
if (true === $complex) {
return $this->execComplex($pagination);
}
$currencyId = $this->getCurrency();
if (null !== $currencyId) {
$currency = CurrencyQuery::create()->findOneById($currencyId);
if (null === $currency) {
throw new \InvalidArgumentException('Cannot found currency id: `' . $currency . '` in product_sale_elements loop');
}
} else {
$currency = $this->request->getSession()->getCurrency();
}
$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
$defaultCurrencySuffix = '_default_currency';
$search = ProductQuery::create();
$search->innerJoinProductSaleElements('pse');
$search->addJoinCondition('pse', '`pse`.IS_DEFAULT=1');
$priceJoin = new Join();
$priceJoin->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'pse', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'price');
$priceJoin->setJoinType(Criteria::LEFT_JOIN);
$search->addJoinObject($priceJoin, 'price_join')
->addJoinCondition('price_join', '`price`.`currency_id` = ?', $currency->getId(), null, \PDO::PARAM_INT);
if ($defaultCurrency->getId() != $currency->getId()) {
$priceJoinDefaultCurrency = new Join();
$priceJoinDefaultCurrency->addExplicitCondition(ProductSaleElementsTableMap::TABLE_NAME, 'ID', 'pse', ProductPriceTableMap::TABLE_NAME, 'PRODUCT_SALE_ELEMENTS_ID', 'price' . $defaultCurrencySuffix);
$priceJoinDefaultCurrency->setJoinType(Criteria::LEFT_JOIN);
$search->addJoinObject($priceJoinDefaultCurrency, 'price_join' . $defaultCurrencySuffix)
->addJoinCondition('price_join' . $defaultCurrencySuffix, '`price' . $defaultCurrencySuffix . '`.`currency_id` = ?', $defaultCurrency->getId(), null, \PDO::PARAM_INT);
/**
* rate value is checked as a float in overloaded getRate method.
*/
$priceToCompareAsSQL = 'CASE WHEN ISNULL(`price`.PRICE) OR `price`.FROM_DEFAULT_CURRENCY = 1 THEN
CASE WHEN `pse`.PROMO=1 THEN `price' . $defaultCurrencySuffix . '`.PROMO_PRICE ELSE `price' . $defaultCurrencySuffix . '`.PRICE END * ' . $currency->getRate() . '
ELSE
CASE WHEN `pse`.PROMO=1 THEN `price`.PROMO_PRICE ELSE `price`.PRICE END
END';
$search->withColumn('ROUND(' . $priceToCompareAsSQL . ', 2)', 'real_price');
$search->withColumn('CASE WHEN ISNULL(`price`.PRICE) OR `price`.FROM_DEFAULT_CURRENCY = 1 THEN `price' . $defaultCurrencySuffix . '`.PRICE * ' . $currency->getRate() . ' ELSE `price`.PRICE END', 'price');
$search->withColumn('CASE WHEN ISNULL(`price`.PRICE) OR `price`.FROM_DEFAULT_CURRENCY = 1 THEN `price' . $defaultCurrencySuffix . '`.PROMO_PRICE * ' . $currency->getRate() . ' ELSE `price`.PROMO_PRICE END', 'promo_price');
} else {
$priceToCompareAsSQL = 'CASE WHEN `pse`.PROMO=1 THEN `price`.PROMO_PRICE ELSE `price`.PRICE END';
$search->withColumn('ROUND(' . $priceToCompareAsSQL . ', 2)', 'real_price');
$search->withColumn('`price`.PRICE', 'price');
$search->withColumn('`price`.PROMO_PRICE', 'promo_price');
}
/* manage translations */
$locale = $this->configureI18nProcessing($search);
$id = $this->getId();
if (!is_null($id)) {
$search->filterById($id, Criteria::IN);
}
$ref = $this->getRef();
if (!is_null($ref)) {
$search->filterByRef($ref, Criteria::IN);
}
$title = $this->getTitle();
if (!is_null($title)) {
$search->where("CASE WHEN NOT ISNULL(`requested_locale_i18n`.ID) THEN `requested_locale_i18n`.`TITLE` ELSE `default_locale_i18n`.`TITLE` END ".Criteria::LIKE." ?", "%".$title."%", \PDO::PARAM_STR);
}
$category = $this->getCategory();
$categoryDefault = $this->getCategoryDefault();
if (!is_null($category) ||!is_null($categoryDefault)) {
$categoryIds = array();
if (!is_array($category)) {
$category = array();
}
if (!is_array($categoryDefault)) {
$categoryDefault = array();
}
$categoryIds = array_merge($categoryIds, $category, $categoryDefault);
$categories =CategoryQuery::create()->filterById($categoryIds, Criteria::IN)->find();
$depth = $this->getDepth();
if (null !== $depth) {
foreach (CategoryQuery::findAllChild($category, $depth) as $subCategory) {
$categories->prepend($subCategory);
}
}
$search->filterByCategory(
$categories,
Criteria::IN
);
}
$new = $this->getNew();
if ($new === true) {
$search->where('`pse`.NEWNESS' . Criteria::EQUAL . '1');
} elseif ($new === false) {
$search->where('`pse`.NEWNESS' . Criteria::EQUAL . '0');
}
$promo = $this->getPromo();
if ($promo === true) {
$search->where('`pse`.PROMO' . Criteria::EQUAL . '1');
} elseif ($promo === false) {
$search->where('`pse`.PROMO' . Criteria::EQUAL . '0');
}
$min_stock = $this->getMin_stock();
if (null != $min_stock) {
$search->where('`pse`.QUANTITY' . Criteria::GREATER_THAN . '?', $min_stock, \PDO::PARAM_INT);
}
$min_weight = $this->getMin_weight();
if (null != $min_weight) {
$search->where('`pse`.WEIGHT' . Criteria::GREATER_THAN . '?', $min_weight, \PDO::PARAM_STR);
}
$max_weight = $this->getMax_weight();
if (null != $max_weight) {
$search->where('`is_max_weight`.WEIGHT' . Criteria::LESS_THAN . '?', $max_weight, \PDO::PARAM_STR);
}
$min_price = $this->getMin_price();
if (null !== $min_price) {
if (false === ConfigQuery::useTaxFreeAmounts()) {
// @todo
}
$search->where('ROUND(' . $priceToCompareAsSQL . ', 2)>=?', $min_price, \PDO::PARAM_STR);
}
$max_price = $this->getMax_price();
if (null !== $max_price) {
if (false === ConfigQuery::useTaxFreeAmounts()) {
// @todo
}
$search->where('ROUND(' . $priceToCompareAsSQL . ', 2)<=?', $max_price, \PDO::PARAM_STR);
}
$current = $this->getCurrent();
if ($current === true) {
$search->filterById($this->request->get("product_id"), Criteria::EQUAL);
} elseif ($current === false) {
$search->filterById($this->request->get("product_id"), Criteria::NOT_IN);
}
$current_category = $this->getCurrent_category();
if ($current_category === true) {
$search->filterByCategory(
CategoryQuery::create()->filterByProduct(
ProductCategoryQuery::create()->filterByProductId(
$this->request->get("product_id"),
Criteria::EQUAL
)->find(),
Criteria::IN
)->find(),
Criteria::IN
);
} elseif ($current_category === false) {
$search->filterByCategory(
CategoryQuery::create()->filterByProduct(
ProductCategoryQuery::create()->filterByProductId(
$this->request->get("product_id"),
Criteria::EQUAL
)->find(),
Criteria::IN
)->find(),
Criteria::NOT_IN
);
}
$visible = $this->getVisible();
if ($visible !== Type\BooleanOrBothType::ANY) $search->filterByVisible($visible ? 1 : 0);
$exclude = $this->getExclude();
if (!is_null($exclude)) {
$search->filterById($exclude, Criteria::NOT_IN);
}
$exclude_category = $this->getExclude_category();
if (!is_null($exclude_category)) {
$search->filterByCategory(
CategoryQuery::create()->filterById($exclude_category, Criteria::IN)->find(),
Criteria::NOT_IN
);
}
$feature_availability = $this->getFeature_availability();
$this->manageFeatureAv($search, $feature_availability);
$feature_values = $this->getFeature_values();
$this->manageFeatureValue($search, $feature_values);
$search->groupBy(ProductTableMap::ID);
$search->withColumn('`pse`.ID', 'pse_id');
$search->withColumn('`pse`.NEWNESS', 'is_new');
$search->withColumn('`pse`.PROMO', 'is_promo');
$search->withColumn('`pse`.QUANTITY', 'quantity');
$search->withColumn('`pse`.WEIGHT', 'weight');
$search->withColumn('`pse`.EAN_CODE', 'ean_code');
$orders = $this->getOrder();
foreach ($orders as $order) {
switch ($order) {
case "id":
$search->orderById(Criteria::ASC);
break;
case "id_reverse":
$search->orderById(Criteria::DESC);
break;
case "alpha":
$search->addAscendingOrderByColumn('i18n_TITLE');
break;
case "alpha_reverse":
$search->addDescendingOrderByColumn('i18n_TITLE');
break;
case "min_price":
$search->addAscendingOrderByColumn('real_price');
break;
case "max_price":
$search->addDescendingOrderByColumn('real_price');
break;
case "manual":
if(null === $categoryIds || count($categoryIds) != 1)
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
$search->orderByPosition(Criteria::ASC);
break;
case "manual_reverse":
if(null === $categoryIds || count($categoryIds) != 1)
throw new \InvalidArgumentException('Manual order cannot be set without single category argument');
$search->orderByPosition(Criteria::DESC);
break;
case "ref":
$search->orderByRef(Criteria::ASC);
break;
case "promo":
$search->addDescendingOrderByColumn('is_promo');
break;
case "new":
$search->addDescendingOrderByColumn('is_new');
break;
case "given_id":
if(null === $id)
throw new \InvalidArgumentException('Given_id order cannot be set without `id` argument');
foreach ($id as $singleId) {
$givenIdMatched = 'given_id_matched_' . $singleId;
$search->withColumn(ProductTableMap::ID . "='$singleId'", $givenIdMatched);
$search->orderBy($givenIdMatched, Criteria::DESC);
}
break;
case "random":
$search->clearOrderByColumns();
$search->addAscendingOrderByColumn('RAND()');
break(2);
}
}
/* perform search */
$products = $this->search($search, $pagination);
$loopResult = new LoopResult($products);
$taxCountry = CountryQuery::create()->findPk(64); // @TODO : make it magic
foreach ($products as $product) {
$loopResultRow = new LoopResultRow($loopResult, $product, $this->versionable, $this->timestampable, $this->countable);
$price = $product->getVirtualColumn('price');
try {
$taxedPrice = $product->getTaxedPrice(
$taxCountry,
$price
);
} catch (TaxEngineException $e) {
$taxedPrice = null;
}
$promoPrice = $product->getVirtualColumn('promo_price');
try {
$taxedPromoPrice = $product->getTaxedPromoPrice(
$taxCountry,
$promoPrice
);
} catch (TaxEngineException $e) {
$taxedPromoPrice = null;
}
// Find previous and next product, in the default category.
$default_category_id = $product->getDefaultCategoryId();
$previous = ProductQuery::create()
->joinProductCategory()
->where('ProductCategory.category_id = ?', $default_category_id)
->filterByPosition($product->getPosition(), Criteria::LESS_THAN)
->orderByPosition(Criteria::DESC)
->findOne()
;
$next = ProductQuery::create()
->joinProductCategory()
->where('ProductCategory.category_id = ?', $default_category_id)
->filterByPosition($product->getPosition(), Criteria::GREATER_THAN)
->orderByPosition(Criteria::ASC)
->findOne()
;
$loopResultRow
->set("ID" , $product->getId())
->set("REF" , $product->getRef())
->set("IS_TRANSLATED" , $product->getVirtualColumn('IS_TRANSLATED'))
->set("LOCALE" , $locale)
->set("TITLE" , $product->getVirtualColumn('i18n_TITLE'))
->set("CHAPO" , $product->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION" , $product->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM" , $product->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("URL" , $product->getUrl($locale))
->set("BEST_PRICE" , $product->getVirtualColumn('is_promo') ? $promoPrice : $price)
->set("BEST_PRICE_TAX" , $taxedPrice - $product->getVirtualColumn('is_promo') ? $taxedPromoPrice - $promoPrice : $taxedPrice - $price)
->set("BEST_TAXED_PRICE" , $product->getVirtualColumn('is_promo') ? $taxedPromoPrice : $taxedPrice)
->set("PRICE" , $price)
->set("PRICE_TAX" , $taxedPrice - $price)
->set("TAXED_PRICE" , $taxedPrice)
->set("PROMO_PRICE" , $promoPrice)
->set("PROMO_PRICE_TAX" , $taxedPromoPrice - $promoPrice)
->set("TAXED_PROMO_PRICE" , $taxedPromoPrice)
->set("PRODUCT_SALE_ELEMENT" , $product->getVirtualColumn('pse_id'))
->set("WEIGHT" , $product->getVirtualColumn('weight'))
->set("QUANTITY" , $product->getVirtualColumn('quantity'))
->set("EAN_CODE" , $product->getVirtualColumn('ean_code'))
->set("IS_PROMO" , $product->getVirtualColumn('is_promo'))
->set("IS_NEW" , $product->getVirtualColumn('is_new'))
->set("POSITION" , $product->getPosition())
->set("VISIBLE" , $product->getVisible() ? "1" : "0")
->set("TEMPLATE" , $product->getTemplateId())
->set("HAS_PREVIOUS" , $previous != null ? 1 : 0)
->set("HAS_NEXT" , $next != null ? 1 : 0)
->set("PREVIOUS" , $previous != null ? $previous->getId() : -1)
->set("NEXT" , $next != null ? $next->getId() : -1)
->set("DEFAULT_CATEGORY" , $default_category_id)
->set("TAX_RULE_ID" , $product->getTaxRuleId())
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
/**
* @param $pagination
*
* @return \Thelia\Core\Template\Element\LoopResult
* @throws \InvalidArgumentException
*/
public function execComplex(&$pagination)
{
$currencyId = $this->getCurrency();
if (null !== $currencyId) {
@@ -175,7 +596,7 @@ class Product extends BaseI18nLoop
$title = $this->getTitle();
if(!is_null($title)){
if (!is_null($title)) {
$search->where(" CASE WHEN NOT ISNULL(`requested_locale_i18n`.ID) THEN `requested_locale_i18n`.`TITLE` ELSE `default_locale_i18n`.`TITLE` END ".Criteria::LIKE." ?", "%".$title."%", \PDO::PARAM_STR);
}
@@ -313,7 +734,7 @@ class Product extends BaseI18nLoop
* In propel we trust : $currency->getRate() always returns a float.
* Or maybe not : rate value is checked as a float in overloaded getRate method.
*/
$MinPriceToCompareAsSQL = 'CASE WHEN ISNULL(CASE WHEN `is_min_price`.PROMO=1 THEN `min_price_data`.PROMO_PRICE ELSE `min_price_data`.PRICE END) THEN
$MinPriceToCompareAsSQL = 'CASE WHEN ISNULL(CASE WHEN `is_min_price`.PROMO=1 THEN `min_price_data`.PROMO_PRICE ELSE `min_price_data`.PRICE END) OR `min_price_data`.FROM_DEFAULT_CURRENCY = 1 THEN
CASE WHEN `is_min_price`.PROMO=1 THEN `min_price_data' . $defaultCurrencySuffix . '`.PROMO_PRICE ELSE `min_price_data' . $defaultCurrencySuffix . '`.PRICE END * ' . $currency->getRate() . '
ELSE
CASE WHEN `is_min_price`.PROMO=1 THEN `min_price_data`.PROMO_PRICE ELSE `min_price_data`.PRICE END
@@ -351,7 +772,7 @@ class Product extends BaseI18nLoop
* In propel we trust : $currency->getRate() always returns a float.
* Or maybe not : rate value is checked as a float in overloaded getRate method.
*/
$MaxPriceToCompareAsSQL = 'CASE WHEN ISNULL(CASE WHEN `is_max_price`.PROMO=1 THEN `max_price_data`.PROMO_PRICE ELSE `max_price_data`.PRICE END) THEN
$MaxPriceToCompareAsSQL = 'CASE WHEN ISNULL(CASE WHEN `is_max_price`.PROMO=1 THEN `max_price_data`.PROMO_PRICE ELSE `max_price_data`.PRICE END) OR `min_price_data`.FROM_DEFAULT_CURRENCY = 1 THEN
CASE WHEN `is_max_price`.PROMO=1 THEN `max_price_data' . $defaultCurrencySuffix . '`.PROMO_PRICE ELSE `max_price_data' . $defaultCurrencySuffix . '`.PRICE END * ' . $currency->getRate() . '
ELSE
CASE WHEN `is_max_price`.PROMO=1 THEN `max_price_data`.PROMO_PRICE ELSE `max_price_data`.PRICE END
@@ -492,59 +913,11 @@ class Product extends BaseI18nLoop
$feature_availability = $this->getFeature_availability();
if (null !== $feature_availability) {
foreach ($feature_availability as $feature => $feature_choice) {
foreach ($feature_choice['values'] as $feature_av) {
$featureAlias = 'fa_' . $feature;
if($feature_av != '*')
$featureAlias .= '_' . $feature_av;
$search->joinFeatureProduct($featureAlias, Criteria::LEFT_JOIN)
->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_ID = ?", $feature, null, \PDO::PARAM_INT);
if($feature_av != '*')
$search->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_AV_ID = ?", $feature_av, null, \PDO::PARAM_INT);
}
/* format for mysql */
$sqlWhereString = $feature_choice['expression'];
if ($sqlWhereString == '*') {
$sqlWhereString = 'NOT ISNULL(`fa_' . $feature . '`.ID)';
} else {
$sqlWhereString = preg_replace('#([0-9]+)#', 'NOT ISNULL(`fa_' . $feature . '_' . '\1`.ID)', $sqlWhereString);
$sqlWhereString = str_replace('&', ' AND ', $sqlWhereString);
$sqlWhereString = str_replace('|', ' OR ', $sqlWhereString);
}
$search->where("(" . $sqlWhereString . ")");
}
}
$this->manageFeatureAv($search, $feature_availability);
$feature_values = $this->getFeature_values();
if (null !== $feature_values) {
foreach ($feature_values as $feature => $feature_choice) {
foreach ($feature_choice['values'] as $feature_value) {
$featureAlias = 'fv_' . $feature;
if($feature_value != '*')
$featureAlias .= '_' . $feature_value;
$search->joinFeatureProduct($featureAlias, Criteria::LEFT_JOIN)
->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_ID = ?", $feature, null, \PDO::PARAM_INT);
if($feature_value != '*')
$search->addJoinCondition($featureAlias, "`$featureAlias`.BY_DEFAULT = ?", $feature_value, null, \PDO::PARAM_STR);
}
/* format for mysql */
$sqlWhereString = $feature_choice['expression'];
if ($sqlWhereString == '*') {
$sqlWhereString = 'NOT ISNULL(`fv_' . $feature . '`.ID)';
} else {
$sqlWhereString = preg_replace('#([a-zA-Z0-9_\-]+)#', 'NOT ISNULL(`fv_' . $feature . '_' . '\1`.ID)', $sqlWhereString);
$sqlWhereString = str_replace('&', ' AND ', $sqlWhereString);
$sqlWhereString = str_replace('|', ' OR ', $sqlWhereString);
}
$search->where("(" . $sqlWhereString . ")");
}
}
$this->manageFeatureValue($search, $feature_values);
$search->groupBy(ProductTableMap::ID);
@@ -620,7 +993,8 @@ class Product extends BaseI18nLoop
try {
$taxedPrice = $product->getTaxedPrice(
$taxCountry
$taxCountry,
$product->getRealLowestPrice()
);
} catch (TaxEngineException $e) {
$taxedPrice = null;
@@ -668,12 +1042,71 @@ class Product extends BaseI18nLoop
->set("PREVIOUS" , $previous != null ? $previous->getId() : -1)
->set("NEXT" , $next != null ? $next->getId() : -1)
->set("DEFAULT_CATEGORY" , $default_category_id)
->set("TAX_RULE_ID" , $product->getTaxRuleId())
;
;
$loopResult->addRow($loopResultRow);
}
return $loopResult;
}
protected function manageFeatureAv(&$search, $feature_availability)
{
if (null !== $feature_availability) {
foreach ($feature_availability as $feature => $feature_choice) {
foreach ($feature_choice['values'] as $feature_av) {
$featureAlias = 'fa_' . $feature;
if($feature_av != '*')
$featureAlias .= '_' . $feature_av;
$search->joinFeatureProduct($featureAlias, Criteria::LEFT_JOIN)
->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_ID = ?", $feature, null, \PDO::PARAM_INT);
if($feature_av != '*')
$search->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_AV_ID = ?", $feature_av, null, \PDO::PARAM_INT);
}
/* format for mysql */
$sqlWhereString = $feature_choice['expression'];
if ($sqlWhereString == '*') {
$sqlWhereString = 'NOT ISNULL(`fa_' . $feature . '`.ID)';
} else {
$sqlWhereString = preg_replace('#([0-9]+)#', 'NOT ISNULL(`fa_' . $feature . '_' . '\1`.ID)', $sqlWhereString);
$sqlWhereString = str_replace('&', ' AND ', $sqlWhereString);
$sqlWhereString = str_replace('|', ' OR ', $sqlWhereString);
}
$search->where("(" . $sqlWhereString . ")");
}
}
}
protected function manageFeatureValue(&$search, $feature_values)
{
if (null !== $feature_values) {
foreach ($feature_values as $feature => $feature_choice) {
foreach ($feature_choice['values'] as $feature_value) {
$featureAlias = 'fv_' . $feature;
if($feature_value != '*')
$featureAlias .= '_' . $feature_value;
$search->joinFeatureProduct($featureAlias, Criteria::LEFT_JOIN)
->addJoinCondition($featureAlias, "`$featureAlias`.FEATURE_ID = ?", $feature, null, \PDO::PARAM_INT);
if($feature_value != '*')
$search->addJoinCondition($featureAlias, "`$featureAlias`.BY_DEFAULT = ?", $feature_value, null, \PDO::PARAM_STR);
}
/* format for mysql */
$sqlWhereString = $feature_choice['expression'];
if ($sqlWhereString == '*') {
$sqlWhereString = 'NOT ISNULL(`fv_' . $feature . '`.ID)';
} else {
$sqlWhereString = preg_replace('#([a-zA-Z0-9_\-]+)#', 'NOT ISNULL(`fv_' . $feature . '_' . '\1`.ID)', $sqlWhereString);
$sqlWhereString = str_replace('&', ' AND ', $sqlWhereString);
$sqlWhereString = str_replace('|', ' OR ', $sqlWhereString);
}
$search->where("(" . $sqlWhereString . ")");
}
}
}
}

View File

@@ -136,8 +136,8 @@ class ProductSaleElements extends BaseLoop
/**
* rate value is checked as a float in overloaded getRate method.
*/
$priceSelectorAsSQL = 'ROUND(CASE WHEN ISNULL(`price`.PRICE) THEN `price_default_currency`.PRICE * ' . $currency->getRate() . ' ELSE `price`.PRICE END, 2)';
$promoPriceSelectorAsSQL = 'ROUND(CASE WHEN ISNULL(`price`.PRICE) THEN `price_default_currency`.PROMO_PRICE * ' . $currency->getRate() . ' ELSE `price`.PROMO_PRICE END, 2)';
$priceSelectorAsSQL = 'ROUND(CASE WHEN ISNULL(`price`.PRICE) OR `price`.FROM_DEFAULT_CURRENCY = 1 THEN `price_default_currency`.PRICE * ' . $currency->getRate() . ' ELSE `price`.PRICE END, 2)';
$promoPriceSelectorAsSQL = 'ROUND(CASE WHEN ISNULL(`price`.PRICE) OR `price`.FROM_DEFAULT_CURRENCY = 1 THEN `price_default_currency`.PROMO_PRICE * ' . $currency->getRate() . ' ELSE `price`.PROMO_PRICE END, 2)';
$search->withColumn($priceSelectorAsSQL, 'price_PRICE')
->withColumn($promoPriceSelectorAsSQL, 'price_PROMO_PRICE')
->withColumn('CASE WHEN ' . ProductSaleElementsTableMap::PROMO . ' = 1 THEN ' . $promoPriceSelectorAsSQL . ' ELSE ' . $priceSelectorAsSQL . ' END', 'price_FINAL_PRICE');

View File

@@ -33,7 +33,6 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\ProfileQuery;
use Thelia\Type;
use Thelia\Type\BooleanOrBothType;
/**
*

View File

@@ -34,7 +34,6 @@ use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Model\ResourceQuery;
use Thelia\Type;
use Thelia\Type\BooleanOrBothType;
/**
*
@@ -87,7 +86,7 @@ class Resource extends BaseI18nLoop
$code = $this->getCode();
if(null !== $code) {
if (null !== $code) {
$search->filterByCode($code, Criteria::IN);
}

View File

@@ -85,10 +85,10 @@ class TaxRuleCountry extends BaseI18nLoop
$country = $this->getCountry();
$taxRule = $this->getTax_rule();
if($ask === 'countries') {
if ($ask === 'countries') {
$taxCountForOriginCountry = TaxRuleCountryQuery::create()->filterByCountryId($country)->count();
if($taxCountForOriginCountry > 0) {
if ($taxCountForOriginCountry > 0) {
$search->groupByCountryId();
$originalCountryJoin = new Join();
@@ -127,7 +127,7 @@ class TaxRuleCountry extends BaseI18nLoop
$search->addAscendingOrderByColumn('i18n_TITLE');
}
} elseif($ask === 'taxes') {
} elseif ($ask === 'taxes') {
$search->filterByCountryId($country);
/* manage tax translation */
@@ -151,8 +151,8 @@ class TaxRuleCountry extends BaseI18nLoop
$loopResultRow = new LoopResultRow($loopResult, $taxRuleCountry, $this->versionable, $this->timestampable, $this->countable);
if($ask === 'countries') {
if($taxCountForOriginCountry > 0) {
if ($ask === 'countries') {
if ($taxCountForOriginCountry > 0) {
$loopResultRow
->set("COUNTRY" , $taxRuleCountry->getCountryId())
->set("COUNTRY_TITLE" , $taxRuleCountry->getVirtualColumn(CountryTableMap::TABLE_NAME . '_i18n_TITLE'))
@@ -167,7 +167,7 @@ class TaxRuleCountry extends BaseI18nLoop
->set("COUNTRY_DESCRIPTION" , $taxRuleCountry->getVirtualColumn('i18n_DESCRIPTION'))
->set("COUNTRY_POSTSCRIPTUM" , $taxRuleCountry->getVirtualColumn('i18n_POSTSCRIPTUM'));
}
} elseif($ask === 'taxes') {
} elseif ($ask === 'taxes') {
$loopResultRow
->set("TAX_RULE" , $taxRuleCountry->getTaxRuleId())
->set("COUNTRY" , $taxRuleCountry->getCountryId())
@@ -178,8 +178,6 @@ class TaxRuleCountry extends BaseI18nLoop
;
}
$loopResult->addRow($loopResultRow);
}

View File

@@ -23,7 +23,7 @@
namespace Thelia\Core\Template;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Thelia;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Form\BaseForm;
/**
@@ -39,7 +39,7 @@ class ParserContext implements \IteratorAggregate
public function __construct(Request $request)
{
// Setup basic variables
$this->set('THELIA_VERSION' , ConfigQuery::read('thelia_version', 'undefined'))
$this->set('THELIA_VERSION' , Thelia::THELIA_VERSION)
;
}

View File

@@ -40,7 +40,7 @@ abstract class AbstractSmartyPlugin
*/
protected function _explode($commaSeparatedValues)
{
if(null === $commaSeparatedValues) {
if (null === $commaSeparatedValues) {
return array();
}

View File

@@ -60,8 +60,8 @@ use Symfony\Component\Form\Extension\Core\View\ChoiceView;
*/
class Form extends AbstractSmartyPlugin
{
static private $taggedFieldsStack = null;
static private $taggedFieldsStackPosition = null;
private static $taggedFieldsStack = null;
private static $taggedFieldsStackPosition = null;
protected $request;
protected $parserContext;
@@ -113,13 +113,12 @@ class Form extends AbstractSmartyPlugin
$template->assign("form_error", $instance->hasError() ? true : false);
$template->assign("form_error_message", $instance->getErrorMessage());
}
else {
} else {
return $content;
}
}
protected function assignFieldValues($template, $fieldName, $fieldValue, $fieldVars)
protected function assignFieldValues($template, $fieldName, $fieldValue, $fieldVars, $total_value_count = 1)
{
$template->assign("name", $fieldName);
@@ -127,7 +126,6 @@ class Form extends AbstractSmartyPlugin
$template->assign("checked", isset($fieldVars['checked']) ? $fieldVars['checked'] : false);
//data
$template->assign("data", $fieldVars['data']);
@@ -136,6 +134,8 @@ class Form extends AbstractSmartyPlugin
$template->assign('required', isset($fieldVars['required']) ? $fieldVars['required'] : false);
$template->assign('total_value_count', $total_value_count);
$errors = $fieldVars["errors"];
$template->assign("error", empty($errors) ? false : true);
@@ -159,13 +159,13 @@ class Form extends AbstractSmartyPlugin
$formFieldType = $formFieldConfig->getType()->getInnerType();
/* access to choices */
if($formFieldType instanceof ChoiceType) {
if ($formFieldType instanceof ChoiceType) {
$template->assign("choices", $formFieldView->vars['choices']);
}
/* access to collections */
if($formFieldType instanceof CollectionType) {
if( true === $formFieldConfig->getOption('prototype') ) {
if ($formFieldType instanceof CollectionType) {
if ( true === $formFieldConfig->getOption('prototype') ) {
} else {
/* access to choices */
@@ -177,17 +177,16 @@ class Form extends AbstractSmartyPlugin
}
/* access to thelia type */
if($formFieldType instanceof TheliaType) {
if ($formFieldType instanceof TheliaType) {
$template->assign("formType", $formFieldView->vars['type']);
switch($formFieldView->vars['type']) {
switch ($formFieldView->vars['type']) {
case "choice":
if(!isset($formFieldView->vars['options']['choices']) || !is_array($formFieldView->vars['options']['choices'])) {
if (!isset($formFieldView->vars['options']['choices']) || !is_array($formFieldView->vars['options']['choices'])) {
//throw new
}
$choices = array();
foreach($formFieldView->vars['options']['choices'] as $value => $choice) {
foreach ($formFieldView->vars['options']['choices'] as $value => $choice) {
$choices[] = new ChoiceView($value, $value, $choice);
}
$template->assign("choices", $choices);
@@ -208,49 +207,42 @@ class Form extends AbstractSmartyPlugin
$value = $formFieldView->vars["value"];
// We have a collection
if (count($formFieldView->children) > 0) {
if (0 < $value_count = count($formFieldView->children)) {
$key = $this->getParam($params, 'value_key');
$key = $this->getParam($params, 'value_key', null);
if ($key != null) {
if ($key !== null) {
// If the field is not found, use an empty value
$val = array_key_exists($key, $value) ? $value[$key] : '';
if (isset($value[$key])) {
$name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key);
$name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key);
$val = $value[$key];
$val = $value[$key];
$this->assignFieldValues($template, $name, $val, $formFieldView->vars);
}
else {
throw new \LogicException(sprintf("Cannot find a value for key '%s' in field '%s'", $key, $formFieldView->vars["name"]));
}
}
else {
$this->assignFieldValues($template, $name, $val, $formFieldView->vars, $value_count);
} else {
throw new \InvalidArgumentException(sprintf("Missing or empty parameter 'value_key' for field '%s'", $formFieldView->vars["name"]));
}
}
else {
} else {
$this->assignFieldValues($template, $formFieldView->vars["full_name"], $formFieldView->vars["value"], $formFieldView->vars);
}
$formFieldView->setRendered();
}
else {
} else {
return $content;
}
}
public function renderTaggedFormFields($params, $content, \Smarty_Internal_Template $template, &$repeat)
{
if(null === $content) {
if (null === $content) {
self::$taggedFieldsStack = $this->getFormFieldsFromTag($params);
self::$taggedFieldsStackPosition = 0;
} else {
self::$taggedFieldsStackPosition++;
}
if(isset(self::$taggedFieldsStack[self::$taggedFieldsStackPosition])) {
if (isset(self::$taggedFieldsStack[self::$taggedFieldsStackPosition])) {
$this->assignFieldValues(
$template,
self::$taggedFieldsStack[self::$taggedFieldsStackPosition]['view']->vars["full_name"],
@@ -270,7 +262,7 @@ class Form extends AbstractSmartyPlugin
self::$taggedFieldsStackPosition = null;
}
if(null !== $content) {
if (null !== $content) {
return $content;
}
}
@@ -324,8 +316,7 @@ class Form extends AbstractSmartyPlugin
if ($repeat) {
$this->assignFieldErrorVars($template, $errors);
}
else {
} else {
return $content;
}
}
@@ -366,8 +357,8 @@ class Form extends AbstractSmartyPlugin
throw new \InvalidArgumentException("'tag' parameter is missing");
$viewList = array();
foreach($instance->getView() as $view) {
if(isset($view->vars['attr']['tag']) && $tag == $view->vars['attr']['tag']) {
foreach ($instance->getView() as $view) {
if (isset($view->vars['attr']['tag']) && $tag == $view->vars['attr']['tag']) {
$fieldData = $instance->getForm()->all()[$view->vars['name']];
$viewList[] = array(
'view' => $view,

View File

@@ -73,10 +73,10 @@ class Format extends AbstractSmartyPlugin
$date = $this->getParam($params, "date", false);
if ($date === false) {
throw new SmartyPluginException("date is a mandatory parameter in format_date function");
return "";
}
if (!$date instanceof \DateTime) {
if (!($date instanceof \DateTime)) {
return "";
}
@@ -112,7 +112,7 @@ class Format extends AbstractSmartyPlugin
$number = $this->getParam($params, "number", false);
if ($number === false) {
throw new SmartyPluginException("number is a mandatory parameter in format_number function");
return "";
}
if ($number == '') {

View File

@@ -8,7 +8,6 @@ use \Symfony\Component\EventDispatcher\EventDispatcherInterface;
use \Smarty;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Thelia\Core\Template\ParserInterface;
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;

View File

@@ -54,9 +54,7 @@ use Propel\Runtime\Connection\ConnectionManagerSingle;
class Thelia extends Kernel
{
const THELIA_VERSION = 0.1;
protected $tpexConfig;
const THELIA_VERSION = '2.0.0-beta1';
public function init()
{

View File

@@ -25,12 +25,9 @@ namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Translation\Translator;
use Thelia\Model\AdminQuery;
use Thelia\Model\ProfileQuery;
use Thelia\Model\ConfigQuery;
class AdministratorCreationForm extends BaseForm
{
@@ -110,7 +107,7 @@ class AdministratorCreationForm extends BaseForm
{
$data = $context->getRoot()->getData();
if($data["password"] === '' && $data["password_confirm"] === '') {
if ($data["password"] === '' && $data["password_confirm"] === '') {
$context->addViolation("password can't be empty");
}
@@ -118,7 +115,7 @@ class AdministratorCreationForm extends BaseForm
$context->addViolation("password confirmation is not the same as password field");
}
if(strlen($data["password"]) < 4) {
if (strlen($data["password"]) < 4) {
$context->addViolation("password must be composed of at least 4 characters");
}
}
@@ -135,4 +132,4 @@ class AdministratorCreationForm extends BaseForm
{
return "thelia_admin_administrator_creation";
}
}
}

View File

@@ -25,7 +25,6 @@ namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\AdminQuery;
class AdministratorModificationForm extends AdministratorCreationForm
@@ -90,7 +89,7 @@ class AdministratorModificationForm extends AdministratorCreationForm
$context->addViolation("password confirmation is not the same as password field");
}
if($data["password"] !== '' && strlen($data["password"]) < 4) {
if ($data["password"] !== '' && strlen($data["password"]) < 4) {
$context->addViolation("password must be composed of at least 4 characters");
}
}

View File

@@ -27,7 +27,6 @@ use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
/**
* Class ContactForm
* @package Thelia\Form
@@ -107,4 +106,4 @@ class ContactForm extends BaseForm
{
return 'thelia_contact';
}
}
}

View File

@@ -23,8 +23,6 @@
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Thelia\Model\ModuleQuery;
use Thelia\Module\BaseModule;
/**
* Class CouponCode

View File

@@ -27,7 +27,6 @@ use Symfony\Component\Validator\Constraints\Date;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\NotEqualTo;
use Symfony\Component\Validator\Constraints\Range;
/**
* Created by JetBrains PhpStorm.

View File

@@ -26,7 +26,6 @@ use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Translation\Translator;
use Thelia\Model\CustomerQuery;
/**
* Class CustomerPasswordUpdateForm

View File

@@ -22,11 +22,8 @@
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Model\CustomerQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Core\Translation\Translator;
/**
* Class CustomerProfilUpdateForm
@@ -69,7 +66,6 @@ class CustomerProfilUpdateForm extends CustomerCreateForm
));
}
/**
* @param $value
* @param ExecutionContextInterface $context

View File

@@ -26,7 +26,6 @@ use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
use Thelia\Core\Translation\Translator;
/**
* Class LangCreateForm
* @package Thelia\Form\Lang
@@ -113,4 +112,4 @@ class LangCreateForm extends BaseForm
{
return 'thelia_language_create';
}
}
}

View File

@@ -24,11 +24,9 @@
namespace Thelia\Form\Lang;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Range;
use Thelia\Form\BaseForm;
use Thelia\Core\Translation\Translator;
/**
* Class LangDefaultBehaviorForm
* @package Thelia\Form\Lang
@@ -82,4 +80,4 @@ class LangDefaultBehaviorForm extends BaseForm
{
return 'thelia_lang_defaultBehavior';
}
}
}

View File

@@ -25,7 +25,6 @@ namespace Thelia\Form\Lang;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* Class LangUpdateForm
* @package Thelia\Form\Lang
@@ -51,4 +50,4 @@ class LangUpdateForm extends LangCreateForm
{
return 'thelia_lang_update';
}
}
}

View File

@@ -24,7 +24,6 @@
namespace Thelia\Form\Lang;
use Thelia\Core\Event\ActionEvent;
/**
* Class LangUrlEvent
* @package Thelia\Form\Lang
@@ -43,4 +42,4 @@ class LangUrlEvent extends ActionEvent
{
return $this->url;
}
}
}

View File

@@ -26,7 +26,6 @@ use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Form\BaseForm;
use Thelia\Model\LangQuery;
/**
* Class LangUrlForm
* @package Thelia\Form\Lang
@@ -84,4 +83,4 @@ class LangUrlForm extends BaseForm
{
return 'thelia_language_url';
}
}
}

View File

@@ -30,7 +30,6 @@ use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Model\NewsletterQuery;
/**
* Class NewsletterForm
* @package Thelia\Form
@@ -95,4 +94,4 @@ class NewsletterForm extends BaseForm
{
return 'thelia_newsletter';
}
}
}

View File

@@ -22,8 +22,91 @@
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Model\Currency;
use Thelia\Core\Translation\Translator;
class ProductDefaultSaleElementUpdateForm extends ProductSaleElementUpdateForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->formBuilder
->add("product_id", "integer", array(
"label" => Translator::getInstance()->trans("Product ID *"),
"label_attr" => array("for" => "product_id_field"),
"constraints" => array(new GreaterThan(array('value' => 0)))
))
->add("product_sale_element_id", "integer", array(
"label" => Translator::getInstance()->trans("Product sale element ID *"),
"label_attr" => array("for" => "product_sale_element_id_field")
))
->add("reference", "text", array(
"label" => Translator::getInstance()->trans("Reference *"),
"label_attr" => array("for" => "reference_field")
))
->add("price", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Product price excluding taxes *"),
"label_attr" => array("for" => "price_field")
))
->add("price_with_tax", "number", array(
"label" => Translator::getInstance()->trans("Product price including taxes"),
"label_attr" => array("for" => "price_with_tax_field")
))
->add("currency", "integer", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Price currency *"),
"label_attr" => array("for" => "currency_field")
))
->add("tax_rule", "integer", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Tax rule for this product *"),
"label_attr" => array("for" => "tax_rule_field")
))
->add("weight", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Weight *"),
"label_attr" => array("for" => "weight_field")
))
->add("quantity", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Available quantity *"),
"label_attr" => array("for" => "quantity_field")
))
->add("sale_price", "number", array(
"label" => Translator::getInstance()->trans("Sale price without taxes"),
"label_attr" => array("for" => "price_with_tax_field")
))
->add("sale_price_with_tax", "number", array(
"label" => Translator::getInstance()->trans("Sale price including taxes"),
"label_attr" => array("for" => "sale_price_with_tax_field")
))
->add("onsale", "integer", array(
"label" => Translator::getInstance()->trans("This product is on sale"),
"label_attr" => array("for" => "onsale_field")
))
->add("isnew", "integer", array(
"label" => Translator::getInstance()->trans("Advertise this product as new"),
"label_attr" => array("for" => "isnew_field")
))
->add("isdefault", "integer", array(
"label" => Translator::getInstance()->trans("Is it the default product sale element ?"),
"label_attr" => array("for" => "isdefault_field")
))
->add("ean_code", "text", array(
"label" => Translator::getInstance()->trans("EAN Code"),
"label_attr" => array("for" => "ean_code_field")
))
->add("use_exchange_rate", "integer", array(
"label" => Translator::getInstance()->trans("Apply exchange rates on price in %sym", array("%sym" => Currency::getDefaultCurrency()->getSymbol())),
"label_attr" => array("for" => "use_exchange_rate_field")
))
;
}
public function getName()
{
return "thelia_product_default_sale_element_update_form";

View File

@@ -23,9 +23,9 @@
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Core\Translation\Translator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Model\Currency;
use Thelia\Core\Translation\Translator;
class ProductSaleElementUpdateForm extends BaseForm
{
@@ -34,68 +34,124 @@ class ProductSaleElementUpdateForm extends BaseForm
protected function buildForm()
{
$this->formBuilder
->add("tax_rule", "integer", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Tax rule for this product *"),
"label_attr" => array("for" => "tax_rule_field")
))
->add("product_id", "integer", array(
"label" => Translator::getInstance()->trans("Product ID *"),
"label_attr" => array("for" => "product_id_field"),
"constraints" => array(new GreaterThan(array('value' => 0)))
"label" => Translator::getInstance()->trans("Product ID *"),
"label_attr" => array("for" => "product_id_field"),
"constraints" => array(new GreaterThan(array('value' => 0)))
))
->add("product_sale_element_id", "integer", array(
"label" => Translator::getInstance()->trans("Product sale element ID *"),
"label_attr" => array("for" => "product_sale_element_id_field")
))
->add("reference", "text", array(
"label" => Translator::getInstance()->trans("Reference *"),
"label_attr" => array("for" => "reference_field")
))
->add("price", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Product price excluding taxes *"),
"label_attr" => array("for" => "price_field")
->add("default_pse", "integer", array(
"label" => Translator::getInstance()->trans("Default product sale element"),
"label_attr" => array("for" => "default_pse_field"),
))
->add("currency", "integer", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Price currency *"),
"label_attr" => array("for" => "currency_field")
))
->add("tax_rule", "integer", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Tax rule for this product *"),
"label_attr" => array("for" => "tax_rule_field")
))
->add("weight", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Weight *"),
"label_attr" => array("for" => "weight_field")
))
->add("quantity", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Available quantity *"),
"label_attr" => array("for" => "quantity_field")
))
->add("sale_price", "number", array(
"label" => Translator::getInstance()->trans("Sale price without taxes *"),
"label_attr" => array("for" => "price_with_tax_field")
))
->add("onsale", "integer", array(
"label" => Translator::getInstance()->trans("This product is on sale"),
"label_attr" => array("for" => "onsale_field")
))
->add("isnew", "integer", array(
"label" => Translator::getInstance()->trans("Advertise this product as new"),
"label_attr" => array("for" => "isnew_field")
))
->add("isdefault", "integer", array(
"label" => Translator::getInstance()->trans("Is it the default product sale element ?"),
"label_attr" => array("for" => "isdefault_field")
))
->add("ean_code", "integer", array(
"label" => Translator::getInstance()->trans("EAN Code"),
"label_attr" => array("for" => "ean_code_field")
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Price currency *"),
"label_attr" => array("for" => "currency_field")
))
->add("use_exchange_rate", "integer", array(
"label" => Translator::getInstance()->trans("Apply exchange rates on price in %sym", array("%sym" => Currency::getDefaultCurrency()->getSymbol())),
"label_attr" => array("for" => "use_exchange_rate_field")
))
// -- Collections
->add('product_sale_element_id', 'collection', array(
'type' => 'integer',
'label' => Translator::getInstance()->trans('Product sale element ID *'),
'label_attr' => array('for' => 'product_sale_element_id_field'),
'allow_add' => true,
'allow_delete' => true,
))
->add('reference', 'collection', array(
'type' => 'text',
'label' => Translator::getInstance()->trans('Reference *'),
'label_attr' => array('for' => 'reference_field'),
'allow_add' => true,
'allow_delete' => true,
))
->add('price', 'collection', array(
'type' => 'number',
'label' => Translator::getInstance()->trans('Product price excluding taxes *'),
'label_attr' => array('for' => 'price_field'),
'allow_add' => true,
'allow_delete' => true,
'options' => array(
'constraints' => array(new NotBlank()),
)
))
->add('price_with_tax', 'collection', array(
'type' => 'number',
'label' => Translator::getInstance()->trans('Product price including taxes'),
'label_attr' => array('for' => 'price_with_tax_field'),
'allow_add' => true,
'allow_delete' => true,
))
->add('weight', 'collection', array(
'type' => 'number',
'label' => Translator::getInstance()->trans('Weight *'),
'label_attr' => array('for' => 'weight_field'),
'allow_add' => true,
'allow_delete' => true,
'options' => array(
'constraints' => array(new NotBlank()),
)
))
->add('quantity', 'collection', array(
'type' => 'number',
'label' => Translator::getInstance()->trans('Available quantity *'),
'label_attr' => array('for' => 'quantity_field'),
'allow_add' => true,
'allow_delete' => true,
'options' => array(
'constraints' => array(new NotBlank()),
)
))
->add('sale_price', 'collection', array(
'label' => Translator::getInstance()->trans('Sale price without taxes'),
'label_attr' => array('for' => 'price_with_tax_field'),
'allow_add' => true,
'allow_delete' => true,
))
->add('sale_price_with_tax', 'collection', array(
'type' => 'number',
'label' => Translator::getInstance()->trans('Sale price including taxes'),
'label_attr' => array('for' => 'sale_price_with_tax_field'),
'allow_add' => true,
'allow_delete' => true,
))
->add('onsale', 'collection', array(
'type' => 'integer',
'label' => Translator::getInstance()->trans('This product is on sale'),
'label_attr' => array('for' => 'onsale_field'),
'allow_add' => true,
'allow_delete' => true,
))
->add('isnew', 'collection', array(
'type' => 'integer',
'label' => Translator::getInstance()->trans('Advertise this product as new'),
'label_attr' => array('for' => 'isnew_field'),
'allow_add' => true,
'allow_delete' => true,
))
->add('isdefault', 'collection', array(
'type' => 'integer',
'label' => Translator::getInstance()->trans('Is it the default product sale element ?'),
'label_attr' => array('for' => 'isdefault_field'),
'allow_add' => true,
'allow_delete' => true,
))
->add('ean_code', 'collection', array(
'type' => 'text',
'label' => Translator::getInstance()->trans('EAN Code'),
'label_attr' => array('for' => 'ean_code_field'),
'allow_add' => true,
'allow_delete' => true,
))
;
}

View File

@@ -26,7 +26,6 @@ use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ProfileQuery;
use Thelia\Model\ModuleQuery;
@@ -57,7 +56,7 @@ class ProfileUpdateModuleAccessForm extends BaseForm
))
;
foreach(ModuleQuery::create()->find() as $module) {
foreach (ModuleQuery::create()->find() as $module) {
$this->formBuilder->add(
self::MODULE_ACCESS_FIELD_PREFIX . ':' . str_replace(".", ":", $module->getCode()),
"choice",

View File

@@ -26,7 +26,6 @@ use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Translation\Translator;
use Thelia\Model\ProfileQuery;
use Thelia\Model\ResourceQuery;
@@ -57,7 +56,7 @@ class ProfileUpdateResourceAccessForm extends BaseForm
))
;
foreach(ResourceQuery::create()->find() as $resource) {
foreach (ResourceQuery::create()->find() as $resource) {
$this->formBuilder->add(
self::RESOURCE_ACCESS_FIELD_PREFIX . ':' . str_replace(".", ":", $resource->getCode()),
"choice",

Some files were not shown because too many files have changed in this diff Show More