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),
);
}
}