Fixed product update process

This commit is contained in:
franck
2013-09-20 17:17:44 +02:00
parent 5622a246b2
commit 1cf8c87d1a
8 changed files with 69 additions and 33 deletions

View File

@@ -53,6 +53,7 @@ use Thelia\Model\FeatureProduct;
use Thelia\Model\FeatureQuery;
use Thelia\Core\Event\FeatureProductDeleteEvent;
use Thelia\Model\FeatureProductQuery;
use Thelia\Model\ProductCategoryQuery;
class Product extends BaseAction implements EventSubscriberInterface
{
@@ -101,11 +102,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);
}
@@ -293,6 +299,7 @@ echo " Create !";
else {
$featureProduct->setFeatureAvId($event->getFeatureValue());
}
echo "value=".$event->getFeatureValue();
$featureProduct->save();
@@ -311,7 +318,7 @@ echo " Create !";
->delete();
;
echo "<br/>Delete p=".$event->getProductId()." f=".$event->getFeatureId();
echo "<br/>Delete p=".$event->getProductId().", f=".$event->getFeatureId();
$event->setFeatureProduct($featureProduct);
}

View File

@@ -114,7 +114,7 @@ class ProductController extends AbstractCrudController
->setPostscriptum($formData['postscriptum'])
->setVisible($formData['visible'])
->setUrl($formData['url'])
->setParent($formData['parent'])
->setDefaultCategory($formData['default_category'])
;
return $changeEvent;
@@ -144,6 +144,7 @@ class ProductController extends AbstractCrudController
// Prepare the data that will hydrate the form
$data = array(
'id' => $object->getId(),
'ref' => $object->getRef(),
'locale' => $object->getLocale(),
'title' => $object->getTitle(),
'chapo' => $object->getChapo(),
@@ -500,7 +501,7 @@ class ProductController extends AbstractCrudController
// Update all features values
$featureValues = $this->getRequest()->get('feature_value', array());
print_r($featureValues);
echo "<br />list: "; print_r($featureValues);
foreach($featureValues as $featureId => $featureValueList) {
// Delete all values for this feature.
@@ -520,7 +521,7 @@ print_r($featureValues);
// Update then features text values
$featureTextValues = $this->getRequest()->get('feature_text_value', array());
print_r($featureTextValues);
echo "<br />free text"; print_r($featureTextValues);
foreach($featureTextValues as $featureId => $featureValue) {
// considere empty text as empty feature value (e.g., we will delete it)
@@ -537,7 +538,7 @@ print_r($featureTextValues);
foreach($allFeatures as $feature) {
if (! in_array($feature->getId(), $updatedFeatures)) {
$event = new FeatureProductDeleteEvent($productId, $feature->getId());
echo "delete $productId, ".$feature->getId()." - ";
echo "<br />delete $productId, ".$feature->getId()." - ";
$this->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $event);
}
}

View File

@@ -70,6 +70,9 @@ class UrlGenerator extends AbstractSmartyPlugin
$mode
);
// FIXME: potentially dangerous ?
$url = str_replace('&', '&amp;', $url);
if ($target != null) $url .= '#'.$target;
return $url;

View File

@@ -47,19 +47,17 @@ 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()),
// "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."),

View File

@@ -87,6 +87,32 @@ class Product extends BaseProduct
return $this;
}
public function updateDefaultCategory($defaultCategoryId) {
// Update the default category
$productCategory = ProductCategoryQuery::create()
->filterByProductId($this->getId())
->filterByDefaultCategory(true)
->findOne()
;
if ($productCategory == null || $productCategory->getCategoryId() != $defaultCategoryId) {
// Delete the old default category
if ($productCategory !== null) $productCategory->delete();
// Add the new default category
$productCategory = new ProductCategory();
$productCategory
->setProduct($this)
->setCategoryId($defaultCategoryId)
->setDefaultCategory(true)
->save($con)
;
}
}
/**
* Create a new product, along with the default category ID
*
@@ -105,14 +131,7 @@ class Product extends BaseProduct
$this->save($con);
// Add the default category
$pc = new ProductCategory();
$pc
->setProduct($this)
->setCategoryId($defaultCategoryId)
->setDefaultCategory(true)
->save($con)
;
$this->updateDefaultCategory($defaultCategoryId);
// Set the position
$this->setPosition($this->getNextPosition())->save($con);

View File

@@ -29,7 +29,7 @@ Parameters:
{$dialog_message nofilter}
</div>
<form method="{$form_method|default:POST}" action="{$form_action}" id="{$form_id}">
<form method="{$form_method|default:POST}" action="{$form_action}" id="{$form_id|default:"{$dialog_id}_form"}">
{$form_content nofilter}

View File

@@ -28,7 +28,7 @@
{/loop}
</select>
<span class="input-group-btn" id="content_add_button">
<span class="input-group-btn" id="apply_template_button">
<button class="btn btn-default btn-primary action-btn" type="button">{intl l="Apply this template"}</button>
</span>
</div>
@@ -37,7 +37,7 @@
{ifloop rel="product_template"}
{* -- Begin attributes management ----------------------------------- *}
{* -- Begin attributes management ------------------------------- *}
<div class="row">
{loop name="product_template" type="template" id={$TEMPLATE|default:0}}{/loop}
@@ -45,14 +45,13 @@
<div class="col-md-12">
<div class="form-group">
<p class="title title-without-tabs">{intl l='Product Attributes'}</p>
<p>{intl l='You can attach here some content to this product'}</p>
</div>
</div>
</div>
{* -- End attributes management -------------------------------------- *}
{* -- End attributes management ---------------------------------- *}
{* -- Begin features management -------------------------------------- *}
{* -- Begin features management ---------------------------------- *}
<div class="row">
<div class="col-md-12">
@@ -139,9 +138,9 @@
</div>
</div>
{* -- End features management --------- *}
{/ifloop}
</div>
{* -- End features management ------------------------------- *}
</div>
{/ifloop}
{elseloop rel="product_template"}
<div class="row">

View File

@@ -12,6 +12,10 @@
{form_hidden_fields form=$form}
{form_field form=$form field='id'}
<input type="hidden" name="{$name}" value="{$value}" />
{/form_field}
{form_field form=$form field='success_url'}
<input type="hidden" name="{$name}" value="{url path='/admin/product' product_id={$product_d}}" />
{/form_field}
@@ -23,11 +27,16 @@
{if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}
<div class="form-group">
<label for="product_ref" class="control-label">
<label class="control-label">
{intl l='Product reference'} :
</label>
<div class="well well-sm">{$REF}</div>
{form_field form=$form field='ref'}
<input type="hidden" name="{$name}" value="{$value}" />
{/form_field}
</div>
{include file="includes/standard-description-form-fields.html"}
@@ -56,7 +65,7 @@
<option value="0">{intl l="Top level"}</option>
{loop name="cat-parent" type="category-tree" category="0" visible="*" product="0"}
<option value="{$ID}" style="padding-left: {3 + $LEVEL * 20}px" {if $DEFAULT_CATEGORY == $ID}selected="selected"{/if} {if $product_id == $ID}disabled="disabled"{/if}>{$TITLE}</option>
<option value="{$ID}" style="padding-left: {3 + $LEVEL * 20}px" {if $DEFAULT_CATEGORY == $ID}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
@@ -84,7 +93,7 @@
<div class="row">
<div class="col-md-12">
<div class="control-group">
<lablel>&nbsp;</lablel>
<label>&nbsp;</label>
<div class="controls">
<p>{intl l='Product created on %date_create. Last modification: %date_change' date_create="{format_date date=$CREATE_DATE}" date_change="{format_date date=$UPDATE_DATE}"}</p>
</div>