Merge branch 'catalog' of https://github.com/thelia/thelia into upload_management
# By franck # Via franck * 'catalog' of https://github.com/thelia/thelia: Finished combination creation GUI Put curresncy selector in toolbar Started price tab Finished product multiple categories attachment Ajaxified product modification tabs Finished product features management Aded feature_template and category_template position management Finished product feature values Fixed product update process Added missing files Working catalog branch Conflicts: core/lib/Thelia/Action/BaseAction.php install/insert.sql local/config/schema.xml templates/admin/default/folders.html templates/admin/default/product-edit.html
This commit is contained in:
@@ -123,19 +123,7 @@ class Attribute extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $attribute = AttributeQuery::create()->findPk($event->getObjectId())) {
|
||||
|
||||
$attribute->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
|
||||
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
return $attribute->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == UpdatePositionEvent::POSITION_UP)
|
||||
return $attribute->movePositionUp();
|
||||
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
|
||||
return $attribute->movePositionDown();
|
||||
}
|
||||
return $this->genericUpdatePosition(AttributeQuery::create(), $event);
|
||||
}
|
||||
|
||||
protected function doAddToAllTemplates(AttributeModel $attribute)
|
||||
|
||||
@@ -112,19 +112,7 @@ class AttributeAv extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $attribute = AttributeAvQuery::create()->findPk($event->getObjectId())) {
|
||||
|
||||
$attribute->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
|
||||
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
return $attribute->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == UpdatePositionEvent::POSITION_UP)
|
||||
return $attribute->movePositionUp();
|
||||
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
|
||||
return $attribute->movePositionDown();
|
||||
}
|
||||
return $this->genericUpdatePosition(AttributeAvQuery::create(), $event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Model\AdminLog;
|
||||
use Propel\Runtime\ActiveQuery\PropelQuery;
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
|
||||
class BaseAction
|
||||
{
|
||||
@@ -47,6 +50,30 @@ class BaseAction
|
||||
return $this->container->get('event_dispatcher');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Changes object position, selecting absolute ou relative change.
|
||||
*
|
||||
* @param $query the query to retrieve the object to move
|
||||
* @param UpdatePositionEvent $event
|
||||
*/
|
||||
protected function genericUpdatePosition(ModelCriteria $query, UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $object = $query->findPk($event->getObjectId())) {
|
||||
|
||||
$object->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
|
||||
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
return $object->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == UpdatePositionEvent::POSITION_UP)
|
||||
return $object->movePositionUp();
|
||||
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
|
||||
return $object->movePositionDown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to append a message to the admin log.
|
||||
*
|
||||
|
||||
@@ -136,19 +136,7 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $category = CategoryQuery::create()->findPk($event->getObjectId())) {
|
||||
|
||||
$category->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
|
||||
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
return $category->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == UpdatePositionEvent::POSITION_UP)
|
||||
return $category->movePositionUp();
|
||||
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
|
||||
return $category->movePositionDown();
|
||||
}
|
||||
return $this->genericUpdatePosition(CategoryQuery::create(), $event);
|
||||
}
|
||||
|
||||
public function addContent(CategoryAddContentEvent $event) {
|
||||
|
||||
@@ -166,20 +166,7 @@ class Currency extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $currency = CurrencyQuery::create()->findPk($event->getObjectId())) {
|
||||
|
||||
$currency->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
echo "loaded $mode !";
|
||||
|
||||
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
return $currency->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == UpdatePositionEvent::POSITION_UP)
|
||||
return $currency->movePositionUp();
|
||||
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
|
||||
return $currency->movePositionDown();
|
||||
}
|
||||
return $this->genericUpdatePosition(CurrencyQuery::create(), $event);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -123,19 +123,7 @@ class Feature extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $feature = FeatureQuery::create()->findPk($event->getObjectId())) {
|
||||
|
||||
$feature->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
|
||||
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
return $feature->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == UpdatePositionEvent::POSITION_UP)
|
||||
return $feature->movePositionUp();
|
||||
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
|
||||
return $feature->movePositionDown();
|
||||
}
|
||||
return $this->genericUpdatePosition(FeatureQuery::create(), $event);
|
||||
}
|
||||
|
||||
protected function doAddToAllTemplates(FeatureModel $feature)
|
||||
|
||||
@@ -112,19 +112,7 @@ class FeatureAv extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $feature = FeatureAvQuery::create()->findPk($event->getObjectId())) {
|
||||
|
||||
$feature->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
|
||||
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
return $feature->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == UpdatePositionEvent::POSITION_UP)
|
||||
return $feature->movePositionUp();
|
||||
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
|
||||
return $feature->movePositionDown();
|
||||
}
|
||||
return $this->genericUpdatePosition(FeatureAvQuery::create(), $event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -48,6 +48,19 @@ use Thelia\Model\AccessoryQuery;
|
||||
use Thelia\Model\Accessory;
|
||||
use Thelia\Core\Event\ProductAddAccessoryEvent;
|
||||
use Thelia\Core\Event\ProductDeleteAccessoryEvent;
|
||||
use Thelia\Core\Event\FeatureProductUpdateEvent;
|
||||
use Thelia\Model\FeatureProduct;
|
||||
use Thelia\Model\FeatureQuery;
|
||||
use Thelia\Core\Event\FeatureProductDeleteEvent;
|
||||
use Thelia\Model\FeatureProductQuery;
|
||||
use Thelia\Model\ProductCategoryQuery;
|
||||
use Thelia\Core\Event\ProductSetTemplateEvent;
|
||||
use Thelia\Model\AttributeCombinationQuery;
|
||||
use Thelia\Core\Template\Loop\ProductSaleElements;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Propel\Runtime\ActiveQuery\PropelQuery;
|
||||
use Thelia\Core\Event\ProductDeleteCategoryEvent;
|
||||
use Thelia\Core\Event\ProductAddCategoryEvent;
|
||||
|
||||
class Product extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
@@ -71,7 +84,15 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
// Set the default tax rule to this product
|
||||
->setTaxRule(TaxRuleQuery::create()->findOneByIsDefault(true))
|
||||
|
||||
->create($event->getDefaultCategory())
|
||||
//public function create($defaultCategoryId, $basePrice, $priceCurrencyId, $taxRuleId, $baseWeight) {
|
||||
|
||||
->create(
|
||||
$event->getDefaultCategory(),
|
||||
$event->getBasePrice(),
|
||||
$event->getCurrencyId(),
|
||||
$event->getTaxRuleId(),
|
||||
$event->getBaseWeight()
|
||||
);
|
||||
;
|
||||
|
||||
$event->setProduct($product);
|
||||
@@ -84,8 +105,6 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function update(ProductUpdateEvent $event)
|
||||
{
|
||||
$search = ProductQuery::create();
|
||||
|
||||
if (null !== $product = ProductQuery::create()->findPk($event->getProductId())) {
|
||||
|
||||
$product
|
||||
@@ -96,11 +115,16 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
->setDescription($event->getDescription())
|
||||
->setChapo($event->getChapo())
|
||||
->setPostscriptum($event->getPostscriptum())
|
||||
|
||||
->setParent($event->getParent())
|
||||
->setVisible($event->getVisible())
|
||||
|
||||
->save();
|
||||
->save()
|
||||
;
|
||||
|
||||
// Update the rewriten URL, if required
|
||||
$product->setRewrittenUrl($event->getLocale(), $event->getUrl());
|
||||
|
||||
// Update default category (ifd required)
|
||||
$product->updateDefaultCategory($event->getDefaultCategory());
|
||||
|
||||
$event->setProduct($product);
|
||||
}
|
||||
@@ -147,19 +171,7 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $product = ProductQuery::create()->findPk($event->getObjectId())) {
|
||||
|
||||
$product->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
|
||||
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
return $product->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == UpdatePositionEvent::POSITION_UP)
|
||||
return $product->movePositionUp();
|
||||
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
|
||||
return $product->movePositionDown();
|
||||
}
|
||||
return $this->genericUpdatePosition(ProductQuery::create(), $event);
|
||||
}
|
||||
|
||||
public function addContent(ProductAddContentEvent $event) {
|
||||
@@ -193,6 +205,34 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
;
|
||||
}
|
||||
|
||||
public function addCategory(ProductAddCategoryEvent $event) {
|
||||
|
||||
if (ProductCategoryQuery::create()
|
||||
->filterByProduct($event->getProduct())
|
||||
->filterByCategoryId($event->getCategoryId())
|
||||
->count() <= 0) {
|
||||
|
||||
$productCategory = new ProductCategory();
|
||||
|
||||
$productCategory
|
||||
->setProduct($event->getProduct())
|
||||
->setCategoryId($event->getCategoryId())
|
||||
->setDefaultCategory(false)
|
||||
->save()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public function removeCategory(ProductDeleteCategoryEvent $event) {
|
||||
|
||||
$productCategory = ProductCategoryQuery::create()
|
||||
->filterByProduct($event->getProduct())
|
||||
->filterByCategoryId($event->getCategoryId())
|
||||
->findOne();
|
||||
|
||||
if ($productCategory != null) $productCategory->delete();
|
||||
}
|
||||
|
||||
public function addAccessory(ProductAddAccessoryEvent $event) {
|
||||
|
||||
if (AccessoryQuery::create()
|
||||
@@ -224,27 +264,96 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
;
|
||||
}
|
||||
|
||||
public function setProductTemplate(ProductSetTemplateEvent $event) {
|
||||
|
||||
$product = $event->getProduct();
|
||||
|
||||
// Delete all product feature relations
|
||||
FeatureProductQuery::create()->filterByProduct($product)->delete();
|
||||
|
||||
// Delete all product attributes sale elements
|
||||
ProductSaleElementsQuery::create()->filterByProduct($product)->delete();
|
||||
|
||||
// Update the product template
|
||||
$template_id = $event->getTemplateId();
|
||||
|
||||
// Set it to null if it's zero.
|
||||
if ($template_id <= 0) $template_id = NULL;
|
||||
|
||||
$product->setTemplateId($template_id)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes accessry position, selecting absolute ou relative change.
|
||||
*
|
||||
* @param ProductChangePositionEvent $event
|
||||
*/
|
||||
public function updateAccessoryPosition(UpdatePositionEvent $event)
|
||||
{
|
||||
return $this->genericUpdatePosition(AccessoryQuery::create(), $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes position, selecting absolute ou relative change.
|
||||
*
|
||||
* @param ProductChangePositionEvent $event
|
||||
*/
|
||||
public function updateAccessoryPosition(UpdatePositionEvent $event)
|
||||
public function updateContentPosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $accessory = AccessoryQuery::create()->findPk($event->getObjectId())) {
|
||||
return $this->genericUpdatePosition(ProductAssociatedContentQuery::create(), $event);
|
||||
}
|
||||
|
||||
$accessory->setDispatcher($this->getDispatcher());
|
||||
public function updateFeatureProductValue(FeatureProductUpdateEvent $event) {
|
||||
|
||||
$mode = $event->getMode();
|
||||
// If the feature is not free text, it may have one ore more values.
|
||||
// If the value exists, we do not change it
|
||||
// If the value does not exists, we create it.
|
||||
//
|
||||
// If the feature is free text, it has only a single value.
|
||||
// Etiher create or update it.
|
||||
|
||||
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
return $accessory->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == UpdatePositionEvent::POSITION_UP)
|
||||
return $accessory->movePositionUp();
|
||||
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
|
||||
return $accessory->movePositionDown();
|
||||
$featureProductQuery = FeatureProductQuery::create()
|
||||
->filterByFeatureId($event->getFeatureId())
|
||||
->filterByProductId($event->getProductId())
|
||||
;
|
||||
|
||||
if ($event->getIsTextValue() !== true) {
|
||||
$featureProductQuery->filterByFeatureAvId($event->getFeatureValue());
|
||||
}
|
||||
|
||||
$featureProduct = $featureProductQuery->findOne();
|
||||
|
||||
if ($featureProduct == null) {
|
||||
$featureProduct = new FeatureProduct();
|
||||
|
||||
$featureProduct
|
||||
->setDispatcher($this->getDispatcher())
|
||||
|
||||
->setProductId($event->getProductId())
|
||||
->setFeatureId($event->getFeatureId())
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
if ($event->getIsTextValue() == true) {
|
||||
$featureProduct->setFreeTextValue($event->getFeatureValue());
|
||||
}
|
||||
else {
|
||||
$featureProduct->setFeatureAvId($event->getFeatureValue());
|
||||
}
|
||||
|
||||
$featureProduct->save();
|
||||
|
||||
$event->setFeatureProduct($featureProduct);
|
||||
}
|
||||
|
||||
public function deleteFeatureProductValue(FeatureProductDeleteEvent $event) {
|
||||
|
||||
$featureProduct = FeatureProductQuery::create()
|
||||
->filterByProductId($event->getProductId())
|
||||
->filterByFeatureId($event->getFeatureId())
|
||||
->delete()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,9 +372,19 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
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_ACCESSORY => array("addAccessory", 128),
|
||||
TheliaEvents::PRODUCT_REMOVE_ACCESSORY => array("removeAccessory", 128),
|
||||
|
||||
TheliaEvents::PRODUCT_ADD_CATEGORY => array("addCategory", 128),
|
||||
TheliaEvents::PRODUCT_REMOVE_CATEGORY => array("removeCategory", 128),
|
||||
|
||||
TheliaEvents::PRODUCT_SET_TEMPLATE => array("setProductTemplate", 128),
|
||||
|
||||
TheliaEvents::PRODUCT_FEATURE_UPDATE_VALUE => array("updateFeatureProductValue", 128),
|
||||
TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE => array("deleteFeatureProductValue", 128),
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,26 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes position, selecting absolute ou relative change.
|
||||
*
|
||||
* @param CategoryChangePositionEvent $event
|
||||
*/
|
||||
public function updateAttributePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
return $this->genericUpdatePosition(AttributeTemplateQuery::create(), $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes position, selecting absolute ou relative change.
|
||||
*
|
||||
* @param CategoryChangePositionEvent $event
|
||||
*/
|
||||
public function updateFeaturePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
return $this->genericUpdatePosition(FeatureTemplateQuery::create(), $event);
|
||||
}
|
||||
|
||||
public function deleteAttribute(TemplateDeleteAttributeEvent $event) {
|
||||
|
||||
$attribute_template = AttributeTemplateQuery::create()
|
||||
@@ -185,6 +205,9 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::TEMPLATE_ADD_FEATURE => array("addFeature", 128),
|
||||
TheliaEvents::TEMPLATE_DELETE_FEATURE => array("deleteFeature", 128),
|
||||
|
||||
TheliaEvents::TEMPLATE_CHANGE_ATTRIBUTE_POSITION => array('updateAttributePosition', 128),
|
||||
TheliaEvents::TEMPLATE_CHANGE_FEATURE_POSITION => array('updateFeaturePosition', 128),
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user