Merge branch 'catalog'

Conflicts:
	core/lib/Thelia/Config/Resources/config.xml
	core/lib/Thelia/Config/Resources/routing/admin.xml
	core/lib/Thelia/Core/Template/Loop/Country.php
	core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php
	core/lib/Thelia/Model/Country.php
	core/lib/Thelia/Model/Profile.php
	core/lib/Thelia/Model/ProfileQuery.php
	install/insert.sql
	install/thelia.sql
	local/config/schema.xml
This commit is contained in:
Franck Allimant
2013-10-24 00:16:33 +02:00
38 changed files with 3324 additions and 1903 deletions

View File

@@ -221,6 +221,7 @@ class Order extends BaseAction implements EventSubscriberInterface
->setWeight($pse->getWeight())
->setTaxRuleTitle($taxRuleI18n->getTitle())
->setTaxRuleDescription($taxRuleI18n->getDescription())
->setEanCode($pse->getEanCode())
;
$orderProduct->setDispatcher($this->getDispatcher());
$orderProduct->save($con);

View File

@@ -54,10 +54,10 @@ 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\ProductCreateCombinationEvent;
use Thelia\Core\Event\Product\ProductSaleElementCreateEvent;
use Propel\Runtime\Propel;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Core\Event\Product\ProductDeleteCombinationEvent;
use Thelia\Core\Event\Product\ProductSaleElementDeleteEvent;
use Thelia\Model\ProductPrice;
use Thelia\Model\ProductSaleElements;
use Thelia\Core\Event\Product\ProductAddAccessoryEvent;
@@ -85,8 +85,6 @@ class Product extends BaseAction implements EventSubscriberInterface
// Set the default tax rule to this product
->setTaxRule(TaxRuleQuery::create()->findOneByIsDefault(true))
//public function create($defaultCategoryId, $basePrice, $priceCurrencyId, $taxRuleId, $baseWeight) {
->create(
$event->getDefaultCategory(),
$event->getBasePrice(),
@@ -304,6 +302,11 @@ class Product extends BaseAction implements EventSubscriberInterface
return $this->genericUpdatePosition(ProductAssociatedContentQuery::create(), $event);
}
/**
* Update the value of a product feature.
*
* @param FeatureProductUpdateEvent $event
*/
public function updateFeatureProductValue(FeatureProductUpdateEvent $event)
{
// If the feature is not free text, it may have one ore more values.
@@ -346,6 +349,11 @@ class Product extends BaseAction implements EventSubscriberInterface
$event->setFeatureProduct($featureProduct);
}
/**
* Delete a product feature value
*
* @param FeatureProductDeleteEvent $event
*/
public function deleteFeatureProductValue(FeatureProductDeleteEvent $event)
{
$featureProduct = FeatureProductQuery::create()
@@ -355,76 +363,6 @@ class Product extends BaseAction implements EventSubscriberInterface
;
}
public function createProductCombination(ProductCreateCombinationEvent $event)
{
$con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$product = $event->getProduct();
// Create an empty product sale element
$salesElement = new ProductSaleElements();
$salesElement
->setProduct($product)
->setRef($product->getRef())
->setPromo(0)
->setNewness(0)
->setWeight(0)
->setIsDefault(false)
->save($con)
;
// Create an empty product price in the default currency
$product_price = new ProductPrice();
$product_price
->setProductSaleElements($salesElement)
->setPromoPrice(0)
->setPrice(0)
->setCurrencyId($event->getCurrencyId())
->save($con)
;
$combinationAttributes = $event->getAttributeAvList();
if (count($combinationAttributes) > 0) {
foreach ($combinationAttributes as $attributeAvId) {
$attributeAv = AttributeAvQuery::create()->findPk($attributeAvId);
if ($attributeAv !== null) {
$attributeCombination = new AttributeCombination();
$attributeCombination
->setAttributeAvId($attributeAvId)
->setAttribute($attributeAv->getAttribute())
->setProductSaleElements($salesElement)
->save();
}
}
}
// Store all the stuff !
$con->commit();
} catch (\Exception $ex) {
$con->rollback();
throw $ex;
}
}
public function deleteProductCombination(ProductDeleteCombinationEvent $event)
{
if (null !== $pse = ProductSaleElementsQuery::create()->findPk($event->getProductSaleElementId())) {
$pse->delete();
}
}
/**
* {@inheritDoc}
*/
@@ -436,18 +374,15 @@ class Product extends BaseAction implements EventSubscriberInterface
TheliaEvents::PRODUCT_DELETE => array("delete", 128),
TheliaEvents::PRODUCT_TOGGLE_VISIBILITY => array("toggleVisibility", 128),
TheliaEvents::PRODUCT_UPDATE_POSITION => array("updatePosition", 128),
TheliaEvents::PRODUCT_UPDATE_POSITION => array("updatePosition", 128),
TheliaEvents::PRODUCT_ADD_CONTENT => array("addContent", 128),
TheliaEvents::PRODUCT_REMOVE_CONTENT => array("removeContent", 128),
TheliaEvents::PRODUCT_UPDATE_ACCESSORY_POSITION => array("updateAccessoryPosition", 128),
TheliaEvents::PRODUCT_UPDATE_CONTENT_POSITION => array("updateContentPosition", 128),
TheliaEvents::PRODUCT_ADD_COMBINATION => array("createProductCombination", 128),
TheliaEvents::PRODUCT_DELETE_COMBINATION => array("deleteProductCombination", 128),
TheliaEvents::PRODUCT_ADD_ACCESSORY => array("addAccessory", 128),
TheliaEvents::PRODUCT_REMOVE_ACCESSORY => array("removeAccessory", 128),
TheliaEvents::PRODUCT_ADD_ACCESSORY => array("addAccessory", 128),
TheliaEvents::PRODUCT_REMOVE_ACCESSORY => array("removeAccessory", 128),
TheliaEvents::PRODUCT_UPDATE_ACCESSORY_POSITION => array("updateAccessoryPosition", 128),
TheliaEvents::PRODUCT_ADD_CATEGORY => array("addCategory", 128),
TheliaEvents::PRODUCT_REMOVE_CATEGORY => array("removeCategory", 128),
@@ -456,7 +391,6 @@ class Product extends BaseAction implements EventSubscriberInterface
TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE => array("updateFeatureProductValue", 128),
TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE => array("deleteFeatureProductValue", 128),
);
}
}

View File

@@ -0,0 +1,232 @@
<?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\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;
use Thelia\Model\ProductSaleElements;
use Thelia\Model\ProductPrice;
use Thelia\Model\AttributeCombination;
use Thelia\Core\Event\ProductSaleElement\ProductSaleElementDeleteEvent;
use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Core\Event\ProductSaleElement\ProductSaleElementUpdateEvent;
use Thelia\Model\ProductPriceQuery;
use Propel\Runtime\Propel;
use Thelia\Model\AttributeAvQuery;
use Thelia\Model\Currency;
use Thelia\Model\Map\AttributeCombinationTableMap;
use Propel\Runtime\ActiveQuery\Criteria;
class ProductSaleElement extends BaseAction implements EventSubscriberInterface
{
/**
* Create a new product sale element, with or without combination
*
* @param ProductSaleElementCreateEvent $event
* @throws Exception
*/
public function create(ProductSaleElementCreateEvent $event)
{
$con = Propel::getWriteConnection(ProductSaleElementsTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
// Check if we have a PSE without combination, this is the "default" PSE. Attach the combination to this PSE
$salesElement = ProductSaleElementsQuery::create()
->filterByProductId($event->getProduct()->getId())
->joinAttributeCombination(null, Criteria::LEFT_JOIN)
->add(AttributeCombinationTableMap::PRODUCT_SALE_ELEMENTS_ID, null, Criteria::ISNULL)
->findOne($con);
if ($salesElement == null) {
// Create a new product sale element
$salesElement = $event->getProduct()->createDefaultProductSaleElement($con, 0, 0, $event->getCurrencyId(), true);
}
else {
// This one is the default
$salesElement->setIsDefault(true)->save($con);
}
// Attach combination, if defined.
$combinationAttributes = $event->getAttributeAvList();
if (count($combinationAttributes) > 0) {
foreach ($combinationAttributes as $attributeAvId) {
$attributeAv = AttributeAvQuery::create()->findPk($attributeAvId);
if ($attributeAv !== null) {
$attributeCombination = new AttributeCombination();
$attributeCombination
->setAttributeAvId($attributeAvId)
->setAttribute($attributeAv->getAttribute())
->setProductSaleElements($salesElement)
->save();
}
}
}
// Store all the stuff !
$con->commit();
}
catch (\Exception $ex) {
$con->rollback();
throw $ex;
}
}
/**
* Update an existing product sale element
*
* @param ProductSaleElementUpdateEvent $event
*/
public function update(ProductSaleElementUpdateEvent $event)
{
$salesElement = ProductSaleElementsQuery::create()->findPk($event->getProductSaleElementId());
$con = Propel::getWriteConnection(ProductSaleElementsTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
// If product sale element is not defined, create it.
if ($salesElement == null) {
$salesElement = new ProductSaleElements();
$salesElement->setProduct($event->getProduct());
}
// Update sale element
$salesElement
->setRef($event->getReference())
->setQuantity($event->getQuantity())
->setPromo($event->getOnsale())
->setNewness($event->getIsnew())
->setWeight($event->getWeight())
->setIsDefault($event->getIsDefault())
->setEanCode($event->getEanCode())
->save()
;
// Update/create price for current currency
$productPrice = ProductPriceQuery::create()
->filterByCurrencyId($event->getCurrencyId())
->filterByProductSaleElementsId($salesElement->getId())
->findOne($con);
// If price is not defined, create it.
if ($productPrice == null) {
$productPrice = new ProductPrice();
$productPrice
->setProductSaleElements($salesElement)
->setCurrencyId($event->getCurrencyId())
;
}
$productPrice
->setPromoPrice($event->getSalePrice())
->setPrice($event->getPrice())
->save($con)
;
// Store all the stuff !
$con->commit();
}
catch (\Exception $ex) {
$con->rollback();
throw $ex;
}
}
/**
* Delete a product sale element
*
* @param ProductSaleElementDeleteEvent $event
*/
public function delete(ProductSaleElementDeleteEvent $event)
{
if (null !== $pse = ProductSaleElementsQuery::create()->findPk($event->getProductSaleElementId())) {
$product = $pse->getProduct();
$con = Propel::getWriteConnection(ProductSaleElementsTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
$pse->delete($con);
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) {
// 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->setIsDefault(true)->save($con);
}
// Store all the stuff !
$con->commit();
}
catch (\Exception $ex) {
$con->rollback();
throw $ex;
}
}
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
TheliaEvents::PRODUCT_ADD_PRODUCT_SALE_ELEMENT => array("create", 128),
TheliaEvents::PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT => array("update", 128),
TheliaEvents::PRODUCT_DELETE_PRODUCT_SALE_ELEMENT => array("delete", 128),
);
}
}

View File

@@ -51,6 +51,11 @@
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.product_sale_element" class="Thelia\Action\ProductSaleElement">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>
</service>
<service id="thelia.action.config" class="Thelia\Action\Config">
<argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/>

View File

@@ -75,10 +75,12 @@
<form name="thelia.admin.product.creation" class="Thelia\Form\ProductCreationForm"/>
<form name="thelia.admin.product.modification" class="Thelia\Form\ProductModificationForm"/>
<form name="thelia.admin.product.details.modification" class="Thelia\Form\ProductDetailsModificationForm"/>
<form name="thelia.admin.product.image.modification" class="Thelia\Form\ProductImageModification"/>
<form name="thelia.admin.product.document.modification" class="Thelia\Form\ProductDocumentModification"/>
<form name="thelia.admin.product_sale_element.update" class="Thelia\Form\ProductSaleElementUpdateForm"/>
<form name="thelia.admin.product_default_sale_element.update" class="Thelia\Form\ProductDefaultSaleElementUpdateForm"/>
<form name="thelia.admin.product.deletion" class="Thelia\Form\ProductModificationForm"/>
<form name="thelia.admin.folder.creation" class="Thelia\Form\FolderCreationForm"/>
@@ -153,6 +155,7 @@
<form name="thelia.contact" class="Thelia\Form\ContactForm"/>
<form name="thelia.newsletter" class="Thelia\Form\NewsletterForm"/>
<form name="thelia.lang.update" class="Thelia\Form\Lang\LangUpdateForm"/>
<form name="thelia.lang.create" class="Thelia\Form\Lang\LangCreateForm"/>
<form name="thelia.lang.defaultBehavior" class="Thelia\Form\Lang\LangDefaultBehaviorForm"/>

View File

@@ -303,6 +303,10 @@
<default key="_controller">Thelia\Controller\Admin\ProductController::updateContentPositionAction</default>
</route>
<route id="admin.product.update-content-position" path="/admin/product/calculate-price">
<default key="_controller">Thelia\Controller\Admin\ProductController::priceCaclulator</default>
</route>
<!-- accessories -->
<route id="admin.products.accessories.add" path="/admin/products/accessory/add">
@@ -349,19 +353,19 @@
</route>
<route id="admin.product.combination.add" path="/admin/product/combination/add">
<default key="_controller">Thelia\Controller\Admin\ProductController::addCombinationAction</default>
<default key="_controller">Thelia\Controller\Admin\ProductController::addProductSaleElementAction</default>
</route>
<route id="admin.product.combination.delete" path="/admin/product/combination/delete">
<default key="_controller">Thelia\Controller\Admin\ProductController::deleteCombinationAction</default>
<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::updateCombinationAction</default>
<default key="_controller">Thelia\Controller\Admin\ProductController::updateProductSaleElementAction</default>
</route>
<route id="admin.product.combination.defaut-price.update" path="/admin/product/default-price/update">
<default key="_controller">Thelia\Controller\Admin\ProductController::updateDefaultPriceAction</default>
<default key="_controller">Thelia\Controller\Admin\ProductController::updateProductDefaultSaleElementAction</default>
</route>

View File

@@ -48,6 +48,23 @@ use Thelia\Model\CategoryQuery;
use Thelia\Core\Event\Product\ProductAddAccessoryEvent;
use Thelia\Core\Event\Product\ProductDeleteAccessoryEvent;
use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Core\Event\ProductSaleElement\ProductSaleElementDeleteEvent;
use Thelia\Core\Event\ProductSaleElement\ProductSaleElementUpdateEvent;
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;
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;
/**
* Manages products
@@ -172,10 +189,58 @@ class ProductController extends AbstractCrudController
protected function hydrateObjectForm($object)
{
// Get the default produc sales element
$salesElement = ProductSaleElementsQuery::create()->filterByProduct($object)->filterByIsDefault(true)->findOne();
$defaultPseData = $combinationPseData = array();
// $prices = $salesElement->getProductPrices();
// Find product's sale elements
$saleElements = ProductSaleElementsQuery::create()
->filterByProduct($object)
->find();
foreach($saleElements as $saleElement) {
// Get the product price for the current currency
$productPrice = ProductPriceQuery::create()
->filterByCurrency($this->getCurrentEditionCurrency())
->filterByProductSaleElements($saleElement)
->findOne()
;
if ($productPrice == null) $productPrice = new ProductPrice();
$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(),
"use_exchange_rate" => $productPrice->getFromDefaultCurrency() ? 1 : 0,
"tax_rule" => $object->getTaxRuleId(),
"currency" => $productPrice->getCurrencyId(),
"weight" => $saleElement->getWeight(),
"quantity" => $saleElement->getQuantity(),
"sale_price" => $productPrice->getPromoPrice(),
"onsale" => $saleElement->getPromo() > 0 ? 1 : 0,
"isnew" => $saleElement->getNewness() > 0 ? 1 : 0,
"isdefault" => $saleElement->getIsDefault() > 0 ? 1 : 0,
"ean_code" => $saleElement->getEanCode()
);
}
else {
}
$defaultPseForm = new ProductDefaultSaleElementUpdateForm($this->getRequest(), "form", $defaultPseData);
$this->getParserContext()->addForm($defaultPseForm);
$combinationPseForm = new ProductSaleElementUpdateForm($this->getRequest(), "form", $combinationPseData);
$this->getParserContext()->addForm($combinationPseForm);
}
// Prepare the data that will hydrate the form
$data = array(
@@ -226,7 +291,7 @@ class ProductController extends AbstractCrudController
'product_id' => $this->getRequest()->get('product_id', 0),
'folder_id' => $this->getRequest()->get('folder_id', 0),
'accessory_category_id' => $this->getRequest()->get('accessory_category_id', 0),
'current_tab' => $this->getRequest()->get('current_tab', 'general')
'current_tab' => $this->getRequest()->get('current_tab', 'general')
);
}
@@ -730,20 +795,21 @@ class ProductController extends AbstractCrudController
/**
* A a new combination to a product
*/
public function addCombinationAction()
public function addProductSaleElementAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, AccessManager::UPDATE)) return $response;
$event = new ProductCreateCombinationEvent(
$event = new ProductSaleElementCreateEvent(
$this->getExistingObject(),
$this->getRequest()->get('combination_attributes', array()),
$this->getCurrentEditionCurrency()->getId()
);
try {
$this->dispatch(TheliaEvents::PRODUCT_ADD_COMBINATION, $event);
} catch (\Exception $ex) {
$this->dispatch(TheliaEvents::PRODUCT_ADD_PRODUCT_SALE_ELEMENT, $event);
}
catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
@@ -751,23 +817,23 @@ class ProductController extends AbstractCrudController
$this->redirectToEditionTemplate();
}
/**
* A a new combination to a product
*/
public function deleteCombinationAction()
public function deleteProductSaleElementAction()
{
// Check current user authorization
if (null !== $response = $this->checkAuth($this->resourceCode, AccessManager::UPDATE)) return $response;
$event = new ProductDeleteCombinationEvent(
$this->getExistingObject(),
$this->getRequest()->get('product_sale_element_id',0)
$event = new ProductSaleElementDeleteEvent(
$this->getRequest()->get('product_sale_element_id',0),
$this->getCurrentEditionCurrency()->getId()
);
try {
$this->dispatch(TheliaEvents::PRODUCT_DELETE_COMBINATION, $event);
} catch (\Exception $ex) {
$this->dispatch(TheliaEvents::PRODUCT_DELETE_PRODUCT_SALE_ELEMENT, $event);
}
catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
@@ -775,4 +841,124 @@ class ProductController extends AbstractCrudController
$this->redirectToEditionTemplate();
}
/**
* Change a product sale element
*/
protected function processProductSaleElementUpdate($changeForm) {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
$error_msg = false;
try {
// Check the form against constraints violations
$form = $this->validateForm($changeForm, "POST");
// Get the form field values
$data = $form->getData();
$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'])
->setTaxrule($data['tax_rule'])
;
$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()));
}
// If we have to stay on the same page, do not redirect to the succesUrl, just redirect to the edit page again.
if ($this->getRequest()->get('save_mode') == 'stay') {
$this->redirectToEditionTemplate($this->getRequest());
}
// Redirect to the success URL
$this->redirect($changeForm->getSuccessUrl());
}
catch (FormValidationException $ex) {
// Form cannot be validated
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
}
catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
$this->setupFormErrorContext(
$this->getTranslator()->trans("ProductSaleElement modification"), $error_msg, $changeForm, $ex);
// At this point, the form has errors, and should be redisplayed.
return $this->renderEditionTemplate();
}
/**
* Change a product sale element attached to a combination
*/
public function updateProductSaleElementAction() {
return $this->processProductSaleElementUpdate(
new ProductSaleElementUpdateForm($this->getRequest())
);
}
/**
* Update default product sale element (not attached to any combination)
*/
public function updateProductDefaultSaleElementAction() {
return $this->processProductSaleElementUpdate(
new ProductDefaultSaleElementUpdateForm($this->getRequest())
);
}
public function priceCaclulator() {
$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));
$calc = new Calculator();
$calc->loadTaxRule(
TaxRuleQuery::create()->findPk($tax_rule),
Country::getShopLocation()
);
if ($action == 'to_tax') {
$return_price = $calc->getTaxedPrice($price);
}
else if ($action == 'from_tax') {
$return_price = $calc->getUntaxedPrice($price);
}
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));
}
}

View File

@@ -0,0 +1,93 @@
<?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

@@ -162,8 +162,12 @@ class BaseController extends ContainerAware
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors .= $this->getErrorMessages($child) . ', ';
$fieldName = $child->getConfig()->getOption('label', $child->getName());
$errors .= sprintf("[%s] %s, ", $fieldName, $this->getErrorMessages($child));
}
}
@@ -192,13 +196,15 @@ 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));
}
}
@@ -223,7 +229,8 @@ class BaseController extends ContainerAware
{
if ($form != null) {
$url = $form->getSuccessUrl();
} else {
}
else {
$url = $this->getRequest()->get("success_url");
}

View File

@@ -21,21 +21,24 @@
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Product;
namespace Thelia\Core\Event\ProductSaleElement;
use Thelia\Model\Product;
use Thelia\Core\Event\Product\ProductEvent;
class ProductCreateCombinationEvent extends ProductEvent
class ProductSaleElementCreateEvent extends ProductSaleElementEvent
{
protected $product;
protected $attribute_av_list;
protected $currency_id;
public function __construct(Product $product, $attribute_av_list, $currency_id)
{
parent::__construct($product);
parent::__construct();
$this->attribute_av_list = $attribute_av_list;
$this->currency_id = $currency_id;
$this->setAttributeAvList($attribute_av_list);
$this->setCurrencyId($currency_id);
$this->setProduct($product);
}
public function getAttributeAvList()
@@ -62,4 +65,15 @@ class ProductCreateCombinationEvent extends ProductEvent
return $this;
}
public function getProduct() {
return $this->product;
}
public function setProduct($product) {
$this->product = $product;
return $this;
}
}

View File

@@ -21,19 +21,21 @@
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\Product;
namespace Thelia\Core\Event\ProductSaleElement;
use Thelia\Model\Product;
use Thelia\Core\Event\Product\ProductEvent;
class ProductDeleteCombinationEvent extends ProductEvent
class ProductSaleElementDeleteEvent extends ProductSaleElementEvent
{
protected $product_sale_element_id;
protected $currency_id;
public function __construct(Product $product, $product_sale_element_id)
public function __construct($product_sale_element_id, $currency_id)
{
parent::__construct($product);
parent::__construct();
$this->product_sale_element_id = $product_sale_element_id;
$this->setCurrencyId($currency_id);
}
public function getProductSaleElementId()
@@ -44,5 +46,19 @@ class ProductDeleteCombinationEvent extends ProductEvent
public function setProductSaleElementId($product_sale_element_id)
{
$this->product_sale_element_id = $product_sale_element_id;
return $this;
}
public function getCurrencyId()
{
return $this->currency_id;
}
public function setCurrencyId($currency_id)
{
$this->currency_id = $currency_id;
return $this;
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\ProductSaleElement;
use Thelia\Model\ProductSaleElement;
use Thelia\Core\Event\ActionEvent;
class ProductSaleElementEvent extends ActionEvent
{
public $product_sale_element = null;
public function __construct(ProductSaleElement $product_sale_element = null)
{
$this->product_sale_element = $product_sale_element;
}
public function hasProductSaleElement()
{
return ! is_null($this->product_sale_element);
}
public function getProductSaleElement()
{
return $this->product_sale_element;
}
public function setProductSaleElement(ProductSaleElement $product_sale_element)
{
$this->product_sale_element = $product_sale_element;
return $this;
}
}

View File

@@ -0,0 +1,211 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event\ProductSaleElement;
use Thelia\Core\Event\Product\ProductCreateEvent;
use Thelia\Model\Product;
use Thelia\Core\Event\Product\ProductEvent;
class ProductSaleElementUpdateEvent extends ProductSaleElementEvent
{
protected $product_sale_element_id;
protected $product;
protected $reference;
protected $price;
protected $currency_id;
protected $weight;
protected $quantity;
protected $sale_price;
protected $onsale;
protected $isnew;
protected $isdefault;
protected $ean_code;
protected $taxrule;
public function __construct(Product $product, $product_sale_element_id)
{
parent::__construct();
$this->setProduct($product);
$this->setProductSaleElementId($product_sale_element_id);
}
public function getProductSaleElementId()
{
return $this->product_sale_element_id;
}
public function setProductSaleElementId($product_sale_element_id)
{
$this->product_sale_element_id = $product_sale_element_id;
return $this;
}
public function getPrice()
{
return $this->price;
}
public function setPrice($price)
{
$this->price = $price;
return $this;
}
public function getCurrencyId()
{
return $this->currency_id;
}
public function setCurrencyId($currency_id)
{
$this->currency_id = $currency_id;
return $this;
}
public function getWeight()
{
return $this->weight;
}
public function setWeight($weight)
{
$this->weight = $weight;
return $this;
}
public function getQuantity()
{
return $this->quantity;
}
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
public function getSalePrice()
{
return $this->sale_price;
}
public function setSalePrice($sale_price)
{
$this->sale_price = $sale_price;
return $this;
}
public function getOnsale()
{
return $this->onsale;
}
public function setOnsale($onsale)
{
$this->onsale = $onsale;
return $this;
}
public function getIsnew()
{
return $this->isnew;
}
public function setIsnew($isnew)
{
$this->isnew = $isnew;
return $this;
}
public function getEanCode()
{
return $this->ean_code;
}
public function setEanCode($ean_code)
{
$this->ean_code = $ean_code;
return $this;
}
public function getIsdefault()
{
return $this->isdefault;
}
public function setIsdefault($isdefault)
{
$this->isdefault = $isdefault;
return $this;
}
public function getReference()
{
return $this->reference;
}
public function setReference($reference)
{
$this->reference = $reference;
return $this;
}
public function getProduct()
{
return $this->product;
}
public function setProduct($product)
{
$this->product = $product;
return $this;
}
public function getTaxrule()
{
return $this->taxrule;
}
public function setTaxrule($taxrule)
{
$this->taxrule = $taxrule;
return $this;
}
}

View File

@@ -255,14 +255,14 @@ final class TheliaEvents
// -- Categories Associated Content ----------------------------------------
const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent";
const AFTER_CREATECATEGORY_ASSOCIATED_CONTENT = "action.after_createCategoryAssociatedContent";
const BEFORE_CREATECATEGORY_ASSOCIATED_CONTENT = "action.before_createCategoryAssociatedContent";
const AFTER_CREATECATEGORY_ASSOCIATED_CONTENT = "action.after_createCategoryAssociatedContent";
const BEFORE_DELETECATEGORY_ASSOCIATED_CONTENT = "action.before_deleteCategoryAssociatedContent";
const AFTER_DELETECATEGORY_ASSOCIATED_CONTENT = "action.after_deleteCategoryAssociatedContent";
const BEFORE_DELETECATEGORY_ASSOCIATED_CONTENT = "action.before_deleteCategoryAssociatedContent";
const AFTER_DELETECATEGORY_ASSOCIATED_CONTENT = "action.after_deleteCategoryAssociatedContent";
const BEFORE_UPDATECATEGORY_ASSOCIATED_CONTENT = "action.before_updateCategoryAssociatedContent";
const AFTER_UPDATECATEGORY_ASSOCIATED_CONTENT = "action.after_updateCategoryAssociatedContent";
const BEFORE_UPDATECATEGORY_ASSOCIATED_CONTENT = "action.before_updateCategoryAssociatedContent";
const AFTER_UPDATECATEGORY_ASSOCIATED_CONTENT = "action.after_updateCategoryAssociatedContent";
// -- Product management -----------------------------------------------
@@ -276,8 +276,9 @@ final class TheliaEvents
const PRODUCT_REMOVE_CONTENT = "action.productRemoveContent";
const PRODUCT_UPDATE_CONTENT_POSITION = "action.updateProductContentPosition";
const PRODUCT_ADD_COMBINATION = "action.productAddCombination";
const PRODUCT_DELETE_COMBINATION = "action.productDeleteCombination";
const PRODUCT_ADD_PRODUCT_SALE_ELEMENT = "action.addProductSaleElement";
const PRODUCT_DELETE_PRODUCT_SALE_ELEMENT = "action.deleteProductSaleElement";
const PRODUCT_UPDATE_PRODUCT_SALE_ELEMENT = "action.updateProductSaleElement";
const PRODUCT_SET_TEMPLATE = "action.productSetTemplate";

View File

@@ -113,13 +113,13 @@ class Country extends BaseI18nLoop
->set("CHAPO", $country->getVirtualColumn('i18n_CHAPO'))
->set("DESCRIPTION", $country->getVirtualColumn('i18n_DESCRIPTION'))
->set("POSTSCRIPTUM", $country->getVirtualColumn('i18n_POSTSCRIPTUM'))
->set("IS_DEFAULT", $country->getByDefault() === 1 ? "1" : "0")
->set("ISOCODE", $country->getIsocode())
->set("ISOALPHA2", $country->getIsoalpha2())
->set("ISOALPHA3", $country->getIsoalpha3())
->set('IS_DEFAULT', $country->getByDefault())
->set("IS_DEFAULT", $country->getByDefault() ? "1" : "0")
->set("IS_SHOP_COUNTRY", $country->getShopCountry() ? "1" : "0")
;
;
$loopResult->addRow($loopResultRow);
}

View File

@@ -108,6 +108,7 @@ class OrderProduct extends BaseLoop
->set("TAX_RULE_TITLE", $product->getTaxRuleTitle())
->set("TAX_RULE_DESCRIPTION", $product->getTaxRuledescription())
->set("PARENT", $product->getParent())
->set("EAN_CODE", $product->getEanCode())
;
$loopResult->addRow($loopResultRow);

View File

@@ -177,6 +177,7 @@ class ProductSaleElements extends BaseLoop
->set("IS_NEW" , $PSEValue->getNewness() === 1 ? 1 : 0)
->set("IS_DEFAULT" , $PSEValue->getIsDefault() === 1 ? 1 : 0)
->set("WEIGHT" , $PSEValue->getWeight())
->set("EAN_CODE" , $PSEValue->getEanCode())
->set("PRICE" , $price)
->set("PRICE_TAX" , $taxedPrice - $price)
->set("TAXED_PRICE" , $taxedPrice)

View File

@@ -22,9 +22,6 @@
/*************************************************************************************/
namespace Thelia\Core\Template\Smarty\Plugins;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
use Symfony\Component\Form\FormView;
use Thelia\Core\Form\Type\TheliaType;
use Thelia\Form\BaseForm;
@@ -33,6 +30,9 @@ use Symfony\Component\HttpFoundation\Request;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\ParserContext;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
/**
*
@@ -78,8 +78,8 @@ class Form extends AbstractSmartyPlugin
{
foreach ($formDefinition as $name => $className) {
if (array_key_exists($name, $this->formDefinition)) {
throw new \InvalidArgumentException(sprintf("%s form name already exists for %s class", $name,
$className));
throw new \InvalidArgumentException(
sprintf("%s form name already exists for %s class", $name, $className));
}
$this->formDefinition[$name] = $className;
@@ -113,7 +113,8 @@ class Form extends AbstractSmartyPlugin
$template->assign("form_error", $instance->hasError() ? true : false);
$template->assign("form_error_message", $instance->getErrorMessage());
} else {
}
else {
return $content;
}
}
@@ -139,7 +140,7 @@ class Form extends AbstractSmartyPlugin
$template->assign("error", empty($errors) ? false : true);
if (! empty($errors)) {
if (!empty($errors)) {
$this->assignFieldErrorVars($template, $errors);
}
@@ -205,30 +206,37 @@ class Form extends AbstractSmartyPlugin
$this->assignFormTypeValues($template, $formFieldConfig, $formFieldView);
$value = $formFieldView->vars["value"];
/* FIXME: doesnt work. We got "This form should not contain extra fields." error.
// We have a collection
if (is_array($value)) {
$key = $this->getParam($params, 'value_key');
// We have a collection
if (count($formFieldView->children) > 0) {
if ($key != null) {
$key = $this->getParam($params, 'value_key');
if (isset($value[$key])) {
if ($key != null) {
$name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $key);
$val = $value[$key];
if (isset($value[$key])) {
$this->assignFieldValues($template, $name, $val, $formFieldView->vars);
}
}
} else {
$this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVars["value"], $formFieldView->vars);
}
*/
$this->assignFieldValues($template, $formFieldView->vars["full_name"], $formFieldView->vars["value"], $formFieldView->vars);
$name = sprintf("%s[%s]", $formFieldView->vars["full_name"], $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 {
throw new \InvalidArgumentException(sprintf("Missing or empty parameter 'value_key' for field '%s'", $formFieldView->vars["name"]));
}
}
else {
$this->assignFieldValues($template, $formFieldView->vars["full_name"], $formFieldView->vars["value"], $formFieldView->vars);
}
$formFieldView->setRendered();
} else {
}
else {
return $content;
}
}
@@ -300,7 +308,7 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar
$formView = $instance->getView();
if ($formView->vars["multipart"]) {
return sprintf('%s="%s"',"enctype", "multipart/form-data");
return sprintf('%s="%s"', "enctype", "multipart/form-data");
}
}
@@ -316,7 +324,8 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar
if ($repeat) {
$this->assignFieldErrorVars($template, $errors);
} else {
}
else {
return $content;
}
}
@@ -339,11 +348,10 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar
$fieldName = $this->getParam($params, 'field');
if (null == $fieldName)
throw new \InvalidArgumentException("'field' parameter is missing");
if (null == $fieldName) throw new \InvalidArgumentException("'field' parameter is missing");
if (empty($instance->getView()[$fieldName]))
throw new \InvalidArgumentException(sprintf("Field name '%s' not found in form %s", $fieldName, $instance->getName()));
if (empty($instance->getView()[$fieldName])) throw new \InvalidArgumentException(
sprintf("Field name '%s' not found in form %s", $fieldName, $instance->getName()));
return $instance->getView()[$fieldName];
}
@@ -398,8 +406,10 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar
throw new \InvalidArgumentException("Missing 'form' parameter in form arguments");
}
if (! $instance instanceof \Thelia\Form\BaseForm) {
throw new \InvalidArgumentException(sprintf("form parameter in form_field block must be an instance of
if (!$instance instanceof \Thelia\Form\BaseForm) {
throw new \InvalidArgumentException(
sprintf(
"form parameter in form_field block must be an instance of
\Thelia\Form\BaseForm, instance of %s found", get_class($instance)));
}
@@ -414,10 +424,7 @@ $this->assignFieldValues($template, $formFieldView->vars["full_name"], $fieldVar
$class = new \ReflectionClass($this->formDefinition[$name]);
return $class->newInstance(
$this->request,
"form"
);
return $class->newInstance($this->request, "form");
}
/**

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\Smarty\Exception\SmartyPluginException;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Tools\DateTimeFormat;
use Thelia\Tools\NumberFormat;
/**
*
@@ -69,21 +70,20 @@ class Format extends AbstractSmartyPlugin
*/
public function formatDate($params, $template = null)
{
$date = $this->getParam($params, "date", false);
if (array_key_exists("date", $params) === false) {
if ($date === false) {
throw new SmartyPluginException("date is a mandatory parameter in format_date function");
}
$date = $params["date"];
if (!$date instanceof \DateTime) {
return "";
}
if (array_key_exists("format", $params)) {
$format = $params["format"];
} else {
$format = DateTimeFormat::getInstance($this->request)->getFormat(array_key_exists("output", $params) ? $params["output"] : null);
$format = $this->getParam($params, "format", false);
if ($format === false) {
$format = DateTimeFormat::getInstance($this->request)->getFormat($this->getParam($params, "output", null));
}
return $date->format($format);
@@ -109,23 +109,22 @@ class Format extends AbstractSmartyPlugin
*/
public function formatNumber($params, $template = null)
{
if (array_key_exists("number", $params) === false) {
$number = $this->getParam($params, "number", false);
if ($number === false) {
throw new SmartyPluginException("number is a mandatory parameter in format_number function");
}
$number = $params["number"];
if (empty($number)) {
if ($number == '') {
return "";
}
$lang = $this->request->getSession()->getLang();
$decimals = array_key_exists("decimals", $params) ? $params["decimals"] : $lang->getDecimals();
$decPoint = array_key_exists("dec_point", $params) ? $params["dec_point"] : $lang->getDecimalSeparator();
$thousandsSep = array_key_exists("thousands_sep", $params) ? $params["thousands_sep"] : $lang->getThousandsSeparator();
return number_format($number, $decimals, $decPoint, $thousandsSep);
return NumberFormat::getInstance($this->request)->format(
$number,
$this->getParam($params, "decimals", null),
$this->getParam($params, "dec_point", null),
$this->getParam($params, "thousands_sep", null)
);
}
/**

View File

@@ -0,0 +1,31 @@
<?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\Form;
class ProductDefaultSaleElementUpdateForm extends ProductSaleElementUpdateForm
{
public function getName()
{
return "thelia_product_default_sale_element_update_form";
}
}

View File

@@ -25,28 +25,33 @@ namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Core\Translation\Translator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Model\Currency;
class ProductDetailsModificationForm extends BaseForm
class ProductSaleElementUpdateForm extends BaseForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->formBuilder
->add("id", "integer", array(
"label" => Translator::getInstance()->trans("Prodcut ID *"),
"label_attr" => array("for" => "product_id_field"),
"constraints" => array(new GreaterThan(array('value' => 0)))
->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 base price excluding taxes *"),
"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 base 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 *"),
@@ -64,11 +69,11 @@ class ProductDetailsModificationForm extends BaseForm
))
->add("quantity", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Current quantity *"),
"label" => Translator::getInstance()->trans("Available quantity *"),
"label_attr" => array("for" => "quantity_field")
))
->add("sale_price", "number", array(
"label" => Translator::getInstance()->trans("Sale price *"),
"label" => Translator::getInstance()->trans("Sale price without taxes *"),
"label_attr" => array("for" => "price_with_tax_field")
))
->add("onsale", "integer", array(
@@ -79,12 +84,23 @@ class ProductDetailsModificationForm extends BaseForm
"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")
))
->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_details_modification";
return "thelia_product_sale_element_update_form";
}
}

View File

@@ -95,10 +95,18 @@ abstract class Country implements ActiveRecordInterface
/**
* The value for the by_default field.
* Note: this column has a database default value of: 0
* @var int
*/
protected $by_default;
/**
* The value for the shop_country field.
* Note: this column has a database default value of: false
* @var boolean
*/
protected $shop_country;
/**
* The value for the created_at field.
* @var string
@@ -174,11 +182,25 @@ abstract class Country implements ActiveRecordInterface
*/
protected $countryI18nsScheduledForDeletion = null;
/**
* Applies default values to this object.
* This method should be called from the object's constructor (or
* equivalent initialization method).
* @see __construct()
*/
public function applyDefaultValues()
{
$this->by_default = 0;
$this->shop_country = false;
}
/**
* Initializes internal state of Thelia\Model\Base\Country object.
* @see applyDefaults()
*/
public function __construct()
{
$this->applyDefaultValues();
}
/**
@@ -498,6 +520,17 @@ abstract class Country implements ActiveRecordInterface
return $this->by_default;
}
/**
* Get the [shop_country] column value.
*
* @return boolean
*/
public function getShopCountry()
{
return $this->shop_country;
}
/**
* Get the [optionally formatted] temporal [created_at] column value.
*
@@ -668,6 +701,35 @@ abstract class Country implements ActiveRecordInterface
return $this;
} // setByDefault()
/**
* Sets the value of the [shop_country] column.
* Non-boolean arguments are converted using the following rules:
* * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
* * 0, '0', 'false', 'off', and 'no' are converted to boolean false
* Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
*
* @param boolean|integer|string $v The new value
* @return \Thelia\Model\Country The current object (for fluent API support)
*/
public function setShopCountry($v)
{
if ($v !== null) {
if (is_string($v)) {
$v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
} else {
$v = (boolean) $v;
}
}
if ($this->shop_country !== $v) {
$this->shop_country = $v;
$this->modifiedColumns[] = CountryTableMap::SHOP_COUNTRY;
}
return $this;
} // setShopCountry()
/**
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
*
@@ -720,6 +782,14 @@ abstract class Country implements ActiveRecordInterface
*/
public function hasOnlyDefaultValues()
{
if ($this->by_default !== 0) {
return false;
}
if ($this->shop_country !== false) {
return false;
}
// otherwise, everything was equal, so return TRUE
return true;
} // hasOnlyDefaultValues()
@@ -765,13 +835,16 @@ abstract class Country implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : CountryTableMap::translateFieldName('ByDefault', TableMap::TYPE_PHPNAME, $indexType)];
$this->by_default = (null !== $col) ? (int) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CountryTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : CountryTableMap::translateFieldName('ShopCountry', TableMap::TYPE_PHPNAME, $indexType)];
$this->shop_country = (null !== $col) ? (boolean) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : CountryTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 7 + $startcol : CountryTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 8 + $startcol : CountryTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
@@ -784,7 +857,7 @@ abstract class Country implements ActiveRecordInterface
$this->ensureConsistency();
}
return $startcol + 8; // 8 = CountryTableMap::NUM_HYDRATE_COLUMNS.
return $startcol + 9; // 9 = CountryTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating \Thelia\Model\Country object", 0, $e);
@@ -1095,6 +1168,9 @@ abstract class Country implements ActiveRecordInterface
if ($this->isColumnModified(CountryTableMap::BY_DEFAULT)) {
$modifiedColumns[':p' . $index++] = 'BY_DEFAULT';
}
if ($this->isColumnModified(CountryTableMap::SHOP_COUNTRY)) {
$modifiedColumns[':p' . $index++] = 'SHOP_COUNTRY';
}
if ($this->isColumnModified(CountryTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
}
@@ -1130,6 +1206,9 @@ abstract class Country implements ActiveRecordInterface
case 'BY_DEFAULT':
$stmt->bindValue($identifier, $this->by_default, PDO::PARAM_INT);
break;
case 'SHOP_COUNTRY':
$stmt->bindValue($identifier, (int) $this->shop_country, PDO::PARAM_INT);
break;
case 'CREATED_AT':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
@@ -1217,9 +1296,12 @@ abstract class Country implements ActiveRecordInterface
return $this->getByDefault();
break;
case 6:
return $this->getCreatedAt();
return $this->getShopCountry();
break;
case 7:
return $this->getCreatedAt();
break;
case 8:
return $this->getUpdatedAt();
break;
default:
@@ -1257,8 +1339,9 @@ abstract class Country implements ActiveRecordInterface
$keys[3] => $this->getIsoalpha2(),
$keys[4] => $this->getIsoalpha3(),
$keys[5] => $this->getByDefault(),
$keys[6] => $this->getCreatedAt(),
$keys[7] => $this->getUpdatedAt(),
$keys[6] => $this->getShopCountry(),
$keys[7] => $this->getCreatedAt(),
$keys[8] => $this->getUpdatedAt(),
);
$virtualColumns = $this->virtualColumns;
foreach ($virtualColumns as $key => $virtualColumn) {
@@ -1331,9 +1414,12 @@ abstract class Country implements ActiveRecordInterface
$this->setByDefault($value);
break;
case 6:
$this->setCreatedAt($value);
$this->setShopCountry($value);
break;
case 7:
$this->setCreatedAt($value);
break;
case 8:
$this->setUpdatedAt($value);
break;
} // switch()
@@ -1366,8 +1452,9 @@ abstract class Country implements ActiveRecordInterface
if (array_key_exists($keys[3], $arr)) $this->setIsoalpha2($arr[$keys[3]]);
if (array_key_exists($keys[4], $arr)) $this->setIsoalpha3($arr[$keys[4]]);
if (array_key_exists($keys[5], $arr)) $this->setByDefault($arr[$keys[5]]);
if (array_key_exists($keys[6], $arr)) $this->setCreatedAt($arr[$keys[6]]);
if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]);
if (array_key_exists($keys[6], $arr)) $this->setShopCountry($arr[$keys[6]]);
if (array_key_exists($keys[7], $arr)) $this->setCreatedAt($arr[$keys[7]]);
if (array_key_exists($keys[8], $arr)) $this->setUpdatedAt($arr[$keys[8]]);
}
/**
@@ -1385,6 +1472,7 @@ abstract class Country implements ActiveRecordInterface
if ($this->isColumnModified(CountryTableMap::ISOALPHA2)) $criteria->add(CountryTableMap::ISOALPHA2, $this->isoalpha2);
if ($this->isColumnModified(CountryTableMap::ISOALPHA3)) $criteria->add(CountryTableMap::ISOALPHA3, $this->isoalpha3);
if ($this->isColumnModified(CountryTableMap::BY_DEFAULT)) $criteria->add(CountryTableMap::BY_DEFAULT, $this->by_default);
if ($this->isColumnModified(CountryTableMap::SHOP_COUNTRY)) $criteria->add(CountryTableMap::SHOP_COUNTRY, $this->shop_country);
if ($this->isColumnModified(CountryTableMap::CREATED_AT)) $criteria->add(CountryTableMap::CREATED_AT, $this->created_at);
if ($this->isColumnModified(CountryTableMap::UPDATED_AT)) $criteria->add(CountryTableMap::UPDATED_AT, $this->updated_at);
@@ -1455,6 +1543,7 @@ abstract class Country implements ActiveRecordInterface
$copyObj->setIsoalpha2($this->getIsoalpha2());
$copyObj->setIsoalpha3($this->getIsoalpha3());
$copyObj->setByDefault($this->getByDefault());
$copyObj->setShopCountry($this->getShopCountry());
$copyObj->setCreatedAt($this->getCreatedAt());
$copyObj->setUpdatedAt($this->getUpdatedAt());
@@ -2359,10 +2448,12 @@ abstract class Country implements ActiveRecordInterface
$this->isoalpha2 = null;
$this->isoalpha3 = null;
$this->by_default = null;
$this->shop_country = null;
$this->created_at = null;
$this->updated_at = null;
$this->alreadyInSave = false;
$this->clearAllReferences();
$this->applyDefaultValues();
$this->resetModified();
$this->setNew(true);
$this->setDeleted(false);

View File

@@ -28,6 +28,7 @@ use Thelia\Model\Map\CountryTableMap;
* @method ChildCountryQuery orderByIsoalpha2($order = Criteria::ASC) Order by the isoalpha2 column
* @method ChildCountryQuery orderByIsoalpha3($order = Criteria::ASC) Order by the isoalpha3 column
* @method ChildCountryQuery orderByByDefault($order = Criteria::ASC) Order by the by_default column
* @method ChildCountryQuery orderByShopCountry($order = Criteria::ASC) Order by the shop_country column
* @method ChildCountryQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildCountryQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
@@ -37,6 +38,7 @@ use Thelia\Model\Map\CountryTableMap;
* @method ChildCountryQuery groupByIsoalpha2() Group by the isoalpha2 column
* @method ChildCountryQuery groupByIsoalpha3() Group by the isoalpha3 column
* @method ChildCountryQuery groupByByDefault() Group by the by_default column
* @method ChildCountryQuery groupByShopCountry() Group by the shop_country column
* @method ChildCountryQuery groupByCreatedAt() Group by the created_at column
* @method ChildCountryQuery groupByUpdatedAt() Group by the updated_at column
*
@@ -69,6 +71,7 @@ use Thelia\Model\Map\CountryTableMap;
* @method ChildCountry findOneByIsoalpha2(string $isoalpha2) Return the first ChildCountry filtered by the isoalpha2 column
* @method ChildCountry findOneByIsoalpha3(string $isoalpha3) Return the first ChildCountry filtered by the isoalpha3 column
* @method ChildCountry findOneByByDefault(int $by_default) Return the first ChildCountry filtered by the by_default column
* @method ChildCountry findOneByShopCountry(boolean $shop_country) Return the first ChildCountry filtered by the shop_country column
* @method ChildCountry findOneByCreatedAt(string $created_at) Return the first ChildCountry filtered by the created_at column
* @method ChildCountry findOneByUpdatedAt(string $updated_at) Return the first ChildCountry filtered by the updated_at column
*
@@ -78,6 +81,7 @@ use Thelia\Model\Map\CountryTableMap;
* @method array findByIsoalpha2(string $isoalpha2) Return ChildCountry objects filtered by the isoalpha2 column
* @method array findByIsoalpha3(string $isoalpha3) Return ChildCountry objects filtered by the isoalpha3 column
* @method array findByByDefault(int $by_default) Return ChildCountry objects filtered by the by_default column
* @method array findByShopCountry(boolean $shop_country) Return ChildCountry objects filtered by the shop_country column
* @method array findByCreatedAt(string $created_at) Return ChildCountry objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildCountry objects filtered by the updated_at column
*
@@ -168,7 +172,7 @@ abstract class CountryQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT ID, AREA_ID, ISOCODE, ISOALPHA2, ISOALPHA3, BY_DEFAULT, CREATED_AT, UPDATED_AT FROM country WHERE ID = :p0';
$sql = 'SELECT ID, AREA_ID, ISOCODE, ISOALPHA2, ISOALPHA3, BY_DEFAULT, SHOP_COUNTRY, CREATED_AT, UPDATED_AT FROM country WHERE ID = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@@ -469,6 +473,33 @@ abstract class CountryQuery extends ModelCriteria
return $this->addUsingAlias(CountryTableMap::BY_DEFAULT, $byDefault, $comparison);
}
/**
* Filter the query on the shop_country column
*
* Example usage:
* <code>
* $query->filterByShopCountry(true); // WHERE shop_country = true
* $query->filterByShopCountry('yes'); // WHERE shop_country = true
* </code>
*
* @param boolean|string $shopCountry The value to use as filter.
* Non-boolean arguments are converted using the following rules:
* * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
* * 0, '0', 'false', 'off', and 'no' are converted to boolean false
* Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildCountryQuery The current query, for fluid interface
*/
public function filterByShopCountry($shopCountry = null, $comparison = null)
{
if (is_string($shopCountry)) {
$shop_country = in_array(strtolower($shopCountry), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
}
return $this->addUsingAlias(CountryTableMap::SHOP_COUNTRY, $shopCountry, $comparison);
}
/**
* Filter the query on the created_at column
*

View File

@@ -82,6 +82,13 @@ abstract class ProductPrice implements ActiveRecordInterface
*/
protected $promo_price;
/**
* The value for the from_default_currency field.
* Note: this column has a database default value of: false
* @var boolean
*/
protected $from_default_currency;
/**
* The value for the created_at field.
* @var string
@@ -112,11 +119,24 @@ abstract class ProductPrice implements ActiveRecordInterface
*/
protected $alreadyInSave = false;
/**
* Applies default values to this object.
* This method should be called from the object's constructor (or
* equivalent initialization method).
* @see __construct()
*/
public function applyDefaultValues()
{
$this->from_default_currency = false;
}
/**
* Initializes internal state of Thelia\Model\Base\ProductPrice object.
* @see applyDefaults()
*/
public function __construct()
{
$this->applyDefaultValues();
}
/**
@@ -414,6 +434,17 @@ abstract class ProductPrice implements ActiveRecordInterface
return $this->promo_price;
}
/**
* Get the [from_default_currency] column value.
*
* @return boolean
*/
public function getFromDefaultCurrency()
{
return $this->from_default_currency;
}
/**
* Get the [optionally formatted] temporal [created_at] column value.
*
@@ -546,6 +577,35 @@ abstract class ProductPrice implements ActiveRecordInterface
return $this;
} // setPromoPrice()
/**
* Sets the value of the [from_default_currency] column.
* Non-boolean arguments are converted using the following rules:
* * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
* * 0, '0', 'false', 'off', and 'no' are converted to boolean false
* Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
*
* @param boolean|integer|string $v The new value
* @return \Thelia\Model\ProductPrice The current object (for fluent API support)
*/
public function setFromDefaultCurrency($v)
{
if ($v !== null) {
if (is_string($v)) {
$v = in_array(strtolower($v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
} else {
$v = (boolean) $v;
}
}
if ($this->from_default_currency !== $v) {
$this->from_default_currency = $v;
$this->modifiedColumns[] = ProductPriceTableMap::FROM_DEFAULT_CURRENCY;
}
return $this;
} // setFromDefaultCurrency()
/**
* Sets the value of [created_at] column to a normalized version of the date/time value specified.
*
@@ -598,6 +658,10 @@ abstract class ProductPrice implements ActiveRecordInterface
*/
public function hasOnlyDefaultValues()
{
if ($this->from_default_currency !== false) {
return false;
}
// otherwise, everything was equal, so return TRUE
return true;
} // hasOnlyDefaultValues()
@@ -637,13 +701,16 @@ abstract class ProductPrice implements ActiveRecordInterface
$col = $row[TableMap::TYPE_NUM == $indexType ? 3 + $startcol : ProductPriceTableMap::translateFieldName('PromoPrice', TableMap::TYPE_PHPNAME, $indexType)];
$this->promo_price = (null !== $col) ? (double) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ProductPriceTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 4 + $startcol : ProductPriceTableMap::translateFieldName('FromDefaultCurrency', TableMap::TYPE_PHPNAME, $indexType)];
$this->from_default_currency = (null !== $col) ? (boolean) $col : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ProductPriceTableMap::translateFieldName('CreatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
$this->created_at = (null !== $col) ? PropelDateTime::newInstance($col, null, '\DateTime') : null;
$col = $row[TableMap::TYPE_NUM == $indexType ? 5 + $startcol : ProductPriceTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
$col = $row[TableMap::TYPE_NUM == $indexType ? 6 + $startcol : ProductPriceTableMap::translateFieldName('UpdatedAt', TableMap::TYPE_PHPNAME, $indexType)];
if ($col === '0000-00-00 00:00:00') {
$col = null;
}
@@ -656,7 +723,7 @@ abstract class ProductPrice implements ActiveRecordInterface
$this->ensureConsistency();
}
return $startcol + 6; // 6 = ProductPriceTableMap::NUM_HYDRATE_COLUMNS.
return $startcol + 7; // 7 = ProductPriceTableMap::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating \Thelia\Model\ProductPrice object", 0, $e);
@@ -911,6 +978,9 @@ abstract class ProductPrice implements ActiveRecordInterface
if ($this->isColumnModified(ProductPriceTableMap::PROMO_PRICE)) {
$modifiedColumns[':p' . $index++] = 'PROMO_PRICE';
}
if ($this->isColumnModified(ProductPriceTableMap::FROM_DEFAULT_CURRENCY)) {
$modifiedColumns[':p' . $index++] = 'FROM_DEFAULT_CURRENCY';
}
if ($this->isColumnModified(ProductPriceTableMap::CREATED_AT)) {
$modifiedColumns[':p' . $index++] = 'CREATED_AT';
}
@@ -940,6 +1010,9 @@ abstract class ProductPrice implements ActiveRecordInterface
case 'PROMO_PRICE':
$stmt->bindValue($identifier, $this->promo_price, PDO::PARAM_STR);
break;
case 'FROM_DEFAULT_CURRENCY':
$stmt->bindValue($identifier, (int) $this->from_default_currency, PDO::PARAM_INT);
break;
case 'CREATED_AT':
$stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
break;
@@ -1014,9 +1087,12 @@ abstract class ProductPrice implements ActiveRecordInterface
return $this->getPromoPrice();
break;
case 4:
return $this->getCreatedAt();
return $this->getFromDefaultCurrency();
break;
case 5:
return $this->getCreatedAt();
break;
case 6:
return $this->getUpdatedAt();
break;
default:
@@ -1052,8 +1128,9 @@ abstract class ProductPrice implements ActiveRecordInterface
$keys[1] => $this->getCurrencyId(),
$keys[2] => $this->getPrice(),
$keys[3] => $this->getPromoPrice(),
$keys[4] => $this->getCreatedAt(),
$keys[5] => $this->getUpdatedAt(),
$keys[4] => $this->getFromDefaultCurrency(),
$keys[5] => $this->getCreatedAt(),
$keys[6] => $this->getUpdatedAt(),
);
$virtualColumns = $this->virtualColumns;
foreach ($virtualColumns as $key => $virtualColumn) {
@@ -1114,9 +1191,12 @@ abstract class ProductPrice implements ActiveRecordInterface
$this->setPromoPrice($value);
break;
case 4:
$this->setCreatedAt($value);
$this->setFromDefaultCurrency($value);
break;
case 5:
$this->setCreatedAt($value);
break;
case 6:
$this->setUpdatedAt($value);
break;
} // switch()
@@ -1147,8 +1227,9 @@ abstract class ProductPrice implements ActiveRecordInterface
if (array_key_exists($keys[1], $arr)) $this->setCurrencyId($arr[$keys[1]]);
if (array_key_exists($keys[2], $arr)) $this->setPrice($arr[$keys[2]]);
if (array_key_exists($keys[3], $arr)) $this->setPromoPrice($arr[$keys[3]]);
if (array_key_exists($keys[4], $arr)) $this->setCreatedAt($arr[$keys[4]]);
if (array_key_exists($keys[5], $arr)) $this->setUpdatedAt($arr[$keys[5]]);
if (array_key_exists($keys[4], $arr)) $this->setFromDefaultCurrency($arr[$keys[4]]);
if (array_key_exists($keys[5], $arr)) $this->setCreatedAt($arr[$keys[5]]);
if (array_key_exists($keys[6], $arr)) $this->setUpdatedAt($arr[$keys[6]]);
}
/**
@@ -1164,6 +1245,7 @@ abstract class ProductPrice implements ActiveRecordInterface
if ($this->isColumnModified(ProductPriceTableMap::CURRENCY_ID)) $criteria->add(ProductPriceTableMap::CURRENCY_ID, $this->currency_id);
if ($this->isColumnModified(ProductPriceTableMap::PRICE)) $criteria->add(ProductPriceTableMap::PRICE, $this->price);
if ($this->isColumnModified(ProductPriceTableMap::PROMO_PRICE)) $criteria->add(ProductPriceTableMap::PROMO_PRICE, $this->promo_price);
if ($this->isColumnModified(ProductPriceTableMap::FROM_DEFAULT_CURRENCY)) $criteria->add(ProductPriceTableMap::FROM_DEFAULT_CURRENCY, $this->from_default_currency);
if ($this->isColumnModified(ProductPriceTableMap::CREATED_AT)) $criteria->add(ProductPriceTableMap::CREATED_AT, $this->created_at);
if ($this->isColumnModified(ProductPriceTableMap::UPDATED_AT)) $criteria->add(ProductPriceTableMap::UPDATED_AT, $this->updated_at);
@@ -1240,6 +1322,7 @@ abstract class ProductPrice implements ActiveRecordInterface
$copyObj->setCurrencyId($this->getCurrencyId());
$copyObj->setPrice($this->getPrice());
$copyObj->setPromoPrice($this->getPromoPrice());
$copyObj->setFromDefaultCurrency($this->getFromDefaultCurrency());
$copyObj->setCreatedAt($this->getCreatedAt());
$copyObj->setUpdatedAt($this->getUpdatedAt());
if ($makeNew) {
@@ -1380,10 +1463,12 @@ abstract class ProductPrice implements ActiveRecordInterface
$this->currency_id = null;
$this->price = null;
$this->promo_price = null;
$this->from_default_currency = null;
$this->created_at = null;
$this->updated_at = null;
$this->alreadyInSave = false;
$this->clearAllReferences();
$this->applyDefaultValues();
$this->resetModified();
$this->setNew(true);
$this->setDeleted(false);

View File

@@ -25,6 +25,7 @@ use Thelia\Model\Map\ProductPriceTableMap;
* @method ChildProductPriceQuery orderByCurrencyId($order = Criteria::ASC) Order by the currency_id column
* @method ChildProductPriceQuery orderByPrice($order = Criteria::ASC) Order by the price column
* @method ChildProductPriceQuery orderByPromoPrice($order = Criteria::ASC) Order by the promo_price column
* @method ChildProductPriceQuery orderByFromDefaultCurrency($order = Criteria::ASC) Order by the from_default_currency column
* @method ChildProductPriceQuery orderByCreatedAt($order = Criteria::ASC) Order by the created_at column
* @method ChildProductPriceQuery orderByUpdatedAt($order = Criteria::ASC) Order by the updated_at column
*
@@ -32,6 +33,7 @@ use Thelia\Model\Map\ProductPriceTableMap;
* @method ChildProductPriceQuery groupByCurrencyId() Group by the currency_id column
* @method ChildProductPriceQuery groupByPrice() Group by the price column
* @method ChildProductPriceQuery groupByPromoPrice() Group by the promo_price column
* @method ChildProductPriceQuery groupByFromDefaultCurrency() Group by the from_default_currency column
* @method ChildProductPriceQuery groupByCreatedAt() Group by the created_at column
* @method ChildProductPriceQuery groupByUpdatedAt() Group by the updated_at column
*
@@ -54,6 +56,7 @@ use Thelia\Model\Map\ProductPriceTableMap;
* @method ChildProductPrice findOneByCurrencyId(int $currency_id) Return the first ChildProductPrice filtered by the currency_id column
* @method ChildProductPrice findOneByPrice(double $price) Return the first ChildProductPrice filtered by the price column
* @method ChildProductPrice findOneByPromoPrice(double $promo_price) Return the first ChildProductPrice filtered by the promo_price column
* @method ChildProductPrice findOneByFromDefaultCurrency(boolean $from_default_currency) Return the first ChildProductPrice filtered by the from_default_currency column
* @method ChildProductPrice findOneByCreatedAt(string $created_at) Return the first ChildProductPrice filtered by the created_at column
* @method ChildProductPrice findOneByUpdatedAt(string $updated_at) Return the first ChildProductPrice filtered by the updated_at column
*
@@ -61,6 +64,7 @@ use Thelia\Model\Map\ProductPriceTableMap;
* @method array findByCurrencyId(int $currency_id) Return ChildProductPrice objects filtered by the currency_id column
* @method array findByPrice(double $price) Return ChildProductPrice objects filtered by the price column
* @method array findByPromoPrice(double $promo_price) Return ChildProductPrice objects filtered by the promo_price column
* @method array findByFromDefaultCurrency(boolean $from_default_currency) Return ChildProductPrice objects filtered by the from_default_currency column
* @method array findByCreatedAt(string $created_at) Return ChildProductPrice objects filtered by the created_at column
* @method array findByUpdatedAt(string $updated_at) Return ChildProductPrice objects filtered by the updated_at column
*
@@ -151,7 +155,7 @@ abstract class ProductPriceQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT PRODUCT_SALE_ELEMENTS_ID, CURRENCY_ID, PRICE, PROMO_PRICE, CREATED_AT, UPDATED_AT FROM product_price WHERE PRODUCT_SALE_ELEMENTS_ID = :p0 AND CURRENCY_ID = :p1';
$sql = 'SELECT PRODUCT_SALE_ELEMENTS_ID, CURRENCY_ID, PRICE, PROMO_PRICE, FROM_DEFAULT_CURRENCY, CREATED_AT, UPDATED_AT FROM product_price WHERE PRODUCT_SALE_ELEMENTS_ID = :p0 AND CURRENCY_ID = :p1';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);
@@ -420,6 +424,33 @@ abstract class ProductPriceQuery extends ModelCriteria
return $this->addUsingAlias(ProductPriceTableMap::PROMO_PRICE, $promoPrice, $comparison);
}
/**
* Filter the query on the from_default_currency column
*
* Example usage:
* <code>
* $query->filterByFromDefaultCurrency(true); // WHERE from_default_currency = true
* $query->filterByFromDefaultCurrency('yes'); // WHERE from_default_currency = true
* </code>
*
* @param boolean|string $fromDefaultCurrency The value to use as filter.
* Non-boolean arguments are converted using the following rules:
* * 1, '1', 'true', 'on', and 'yes' are converted to boolean true
* * 0, '0', 'false', 'off', and 'no' are converted to boolean false
* Check on string values is case insensitive (so 'FaLsE' is seen as 'false').
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return ChildProductPriceQuery The current query, for fluid interface
*/
public function filterByFromDefaultCurrency($fromDefaultCurrency = null, $comparison = null)
{
if (is_string($fromDefaultCurrency)) {
$from_default_currency = in_array(strtolower($fromDefaultCurrency), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
}
return $this->addUsingAlias(ProductPriceTableMap::FROM_DEFAULT_CURRENCY, $fromDefaultCurrency, $comparison);
}
/**
* Filter the query on the created_at column
*

View File

@@ -8,7 +8,9 @@ use Propel\Runtime\Propel;
use Thelia\Core\Event\Country\CountryEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Base\Country as BaseCountry;
use Thelia\Model\Map\CountryTableMap;
use Thelia\Core\Translation\Translator;
class Country extends BaseCountry
{
@@ -79,4 +81,31 @@ class Country extends BaseCountry
$this->dispatchEvent(TheliaEvents::AFTER_DELETECOUNTRY, new CountryEvent($this));
}
/**
* Return the default country
*
* @throws LogicException if no default country is defined
*/
public static function getDefaultCountry() {
$dc = CountryQuery::create()->findOneByByDefault(true);
if ($dc == null)
throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one."));
return $dc;
}
/**
* Return the shop country
*
* @throws LogicException if no shop country is defined
*/
public static function getShopLocation() {
$dc = CountryQuery::create()->findOneByShopCountry(true);
if ($dc == null)
throw new \LogicException(Translator::getInstance()->trans("Cannot find the shop country. Please select a shop country."));
return $dc;
}
}

View File

@@ -57,7 +57,7 @@ class CountryTableMap extends TableMap
/**
* The total number of columns
*/
const NUM_COLUMNS = 8;
const NUM_COLUMNS = 9;
/**
* The number of lazy-loaded columns
@@ -67,7 +67,7 @@ class CountryTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
const NUM_HYDRATE_COLUMNS = 8;
const NUM_HYDRATE_COLUMNS = 9;
/**
* the column name for the ID field
@@ -99,6 +99,11 @@ class CountryTableMap extends TableMap
*/
const BY_DEFAULT = 'country.BY_DEFAULT';
/**
* the column name for the SHOP_COUNTRY field
*/
const SHOP_COUNTRY = 'country.SHOP_COUNTRY';
/**
* the column name for the CREATED_AT field
*/
@@ -130,12 +135,12 @@ class CountryTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
self::TYPE_PHPNAME => array('Id', 'AreaId', 'Isocode', 'Isoalpha2', 'Isoalpha3', 'ByDefault', 'CreatedAt', 'UpdatedAt', ),
self::TYPE_STUDLYPHPNAME => array('id', 'areaId', 'isocode', 'isoalpha2', 'isoalpha3', 'byDefault', 'createdAt', 'updatedAt', ),
self::TYPE_COLNAME => array(CountryTableMap::ID, CountryTableMap::AREA_ID, CountryTableMap::ISOCODE, CountryTableMap::ISOALPHA2, CountryTableMap::ISOALPHA3, CountryTableMap::BY_DEFAULT, CountryTableMap::CREATED_AT, CountryTableMap::UPDATED_AT, ),
self::TYPE_RAW_COLNAME => array('ID', 'AREA_ID', 'ISOCODE', 'ISOALPHA2', 'ISOALPHA3', 'BY_DEFAULT', 'CREATED_AT', 'UPDATED_AT', ),
self::TYPE_FIELDNAME => array('id', 'area_id', 'isocode', 'isoalpha2', 'isoalpha3', 'by_default', 'created_at', 'updated_at', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, )
self::TYPE_PHPNAME => array('Id', 'AreaId', 'Isocode', 'Isoalpha2', 'Isoalpha3', 'ByDefault', 'ShopCountry', 'CreatedAt', 'UpdatedAt', ),
self::TYPE_STUDLYPHPNAME => array('id', 'areaId', 'isocode', 'isoalpha2', 'isoalpha3', 'byDefault', 'shopCountry', 'createdAt', 'updatedAt', ),
self::TYPE_COLNAME => array(CountryTableMap::ID, CountryTableMap::AREA_ID, CountryTableMap::ISOCODE, CountryTableMap::ISOALPHA2, CountryTableMap::ISOALPHA3, CountryTableMap::BY_DEFAULT, CountryTableMap::SHOP_COUNTRY, CountryTableMap::CREATED_AT, CountryTableMap::UPDATED_AT, ),
self::TYPE_RAW_COLNAME => array('ID', 'AREA_ID', 'ISOCODE', 'ISOALPHA2', 'ISOALPHA3', 'BY_DEFAULT', 'SHOP_COUNTRY', 'CREATED_AT', 'UPDATED_AT', ),
self::TYPE_FIELDNAME => array('id', 'area_id', 'isocode', 'isoalpha2', 'isoalpha3', 'by_default', 'shop_country', 'created_at', 'updated_at', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, )
);
/**
@@ -145,12 +150,12 @@ class CountryTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
self::TYPE_PHPNAME => array('Id' => 0, 'AreaId' => 1, 'Isocode' => 2, 'Isoalpha2' => 3, 'Isoalpha3' => 4, 'ByDefault' => 5, 'CreatedAt' => 6, 'UpdatedAt' => 7, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'areaId' => 1, 'isocode' => 2, 'isoalpha2' => 3, 'isoalpha3' => 4, 'byDefault' => 5, 'createdAt' => 6, 'updatedAt' => 7, ),
self::TYPE_COLNAME => array(CountryTableMap::ID => 0, CountryTableMap::AREA_ID => 1, CountryTableMap::ISOCODE => 2, CountryTableMap::ISOALPHA2 => 3, CountryTableMap::ISOALPHA3 => 4, CountryTableMap::BY_DEFAULT => 5, CountryTableMap::CREATED_AT => 6, CountryTableMap::UPDATED_AT => 7, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'AREA_ID' => 1, 'ISOCODE' => 2, 'ISOALPHA2' => 3, 'ISOALPHA3' => 4, 'BY_DEFAULT' => 5, 'CREATED_AT' => 6, 'UPDATED_AT' => 7, ),
self::TYPE_FIELDNAME => array('id' => 0, 'area_id' => 1, 'isocode' => 2, 'isoalpha2' => 3, 'isoalpha3' => 4, 'by_default' => 5, 'created_at' => 6, 'updated_at' => 7, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, )
self::TYPE_PHPNAME => array('Id' => 0, 'AreaId' => 1, 'Isocode' => 2, 'Isoalpha2' => 3, 'Isoalpha3' => 4, 'ByDefault' => 5, 'ShopCountry' => 6, 'CreatedAt' => 7, 'UpdatedAt' => 8, ),
self::TYPE_STUDLYPHPNAME => array('id' => 0, 'areaId' => 1, 'isocode' => 2, 'isoalpha2' => 3, 'isoalpha3' => 4, 'byDefault' => 5, 'shopCountry' => 6, 'createdAt' => 7, 'updatedAt' => 8, ),
self::TYPE_COLNAME => array(CountryTableMap::ID => 0, CountryTableMap::AREA_ID => 1, CountryTableMap::ISOCODE => 2, CountryTableMap::ISOALPHA2 => 3, CountryTableMap::ISOALPHA3 => 4, CountryTableMap::BY_DEFAULT => 5, CountryTableMap::SHOP_COUNTRY => 6, CountryTableMap::CREATED_AT => 7, CountryTableMap::UPDATED_AT => 8, ),
self::TYPE_RAW_COLNAME => array('ID' => 0, 'AREA_ID' => 1, 'ISOCODE' => 2, 'ISOALPHA2' => 3, 'ISOALPHA3' => 4, 'BY_DEFAULT' => 5, 'SHOP_COUNTRY' => 6, 'CREATED_AT' => 7, 'UPDATED_AT' => 8, ),
self::TYPE_FIELDNAME => array('id' => 0, 'area_id' => 1, 'isocode' => 2, 'isoalpha2' => 3, 'isoalpha3' => 4, 'by_default' => 5, 'shop_country' => 6, 'created_at' => 7, 'updated_at' => 8, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, 7, 8, )
);
/**
@@ -174,7 +179,8 @@ class CountryTableMap extends TableMap
$this->addColumn('ISOCODE', 'Isocode', 'VARCHAR', true, 4, null);
$this->addColumn('ISOALPHA2', 'Isoalpha2', 'VARCHAR', false, 2, null);
$this->addColumn('ISOALPHA3', 'Isoalpha3', 'VARCHAR', false, 4, null);
$this->addColumn('BY_DEFAULT', 'ByDefault', 'TINYINT', false, null, null);
$this->addColumn('BY_DEFAULT', 'ByDefault', 'TINYINT', false, null, 0);
$this->addColumn('SHOP_COUNTRY', 'ShopCountry', 'BOOLEAN', true, 1, false);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()
@@ -358,6 +364,7 @@ class CountryTableMap extends TableMap
$criteria->addSelectColumn(CountryTableMap::ISOALPHA2);
$criteria->addSelectColumn(CountryTableMap::ISOALPHA3);
$criteria->addSelectColumn(CountryTableMap::BY_DEFAULT);
$criteria->addSelectColumn(CountryTableMap::SHOP_COUNTRY);
$criteria->addSelectColumn(CountryTableMap::CREATED_AT);
$criteria->addSelectColumn(CountryTableMap::UPDATED_AT);
} else {
@@ -367,6 +374,7 @@ class CountryTableMap extends TableMap
$criteria->addSelectColumn($alias . '.ISOALPHA2');
$criteria->addSelectColumn($alias . '.ISOALPHA3');
$criteria->addSelectColumn($alias . '.BY_DEFAULT');
$criteria->addSelectColumn($alias . '.SHOP_COUNTRY');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
}

View File

@@ -57,7 +57,7 @@ class ProductPriceTableMap extends TableMap
/**
* The total number of columns
*/
const NUM_COLUMNS = 6;
const NUM_COLUMNS = 7;
/**
* The number of lazy-loaded columns
@@ -67,7 +67,7 @@ class ProductPriceTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
const NUM_HYDRATE_COLUMNS = 6;
const NUM_HYDRATE_COLUMNS = 7;
/**
* the column name for the PRODUCT_SALE_ELEMENTS_ID field
@@ -89,6 +89,11 @@ class ProductPriceTableMap extends TableMap
*/
const PROMO_PRICE = 'product_price.PROMO_PRICE';
/**
* the column name for the FROM_DEFAULT_CURRENCY field
*/
const FROM_DEFAULT_CURRENCY = 'product_price.FROM_DEFAULT_CURRENCY';
/**
* the column name for the CREATED_AT field
*/
@@ -111,12 +116,12 @@ class ProductPriceTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
self::TYPE_PHPNAME => array('ProductSaleElementsId', 'CurrencyId', 'Price', 'PromoPrice', 'CreatedAt', 'UpdatedAt', ),
self::TYPE_STUDLYPHPNAME => array('productSaleElementsId', 'currencyId', 'price', 'promoPrice', 'createdAt', 'updatedAt', ),
self::TYPE_COLNAME => array(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID, ProductPriceTableMap::CURRENCY_ID, ProductPriceTableMap::PRICE, ProductPriceTableMap::PROMO_PRICE, ProductPriceTableMap::CREATED_AT, ProductPriceTableMap::UPDATED_AT, ),
self::TYPE_RAW_COLNAME => array('PRODUCT_SALE_ELEMENTS_ID', 'CURRENCY_ID', 'PRICE', 'PROMO_PRICE', 'CREATED_AT', 'UPDATED_AT', ),
self::TYPE_FIELDNAME => array('product_sale_elements_id', 'currency_id', 'price', 'promo_price', 'created_at', 'updated_at', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
self::TYPE_PHPNAME => array('ProductSaleElementsId', 'CurrencyId', 'Price', 'PromoPrice', 'FromDefaultCurrency', 'CreatedAt', 'UpdatedAt', ),
self::TYPE_STUDLYPHPNAME => array('productSaleElementsId', 'currencyId', 'price', 'promoPrice', 'fromDefaultCurrency', 'createdAt', 'updatedAt', ),
self::TYPE_COLNAME => array(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID, ProductPriceTableMap::CURRENCY_ID, ProductPriceTableMap::PRICE, ProductPriceTableMap::PROMO_PRICE, ProductPriceTableMap::FROM_DEFAULT_CURRENCY, ProductPriceTableMap::CREATED_AT, ProductPriceTableMap::UPDATED_AT, ),
self::TYPE_RAW_COLNAME => array('PRODUCT_SALE_ELEMENTS_ID', 'CURRENCY_ID', 'PRICE', 'PROMO_PRICE', 'FROM_DEFAULT_CURRENCY', 'CREATED_AT', 'UPDATED_AT', ),
self::TYPE_FIELDNAME => array('product_sale_elements_id', 'currency_id', 'price', 'promo_price', 'from_default_currency', 'created_at', 'updated_at', ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, )
);
/**
@@ -126,12 +131,12 @@ class ProductPriceTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
self::TYPE_PHPNAME => array('ProductSaleElementsId' => 0, 'CurrencyId' => 1, 'Price' => 2, 'PromoPrice' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ),
self::TYPE_STUDLYPHPNAME => array('productSaleElementsId' => 0, 'currencyId' => 1, 'price' => 2, 'promoPrice' => 3, 'createdAt' => 4, 'updatedAt' => 5, ),
self::TYPE_COLNAME => array(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID => 0, ProductPriceTableMap::CURRENCY_ID => 1, ProductPriceTableMap::PRICE => 2, ProductPriceTableMap::PROMO_PRICE => 3, ProductPriceTableMap::CREATED_AT => 4, ProductPriceTableMap::UPDATED_AT => 5, ),
self::TYPE_RAW_COLNAME => array('PRODUCT_SALE_ELEMENTS_ID' => 0, 'CURRENCY_ID' => 1, 'PRICE' => 2, 'PROMO_PRICE' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ),
self::TYPE_FIELDNAME => array('product_sale_elements_id' => 0, 'currency_id' => 1, 'price' => 2, 'promo_price' => 3, 'created_at' => 4, 'updated_at' => 5, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
self::TYPE_PHPNAME => array('ProductSaleElementsId' => 0, 'CurrencyId' => 1, 'Price' => 2, 'PromoPrice' => 3, 'FromDefaultCurrency' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ),
self::TYPE_STUDLYPHPNAME => array('productSaleElementsId' => 0, 'currencyId' => 1, 'price' => 2, 'promoPrice' => 3, 'fromDefaultCurrency' => 4, 'createdAt' => 5, 'updatedAt' => 6, ),
self::TYPE_COLNAME => array(ProductPriceTableMap::PRODUCT_SALE_ELEMENTS_ID => 0, ProductPriceTableMap::CURRENCY_ID => 1, ProductPriceTableMap::PRICE => 2, ProductPriceTableMap::PROMO_PRICE => 3, ProductPriceTableMap::FROM_DEFAULT_CURRENCY => 4, ProductPriceTableMap::CREATED_AT => 5, ProductPriceTableMap::UPDATED_AT => 6, ),
self::TYPE_RAW_COLNAME => array('PRODUCT_SALE_ELEMENTS_ID' => 0, 'CURRENCY_ID' => 1, 'PRICE' => 2, 'PROMO_PRICE' => 3, 'FROM_DEFAULT_CURRENCY' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ),
self::TYPE_FIELDNAME => array('product_sale_elements_id' => 0, 'currency_id' => 1, 'price' => 2, 'promo_price' => 3, 'from_default_currency' => 4, 'created_at' => 5, 'updated_at' => 6, ),
self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, )
);
/**
@@ -154,6 +159,7 @@ class ProductPriceTableMap extends TableMap
$this->addForeignPrimaryKey('CURRENCY_ID', 'CurrencyId', 'INTEGER' , 'currency', 'ID', true, null, null);
$this->addColumn('PRICE', 'Price', 'FLOAT', true, null, null);
$this->addColumn('PROMO_PRICE', 'PromoPrice', 'FLOAT', false, null, null);
$this->addColumn('FROM_DEFAULT_CURRENCY', 'FromDefaultCurrency', 'BOOLEAN', true, 1, false);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()
@@ -371,6 +377,7 @@ class ProductPriceTableMap extends TableMap
$criteria->addSelectColumn(ProductPriceTableMap::CURRENCY_ID);
$criteria->addSelectColumn(ProductPriceTableMap::PRICE);
$criteria->addSelectColumn(ProductPriceTableMap::PROMO_PRICE);
$criteria->addSelectColumn(ProductPriceTableMap::FROM_DEFAULT_CURRENCY);
$criteria->addSelectColumn(ProductPriceTableMap::CREATED_AT);
$criteria->addSelectColumn(ProductPriceTableMap::UPDATED_AT);
} else {
@@ -378,6 +385,7 @@ class ProductPriceTableMap extends TableMap
$criteria->addSelectColumn($alias . '.CURRENCY_ID');
$criteria->addSelectColumn($alias . '.PRICE');
$criteria->addSelectColumn($alias . '.PROMO_PRICE');
$criteria->addSelectColumn($alias . '.FROM_DEFAULT_CURRENCY');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
}

View File

@@ -147,7 +147,7 @@ class ProfileModuleTableMap extends TableMap
// columns
$this->addForeignPrimaryKey('PROFILE_ID', 'ProfileId', 'INTEGER' , 'profile', 'ID', true, null, null);
$this->addForeignPrimaryKey('MODULE_ID', 'ModuleId', 'INTEGER' , 'module', 'ID', true, null, null);
$this->addColumn('ACCESS', 'Access', 'INTEGER', true, null, 0);
$this->addColumn('ACCESS', 'Access', 'TINYINT', false, null, 0);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()

View File

@@ -12,6 +12,7 @@ use Thelia\Core\Event\Product\ProductEvent;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Propel;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\ProductSaleElementsQuery;
class Product extends BaseProduct
{
@@ -47,6 +48,20 @@ class Product extends BaseProduct
return $taxCalculator->load($this, $country)->getTaxedPrice($this->getRealLowestPrice());
}
/**
* Return the default PSE for this product.
*/
public function getDefaultSaleElements() {
return ProductSaleElementsQuery::create()->filterByProductId($this->id)->filterByIsDefault(true)->find();
}
/**
* Return PSE count fir this product.
*/
public function countSaleElements() {
return ProductSaleElementsQuery::create()->filterByProductId($this->id)->filterByIsDefault(true)->count();
}
/**
* @return the current default category ID for this product
*/
@@ -100,7 +115,7 @@ class Product extends BaseProduct
;
if ($productCategory == null || $productCategory->getCategoryId() != $defaultCategoryId) {
exit;
// Delete the old default category
if ($productCategory !== null) $productCategory->delete();
@@ -131,10 +146,10 @@ class Product extends BaseProduct
$con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
$con->beginTransaction();
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT, new ProductEvent($this));
try {
// Create the product
$this->save($con);
@@ -146,29 +161,8 @@ class Product extends BaseProduct
$this->setTaxRuleId($taxRuleId);
// Create an empty product sale element
$sale_elements = new ProductSaleElements();
$sale_elements
->setProduct($this)
->setRef($this->getRef())
->setPromo(0)
->setNewness(0)
->setWeight($baseWeight)
->setIsDefault(true)
->save($con)
;
// Create an empty product price in the default currency
$product_price = new ProductPrice();
$product_price
->setProductSaleElements($sale_elements)
->setPromoPrice($basePrice)
->setPrice($basePrice)
->setCurrencyId($priceCurrencyId)
->save($con)
;
// Create the default product sale element of this product
$sale_elements = $this->createDefaultProductSaleElement($con, $baseWeight, $basePrice, $priceCurrencyId, true);
// Store all the stuff !
$con->commit();
@@ -183,6 +177,38 @@ class Product extends BaseProduct
}
}
/**
* Create a basic product sale element attached to this product.
*/
public function createDefaultProductSaleElement(ConnectionInterface $con, $weight, $basePrice, $currencyId, $isDefault) {
// Create an empty product sale element
$sale_elements = new ProductSaleElements();
$sale_elements
->setProduct($this)
->setRef($this->getRef())
->setPromo(0)
->setNewness(0)
->setWeight($weight)
->setIsDefault($isDefault)
->save($con)
;
// Create an empty product price in the default currency
$product_price = new ProductPrice();
$product_price
->setProductSaleElements($sale_elements)
->setPromoPrice($basePrice)
->setPrice($basePrice)
->setCurrencyId($currencyId)
->save($con)
;
return $sale_elements;
}
/**
* Calculate next position relative to our default category
*/

View File

@@ -1,5 +1,4 @@
<?php
namespace Thelia\Model;
use Thelia\Model\Base\Profile as BaseProfile;
@@ -8,4 +7,4 @@ use Thelia\Model\Tools\ModelEventDispatcherTrait;
class Profile extends BaseProfile
{
use ModelEventDispatcherTrait;
}
}

View File

@@ -0,0 +1,52 @@
<?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\Tools;
use Symfony\Component\HttpFoundation\Request;
class NumberFormat
{
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
}
public static function getInstance(Request $request)
{
return new NumberFormat($request);
}
public function format($number, $decimals = null, $decPoint = null, $thousandsSep = null)
{
$lang = $this->request->getSession()->getLang();
if ($decimals == null) $decimals = $lang->getDecimals();
if ($decPoint == null) $decPoint = $lang->getDecimalSeparator();
if ($thousandsSep == null) $thousandsSep = $lang->getThousandsSeparator();
return number_format($number, $decimals, $decPoint, $thousandsSep);
}
}