Finished product multiple categories attachment
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Propel\Runtime\ActiveQuery\PropelQuery;
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
|
||||
class BaseAction
|
||||
{
|
||||
@@ -45,4 +48,28 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -58,6 +58,9 @@ 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
|
||||
{
|
||||
@@ -81,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);
|
||||
@@ -94,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
|
||||
@@ -162,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) {
|
||||
@@ -208,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()
|
||||
@@ -259,25 +284,23 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes position, selecting absolute ou relative change.
|
||||
* Changes accessry position, selecting absolute ou relative change.
|
||||
*
|
||||
* @param ProductChangePositionEvent $event
|
||||
*/
|
||||
public function updateAccessoryPosition(UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $accessory = AccessoryQuery::create()->findPk($event->getObjectId())) {
|
||||
return $this->genericUpdatePosition(AccessoryQuery::create(), $event);
|
||||
}
|
||||
|
||||
$accessory->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
|
||||
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();
|
||||
}
|
||||
/**
|
||||
* Changes position, selecting absolute ou relative change.
|
||||
*
|
||||
* @param ProductChangePositionEvent $event
|
||||
*/
|
||||
public function updateContentPosition(UpdatePositionEvent $event)
|
||||
{
|
||||
return $this->genericUpdatePosition(ProductAssociatedContentQuery::create(), $event);
|
||||
}
|
||||
|
||||
public function updateFeatureProductValue(FeatureProductUpdateEvent $event) {
|
||||
@@ -299,10 +322,8 @@ class Product extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
$featureProduct = $featureProductQuery->findOne();
|
||||
echo "<br /> create or update: f=".$event->getFeatureId().", p=".$event->getProductId();
|
||||
|
||||
if ($featureProduct == null) {
|
||||
echo " Create !";
|
||||
$featureProduct = new FeatureProduct();
|
||||
|
||||
$featureProduct
|
||||
@@ -313,7 +334,6 @@ echo " Create !";
|
||||
|
||||
;
|
||||
}
|
||||
else echo " Update !";
|
||||
|
||||
if ($event->getIsTextValue() == true) {
|
||||
$featureProduct->setFreeTextValue($event->getFeatureValue());
|
||||
@@ -321,7 +341,6 @@ echo " Create !";
|
||||
else {
|
||||
$featureProduct->setFeatureAvId($event->getFeatureValue());
|
||||
}
|
||||
echo "value=".$event->getFeatureValue();
|
||||
|
||||
$featureProduct->save();
|
||||
|
||||
@@ -335,8 +354,6 @@ echo "value=".$event->getFeatureValue();
|
||||
->filterByFeatureId($event->getFeatureId())
|
||||
->delete()
|
||||
;
|
||||
|
||||
echo "<br/>Delete p=".$event->getProductId().", f=".$event->getFeatureId();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -355,10 +372,14 @@ echo "value=".$event->getFeatureValue();
|
||||
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),
|
||||
|
||||
@@ -142,9 +142,7 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function updateAttributePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
$attributeTemplate = AttributeTemplateQuery::create()->findPk($event->getObjectId());
|
||||
|
||||
$this->updatePosition($attributeTemplate, $event);
|
||||
return $this->genericUpdatePosition(AttributeTemplateQuery::create(), $event);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,26 +152,7 @@ class Template extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function updateFeaturePosition(UpdatePositionEvent $event)
|
||||
{
|
||||
$featureTemplate = FeatureTemplateQuery::create()->findPk($event->getObjectId());
|
||||
|
||||
$this->updatePosition($featureTemplate, $event);
|
||||
}
|
||||
|
||||
protected function updatePosition($object, UpdatePositionEvent $event)
|
||||
{
|
||||
if (null !== $object) {
|
||||
|
||||
$object->setDispatcher($this->getDispatcher());
|
||||
|
||||
$mode = $event->getMode();
|
||||
|
||||
if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE)
|
||||
$object->changeAbsolutePosition($event->getPosition());
|
||||
else if ($mode == UpdatePositionEvent::POSITION_UP)
|
||||
$object->movePositionUp();
|
||||
else if ($mode == UpdatePositionEvent::POSITION_DOWN)
|
||||
$object->movePositionDown();
|
||||
}
|
||||
return $this->genericUpdatePosition(FeatureTemplateQuery::create(), $event);
|
||||
}
|
||||
|
||||
public function deleteAttribute(TemplateDeleteAttributeEvent $event) {
|
||||
|
||||
@@ -155,13 +155,24 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\ProductController::loadGeneralAjaxTabAction</default>
|
||||
</route>
|
||||
|
||||
<!-- Product Related content and accessories -->
|
||||
<!-- Product associations, categories, content and accessories -->
|
||||
|
||||
<route id="admin.products.related.tab" path="/admin/products/related/tab">
|
||||
<default key="_controller">Thelia\Controller\Admin\ProductController::loadRelatedAjaxTabAction</default>
|
||||
</route>
|
||||
|
||||
<!-- categories -->
|
||||
|
||||
<route id="admin.products.additional-category.add" path="/admin/products/category/add">
|
||||
<default key="_controller">Thelia\Controller\Admin\ProductController::addAdditionalCategoryAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.products.additional-category.delete" path="/admin/products/category/delete">
|
||||
<default key="_controller">Thelia\Controller\Admin\ProductController::deleteAdditionalCategoryAction</default>
|
||||
</route>
|
||||
|
||||
<!-- content -->
|
||||
|
||||
<route id="admin.products.related-content.add" path="/admin/products/content/add">
|
||||
<default key="_controller">Thelia\Controller\Admin\ProductController::addRelatedContentAction</default>
|
||||
</route>
|
||||
@@ -175,6 +186,10 @@
|
||||
<requirement key="_format">xml|json</requirement>
|
||||
</route>
|
||||
|
||||
<route id="admin.product.update-content-position" path="/admin/product/update-content-position">
|
||||
<default key="_controller">Thelia\Controller\Admin\ProductController::updateContentPositionAction</default>
|
||||
</route>
|
||||
|
||||
<!-- accessories -->
|
||||
|
||||
<route id="admin.products.accessories.add" path="/admin/products/accessory/add">
|
||||
|
||||
@@ -446,6 +446,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
/**
|
||||
* Update object position (only for objects whichsupport that)
|
||||
*
|
||||
* FIXME: integrate with genericUpdatePositionAction
|
||||
*/
|
||||
public function updatePositionAction()
|
||||
{
|
||||
@@ -483,6 +485,38 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
}
|
||||
}
|
||||
|
||||
protected function genericUpdatePositionAction($object, $eventName, $doFinalRedirect = true) {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
if ($object != null) {
|
||||
|
||||
try {
|
||||
$mode = $this->getRequest()->get('mode', null);
|
||||
|
||||
if ($mode == 'up')
|
||||
$mode = UpdatePositionEvent::POSITION_UP;
|
||||
else if ($mode == 'down')
|
||||
$mode = UpdatePositionEvent::POSITION_DOWN;
|
||||
else
|
||||
$mode = UpdatePositionEvent::POSITION_ABSOLUTE;
|
||||
|
||||
$position = $this->getRequest()->get('position', null);
|
||||
|
||||
$event = new UpdatePositionEvent($object->getId(), $mode, $position);
|
||||
|
||||
$this->dispatch($eventName, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
}
|
||||
|
||||
if ($doFinalRedirect) $this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Online status toggle (only for object which support it)
|
||||
*/
|
||||
|
||||
@@ -48,6 +48,9 @@ use Thelia\Model\FeatureQuery;
|
||||
use Thelia\Core\Event\FeatureProductDeleteEvent;
|
||||
use Thelia\Model\FeatureTemplateQuery;
|
||||
use Thelia\Core\Event\ProductSetTemplateEvent;
|
||||
use Thelia\Model\Base\ProductSaleElementsQuery;
|
||||
use Thelia\Core\Event\ProductAddCategoryEvent;
|
||||
use Thelia\Core\Event\ProductDeleteCategoryEvent;
|
||||
|
||||
/**
|
||||
* Manages products
|
||||
@@ -77,33 +80,6 @@ class ProductController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* General ajax tab loading
|
||||
*/
|
||||
public function loadGeneralAjaxTabAction() {
|
||||
|
||||
// Load the object
|
||||
$object = $this->getExistingObject();
|
||||
|
||||
if ($object != null) {
|
||||
|
||||
// Hydrate the form abd pass it to the parser
|
||||
$changeForm = $this->hydrateObjectForm($object);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($changeForm);
|
||||
|
||||
return $this->render(
|
||||
'ajax/product-general-tab',
|
||||
array(
|
||||
'product_id' => $this->getRequest()->get('product_id', 0),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attributes ajax tab loading
|
||||
*/
|
||||
@@ -125,9 +101,10 @@ class ProductController extends AbstractCrudController
|
||||
return $this->render(
|
||||
'ajax/product-related-tab',
|
||||
array(
|
||||
'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)
|
||||
'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)
|
||||
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -152,6 +129,10 @@ class ProductController extends AbstractCrudController
|
||||
->setLocale($formData['locale'])
|
||||
->setDefaultCategory($formData['default_category'])
|
||||
->setVisible($formData['visible'])
|
||||
->setBasePrice($formData['price'])
|
||||
->setBaseWeight($formData['weight'])
|
||||
->setCurrencyId($formData['currency'])
|
||||
->setTaxRuleId($formData['tax_rule'])
|
||||
;
|
||||
|
||||
return $createEvent;
|
||||
@@ -171,6 +152,10 @@ class ProductController extends AbstractCrudController
|
||||
->setVisible($formData['visible'])
|
||||
->setUrl($formData['url'])
|
||||
->setDefaultCategory($formData['default_category'])
|
||||
->setBasePrice($formData['price'])
|
||||
->setBaseWeight($formData['weight'])
|
||||
->setCurrencyId($formData['currency'])
|
||||
->setTaxRuleId($formData['tax_rule'])
|
||||
;
|
||||
|
||||
return $changeEvent;
|
||||
@@ -197,6 +182,11 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Get the default produc sales element
|
||||
$salesElement = ProductSaleElementsQuery::create()->filterByProduct($object)->filterByIsDefault(true)->findOne();
|
||||
|
||||
// $prices = $salesElement->getProductPrices();
|
||||
|
||||
// Prepare the data that will hydrate the form
|
||||
$data = array(
|
||||
'id' => $object->getId(),
|
||||
@@ -209,6 +199,8 @@ class ProductController extends AbstractCrudController
|
||||
'visible' => $object->getVisible(),
|
||||
'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()),
|
||||
'default_category' => $object->getDefaultCategoryId()
|
||||
|
||||
// A terminer pour les prix
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
@@ -240,10 +232,10 @@ class ProductController extends AbstractCrudController
|
||||
protected function getEditionArguments()
|
||||
{
|
||||
return array(
|
||||
'category_id' => $this->getCategoryId(),
|
||||
'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),
|
||||
'category_id' => $this->getCategoryId(),
|
||||
'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')
|
||||
);
|
||||
}
|
||||
@@ -478,7 +470,6 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
public function deleteAccessoryAction()
|
||||
{
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
|
||||
|
||||
@@ -508,33 +499,26 @@ class ProductController extends AbstractCrudController
|
||||
*/
|
||||
public function updateAccessoryPositionAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth('admin.products.update')) return $response;
|
||||
$accessory = AccessoryQuery::create()->findPk($this->getRequest()->get('accessory_id', null));
|
||||
|
||||
try {
|
||||
$mode = $this->getRequest()->get('mode', null);
|
||||
|
||||
if ($mode == 'up')
|
||||
$mode = UpdatePositionEvent::POSITION_UP;
|
||||
else if ($mode == 'down')
|
||||
$mode = UpdatePositionEvent::POSITION_DOWN;
|
||||
else
|
||||
$mode = UpdatePositionEvent::POSITION_ABSOLUTE;
|
||||
|
||||
$position = $this->getRequest()->get('position', null);
|
||||
|
||||
$event = new UpdatePositionEvent($this->getRequest()->get('accessory_id', null), $mode, $position);
|
||||
|
||||
$this->dispatch(TheliaEvents::PRODUCT_UPDATE_ACCESSORY_POSITION, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
return $this->genericUpdatePositionAction(
|
||||
$accessory,
|
||||
TheliaEvents::PRODUCT_UPDATE_ACCESSORY_POSITION
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update related content position
|
||||
*/
|
||||
public function updateContentPositionAction()
|
||||
{
|
||||
$content = ProductAssociatedContentQuery::create()->findPk($this->getRequest()->get('content_id', null));
|
||||
|
||||
return $this->genericUpdatePositionAction(
|
||||
$content,
|
||||
TheliaEvents::PRODUCT_UPDATE_CONTENT_POSITION
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change product template for a given product.
|
||||
@@ -636,4 +620,56 @@ class ProductController extends AbstractCrudController
|
||||
// Redirect to the category/product list
|
||||
$this->redirectToListTemplate();
|
||||
}
|
||||
|
||||
public function addAdditionalCategoryAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
|
||||
|
||||
$category_id = intval($this->getRequest()->get('additional_category_id'));
|
||||
|
||||
if ($category_id > 0) {
|
||||
|
||||
$event = new ProductAddCategoryEvent(
|
||||
$this->getExistingObject(),
|
||||
$category_id
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_ADD_CATEGORY, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
|
||||
public function deleteAdditionalCategoryAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
|
||||
|
||||
$category_id = intval($this->getRequest()->get('additional_category_id'));
|
||||
|
||||
if ($category_id > 0) {
|
||||
|
||||
$event = new ProductDeleteCategoryEvent(
|
||||
$this->getExistingObject(),
|
||||
$category_id
|
||||
);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::PRODUCT_REMOVE_CATEGORY, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ class TemplateController extends AbstractCrudController
|
||||
->findOne()
|
||||
;
|
||||
|
||||
return $this->updatePosition(
|
||||
return $this->genericUpdatePositionAction(
|
||||
$attributeTemplate,
|
||||
TheliaEvents::TEMPLATE_CHANGE_ATTRIBUTE_POSITION
|
||||
);
|
||||
@@ -325,41 +325,9 @@ class TemplateController extends AbstractCrudController
|
||||
->findOne()
|
||||
;
|
||||
|
||||
return $this->updatePosition(
|
||||
return $this->genericUpdatePositionAction(
|
||||
$featureTemplate,
|
||||
TheliaEvents::TEMPLATE_CHANGE_FEATURE_POSITION
|
||||
);
|
||||
}
|
||||
|
||||
protected function updatePosition($object, $eventName) {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->updatePermissionIdentifier)) return $response;
|
||||
|
||||
if ($object != null) {
|
||||
|
||||
try {
|
||||
$mode = $this->getRequest()->get('mode', null);
|
||||
|
||||
if ($mode == 'up')
|
||||
$mode = UpdatePositionEvent::POSITION_UP;
|
||||
else if ($mode == 'down')
|
||||
$mode = UpdatePositionEvent::POSITION_DOWN;
|
||||
else
|
||||
$mode = UpdatePositionEvent::POSITION_ABSOLUTE;
|
||||
|
||||
$position = $this->getRequest()->get('position', null);
|
||||
|
||||
$event = new UpdatePositionEvent($object->getId(), $mode, $position);
|
||||
|
||||
$this->dispatch($eventName, $event);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirectToEditionTemplate();
|
||||
}
|
||||
}
|
||||
48
core/lib/Thelia/Core/Event/ProductAddCategoryEvent.php
Normal file
48
core/lib/Thelia/Core/Event/ProductAddCategoryEvent.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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;
|
||||
|
||||
use Thelia\Model\Product;
|
||||
|
||||
class ProductAddCategoryEvent extends ProductEvent
|
||||
{
|
||||
protected $category_id;
|
||||
|
||||
public function __construct(Product $product, $category_id)
|
||||
{
|
||||
parent::__construct($product);
|
||||
|
||||
$this->category_id = $category_id;
|
||||
}
|
||||
|
||||
public function getCategoryId()
|
||||
{
|
||||
return $this->category_id;
|
||||
}
|
||||
|
||||
public function setCategoryId($category_id)
|
||||
{
|
||||
$this->category_id = $category_id;
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,11 @@ class ProductCreateEvent extends ProductEvent
|
||||
protected $default_category;
|
||||
protected $visible;
|
||||
|
||||
protected $basePrice;
|
||||
protected $baseWeight;
|
||||
protected $taxRuleId;
|
||||
protected $currencyId;
|
||||
|
||||
public function getRef()
|
||||
{
|
||||
return $this->ref;
|
||||
@@ -85,4 +90,48 @@ class ProductCreateEvent extends ProductEvent
|
||||
$this->visible = $visible;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBasePrice()
|
||||
{
|
||||
return $this->basePrice;
|
||||
}
|
||||
|
||||
public function setBasePrice($basePrice)
|
||||
{
|
||||
$this->basePrice = $basePrice;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBaseWeight()
|
||||
{
|
||||
return $this->baseWeight;
|
||||
}
|
||||
|
||||
public function setBaseWeight($baseWeight)
|
||||
{
|
||||
$this->baseWeight = $baseWeight;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTaxRuleId()
|
||||
{
|
||||
return $this->taxRuleId;
|
||||
}
|
||||
|
||||
public function setTaxRuleId($taxRuleId)
|
||||
{
|
||||
$this->taxRuleId = $taxRuleId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCurrencyId()
|
||||
{
|
||||
return $this->currencyId;
|
||||
}
|
||||
|
||||
public function setCurrencyId($currencyId)
|
||||
{
|
||||
$this->currencyId = $currencyId;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
50
core/lib/Thelia/Core/Event/ProductDeleteCategoryEvent.php
Normal file
50
core/lib/Thelia/Core/Event/ProductDeleteCategoryEvent.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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;
|
||||
use Thelia\Model\Product;
|
||||
|
||||
class ProductDeleteCategoryEvent extends ProductEvent
|
||||
{
|
||||
protected $category_id;
|
||||
|
||||
public function __construct(Product $product, $category_id)
|
||||
{
|
||||
parent::__construct($product);
|
||||
|
||||
$this->category_id = $category_id;
|
||||
}
|
||||
|
||||
public function getCategoryId()
|
||||
{
|
||||
return $this->category_id;
|
||||
}
|
||||
|
||||
public function setCategoryId($category_id)
|
||||
{
|
||||
$this->category_id = $category_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -184,17 +184,21 @@ final class TheliaEvents
|
||||
const PRODUCT_TOGGLE_VISIBILITY = "action.toggleProductVisibility";
|
||||
const PRODUCT_UPDATE_POSITION = "action.updateProductPosition";
|
||||
|
||||
const PRODUCT_ADD_CONTENT = "action.productAddContent";
|
||||
const PRODUCT_REMOVE_CONTENT = "action.productRemoveContent";
|
||||
const PRODUCT_ADD_CONTENT = "action.productAddContent";
|
||||
const PRODUCT_REMOVE_CONTENT = "action.productRemoveContent";
|
||||
const PRODUCT_UPDATE_CONTENT_POSITION = "action.updateProductContentPosition";
|
||||
|
||||
const PRODUCT_SET_TEMPLATE = "action.productSetTemplate";
|
||||
|
||||
const PRODUCT_ADD_ACCESSORY = "action.productAddAccessory";
|
||||
const PRODUCT_REMOVE_ACCESSORY = "action.productRemoveAccessory";
|
||||
const PRODUCT_UPDATE_ACCESSORY_POSITION = "action.updateProductPosition";
|
||||
const PRODUCT_ADD_ACCESSORY = "action.productAddProductAccessory";
|
||||
const PRODUCT_REMOVE_ACCESSORY = "action.productRemoveProductAccessory";
|
||||
const PRODUCT_UPDATE_ACCESSORY_POSITION = "action.updateProductAccessoryPosition";
|
||||
|
||||
const PRODUCT_FEATURE_UPDATE_VALUE = "action.after_updateProductFeatureValue";
|
||||
const PRODUCT_FEATURE_DELETE_VALUE = "action.after_deleteProductFeatureValue";
|
||||
const PRODUCT_FEATURE_UPDATE_VALUE = "action.updateProductFeatureValue";
|
||||
const PRODUCT_FEATURE_DELETE_VALUE = "action.deleteProductFeatureValue";
|
||||
|
||||
const PRODUCT_ADD_CATEGORY = "action.addProductCategory";
|
||||
const PRODUCT_REMOVE_CATEGORY = "action.deleteProductCategory";
|
||||
|
||||
const BEFORE_CREATEPRODUCT = "action.before_createproduct";
|
||||
const AFTER_CREATEPRODUCT = "action.after_createproduct";
|
||||
|
||||
@@ -74,6 +74,7 @@ class Accessory extends Product
|
||||
$search = AccessoryQuery::create();
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
$search->filterByProductId($product, Criteria::IN);
|
||||
|
||||
$order = $this->getOrder();
|
||||
@@ -93,10 +94,16 @@ class Accessory extends Product
|
||||
$accessories = $this->search($search);
|
||||
|
||||
$accessoryIdList = array(0);
|
||||
$accessoryPosition = array();
|
||||
$accessoryPosition = $accessoryId = array();
|
||||
|
||||
foreach ($accessories as $accessory) {
|
||||
array_push($accessoryIdList, $accessory->getAccessory());
|
||||
$accessoryPosition[$accessory->getAccessory()] = $accessory->getPosition();
|
||||
|
||||
$accessoryProductId = $accessory->getAccessory();
|
||||
|
||||
array_push($accessoryIdList, $accessoryProductId);
|
||||
|
||||
$accessoryPosition[$accessoryProductId] = $accessory->getPosition();
|
||||
$accessoryId[$accessoryProductId] = $accessory->getId();
|
||||
}
|
||||
|
||||
$receivedIdList = $this->getId();
|
||||
@@ -111,12 +118,15 @@ class Accessory extends Product
|
||||
$loopResult = parent::exec($pagination);
|
||||
|
||||
foreach($loopResult as $loopResultRow) {
|
||||
|
||||
$accessoryProductId = $loopResultRow->get('ID');
|
||||
|
||||
$loopResultRow
|
||||
->set("POSITION" , $accessoryPosition[$loopResultRow->get('ID')])
|
||||
;
|
||||
->set("ID" , $accessoryId[$accessoryProductId])
|
||||
->set("POSITION", $accessoryPosition[$accessoryProductId])
|
||||
;
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -135,8 +135,17 @@ class AssociatedContent extends Content
|
||||
$associatedContents = $this->search($search);
|
||||
|
||||
$associatedContentIdList = array(0);
|
||||
|
||||
$contentIdList = array(0);
|
||||
$contentPosition = $contentId = array();
|
||||
|
||||
foreach ($associatedContents as $associatedContent) {
|
||||
array_push($associatedContentIdList, $associatedContent->getContentId());
|
||||
|
||||
$associatedContentId = $associatedContent->getContentId();
|
||||
|
||||
array_push($associatedContentIdList, $associatedContentId);
|
||||
$contentPosition[$associatedContentId] = $associatedContent->getPosition();
|
||||
$contentId[$associatedContentId] = $associatedContent->getId();
|
||||
}
|
||||
|
||||
$receivedIdList = $this->getId();
|
||||
@@ -148,7 +157,18 @@ class AssociatedContent extends Content
|
||||
$this->args->get('id')->setValue( implode(',', array_intersect($receivedIdList, $associatedContentIdList)) );
|
||||
}
|
||||
|
||||
return parent::exec($pagination);
|
||||
}
|
||||
$loopResult = parent::exec($pagination);
|
||||
|
||||
foreach($loopResult as $loopResultRow) {
|
||||
|
||||
$relatedContentId = $loopResultRow->get('ID');
|
||||
|
||||
$loopResultRow
|
||||
->set("ID" , $contentId[$relatedContentId])
|
||||
->set("POSITION", $contentPosition[$relatedContentId])
|
||||
;
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,12 +121,15 @@ class Attribute extends BaseI18nLoop
|
||||
// Create template array
|
||||
if ($template == null) $template = array();
|
||||
|
||||
foreach($products as $product)
|
||||
$template[] = $product->getTemplateId();
|
||||
foreach($products as $product) {
|
||||
$tpl_id = $product->getTemplateId();
|
||||
|
||||
if (! is_null($tpl_id)) $template[] = $tpl_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $template) {
|
||||
if (! empty($template)) {
|
||||
|
||||
// Join with feature_template table to get position
|
||||
$search
|
||||
|
||||
@@ -35,6 +35,7 @@ use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
use Thelia\Type\BooleanOrBothType;
|
||||
use Thelia\Model\ProductQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -73,6 +74,8 @@ class Category extends BaseI18nLoop
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createIntTypeArgument('parent'),
|
||||
Argument::createIntTypeArgument('product'),
|
||||
Argument::createIntTypeArgument('exclude_product'),
|
||||
Argument::createBooleanTypeArgument('current'),
|
||||
Argument::createBooleanTypeArgument('not_empty', 0),
|
||||
Argument::createBooleanOrBothTypeArgument('visible', 1),
|
||||
@@ -128,6 +131,22 @@ class Category extends BaseI18nLoop
|
||||
if ($this->getVisible() != BooleanOrBothType::ANY)
|
||||
$search->filterByVisible($this->getVisible() ? 1 : 0);
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
if ($product != null) {
|
||||
$obj = ProductQuery::create()->findPk($product);
|
||||
|
||||
if ($obj != null) $search->filterByProduct($obj, Criteria::IN);
|
||||
}
|
||||
|
||||
$exclude_product = $this->getExclude_product();
|
||||
|
||||
if ($exclude_product != null) {
|
||||
$obj = ProductQuery::create()->findPk($exclude_product);
|
||||
|
||||
if ($obj != null) $search->filterByProduct($obj, Criteria::NOT_IN);
|
||||
}
|
||||
|
||||
$orders = $this->getOrder();
|
||||
|
||||
foreach ($orders as $order) {
|
||||
|
||||
@@ -124,12 +124,15 @@ class Feature extends BaseI18nLoop
|
||||
// Create template array
|
||||
if ($template == null) $template = array();
|
||||
|
||||
foreach($products as $product)
|
||||
$template[] = $product->getTemplateId();
|
||||
foreach($products as $product) {
|
||||
$tpl_id = $product->getTemplateId();
|
||||
|
||||
if (! is_null($tpl_id)) $template[] = $tpl_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $template) {
|
||||
if (! empty($template)) {
|
||||
|
||||
// Join with feature_template table to get position
|
||||
$search
|
||||
|
||||
@@ -47,23 +47,43 @@ class ProductCreationForm extends BaseForm
|
||||
"label_attr" => array("for" => "ref")
|
||||
))
|
||||
->add("title", "text", array(
|
||||
// "constraints" => array(new NotBlank()),
|
||||
"constraints" => array(new NotBlank()),
|
||||
"label" => "Product title *",
|
||||
"label_attr" => array("for" => "title")
|
||||
))
|
||||
->add("default_category", "integer", array(
|
||||
// "constraints" => array(new NotBlank()),
|
||||
"label" => Translator::getInstance()->trans("Default product category."),
|
||||
"constraints" => array(new NotBlank()),
|
||||
"label" => Translator::getInstance()->trans("Default product category *"),
|
||||
"label_attr" => array("for" => "default_category_field")
|
||||
))
|
||||
->add("locale", "text", array(
|
||||
//"constraints" => array(new NotBlank())
|
||||
"constraints" => array(new NotBlank())
|
||||
))
|
||||
->add("visible", "integer", array(
|
||||
"label" => Translator::getInstance()->trans("This product is online."),
|
||||
"label" => Translator::getInstance()->trans("This product is online"),
|
||||
"label_attr" => array("for" => "visible_field")
|
||||
))
|
||||
;
|
||||
->add("price", "number", array(
|
||||
"constraints" => array(new NotBlank()),
|
||||
"label" => Translator::getInstance()->trans("Product base price excluding taxes *"),
|
||||
"label_attr" => array("for" => "price_field")
|
||||
))
|
||||
->add("currency", "integer", array(
|
||||
"constraints" => array(new NotBlank()),
|
||||
"label" => Translator::getInstance()->trans("Price currency *"),
|
||||
"label_attr" => array("for" => "currency_field")
|
||||
))
|
||||
->add("tax_rule", "integer", array(
|
||||
"constraints" => array(new NotBlank()),
|
||||
"label" => Translator::getInstance()->trans("Tax rule for this product *"),
|
||||
"label_attr" => array("for" => "tax_rule_field")
|
||||
))
|
||||
->add("weight", "number", array(
|
||||
"constraints" => array(new NotBlank()),
|
||||
"label" => Translator::getInstance()->trans("Weight *"),
|
||||
"label_attr" => array("for" => "weight_field")
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
public function checkDuplicateRef($value, ExecutionContextInterface $context)
|
||||
|
||||
@@ -98,7 +98,8 @@ class Product extends BaseProduct
|
||||
->filterByDefaultCategory(true)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
var_dump($productCategory);
|
||||
exit;
|
||||
if ($productCategory == null || $productCategory->getCategoryId() != $defaultCategoryId) {
|
||||
|
||||
// Delete the old default category
|
||||
@@ -120,8 +121,13 @@ class Product extends BaseProduct
|
||||
* Create a new product, along with the default category ID
|
||||
*
|
||||
* @param int $defaultCategoryId the default category ID of this product
|
||||
* @param float $basePrice the product base price
|
||||
* @param int $priceCurrencyId the price currency Id
|
||||
* @param int $taxRuleId the product tax rule ID
|
||||
* @param float $baseWeight base weight in Kg
|
||||
*/
|
||||
public function create($defaultCategoryId) {
|
||||
|
||||
public function create($defaultCategoryId, $basePrice, $priceCurrencyId, $taxRuleId, $baseWeight) {
|
||||
|
||||
$con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
|
||||
|
||||
@@ -139,6 +145,8 @@ class Product extends BaseProduct
|
||||
// Set the position
|
||||
$this->setPosition($this->getNextPosition())->save($con);
|
||||
|
||||
$this->setTaxRuleId($taxRuleId);
|
||||
|
||||
// Create an empty product sale element
|
||||
$sale_elements = new ProductSaleElements();
|
||||
|
||||
@@ -147,7 +155,8 @@ class Product extends BaseProduct
|
||||
->setRef($this->getRef())
|
||||
->setPromo(0)
|
||||
->setNewness(0)
|
||||
->setWeight(0)
|
||||
->setWeight($baseWeight)
|
||||
->setIsDefault(true)
|
||||
->save($con)
|
||||
;
|
||||
|
||||
@@ -156,9 +165,9 @@ class Product extends BaseProduct
|
||||
|
||||
$product_price
|
||||
->setProductSaleElements($sale_elements)
|
||||
->setPromoPrice(0)
|
||||
->setPrice(0)
|
||||
->setCurrency(CurrencyQuery::create()->findOneByByDefault(true))
|
||||
->setPromoPrice($basePrice)
|
||||
->setPrice($basePrice)
|
||||
->setCurrencyId($priceCurrencyId)
|
||||
->save($con)
|
||||
;
|
||||
|
||||
|
||||
@@ -11,11 +11,22 @@ class ProductAssociatedContent extends BaseProductAssociatedContent {
|
||||
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our product
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByProductId($this->getProductId());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT_ASSOCIATED_CONTENT, new ProductAssociatedContentEvent($this));
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user