Merge branch 'catalog' of https://github.com/thelia/thelia into upload_management

# By franck
# Via franck
* 'catalog' of https://github.com/thelia/thelia:
  Finished product combination basic function
  Formatted combination table
This commit is contained in:
gmorel
2013-09-24 18:41:57 +02:00
9 changed files with 392 additions and 260 deletions

View File

@@ -56,7 +56,6 @@ 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;
@@ -66,6 +65,9 @@ use Thelia\Model\AttributeCombination;
use Thelia\Core\Event\ProductCreateCombinationEvent;
use Propel\Runtime\Propel;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Core\Event\ProductDeleteCombinationEvent;
use Thelia\Model\ProductPrice;
use Thelia\Model\ProductSaleElements;
class Product extends BaseAction implements EventSubscriberInterface
{
@@ -367,19 +369,31 @@ class Product extends BaseAction implements EventSubscriberInterface
$con->beginTransaction();
try {
$product = $event->getProduct();
if ($event->getUseDefaultPricing()) {
// Get the default pricing
$salesElement = ProductSaleElementsQuery::create()->filterByIsDefault(true)->findOne();
}
else {
// We have to create a new ProductSaleElement
echo "no default !!!!";
exit;
}
// Create an empty product sale element
$salesElement = new ProductSaleElements();
if (null == $salesElement)
throw new \LogicException("Cannot create or get the product sales element for this new combination.");
$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();
@@ -412,6 +426,13 @@ class Product extends BaseAction implements EventSubscriberInterface
}
}
public function deleteProductCombination(ProductDeleteCombinationEvent $event) {
if (null !== $pse = ProductSaleElementsQuery::create()->findPk($event->getProductSaleElementId())) {
$pse->delete();
}
}
/**
* {@inheritDoc}
*/

View File

@@ -223,7 +223,7 @@
<default key="_controller">Thelia\Controller\Admin\ProductController::loadGeneralAjaxTabAction</default>
</route>
<!-- Product associations, categories, content and accessories -->
<!-- Product categories, content and accessories -->
<route id="admin.products.related.tab" path="/admin/products/related/tab">
<default key="_controller">Thelia\Controller\Admin\ProductController::loadRelatedAjaxTabAction</default>
@@ -311,6 +311,16 @@
<default key="_controller">Thelia\Controller\Admin\ProductController::deleteCombinationAction</default>
</route>
<route id="admin.product.combination.update" path="/admin/product/combination/update">
<default key="_controller">Thelia\Controller\Admin\ProductController::updateCombinationAction</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>
</route>
<!-- Folder routes management -->

View File

@@ -42,6 +42,7 @@ use Thelia\Log\Tlog;
use Symfony\Component\Routing\Router;
use Thelia\Model\Admin;
use Thelia\Core\Security\Token\CookieTokenProvider;
use Thelia\Model\CurrencyQuery;
class BaseAdminController extends BaseController
{
@@ -258,7 +259,7 @@ class BaseAdminController extends BaseController
// Return the new language if a change is required.
if (null !== $edit_currency_id = $this->getRequest()->get('edit_currency_id', null)) {
if (null !== $edit_currency = LangQuery::create()->findOneById($edit_currency_id)) {
if (null !== $edit_currency = CurrencyQuery::create()->findOneById($edit_currency_id)) {
return $edit_currency;
}
}

View File

@@ -56,6 +56,7 @@ use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Model\AttributeCombination;
use Thelia\Model\AttributeAv;
use Thelia\Core\Event\ProductCreateCombinationEvent;
use Thelia\Core\Event\ProductDeleteCombinationEvent;
/**
* Manages products
@@ -753,8 +754,8 @@ class ProductController extends AbstractCrudController
$event = new ProductCreateCombinationEvent(
$this->getExistingObject(),
$this->getRequest()->get('use_default_princing', 0),
$this->getRequest()->get('combination_attributes', array())
$this->getRequest()->get('combination_attributes', array()),
$this->getCurrentEditionCurrency()->getId()
);
try {
@@ -764,8 +765,33 @@ class ProductController extends AbstractCrudController
// Any error
return $this->errorPage($ex);
}
echo "done!";
exit;
$this->redirectToEditionTemplate();
}
/**
* A a new combination to a product
*/
public function deleteCombinationAction() {
// Check current user authorization
if (null !== $response = $this->checkAuth("admin.products.update")) return $response;
$event = new ProductDeleteCombinationEvent(
$this->getExistingObject(),
$this->getRequest()->get('product_sale_element_id',0)
);
try {
$this->dispatch(TheliaEvents::PRODUCT_DELETE_COMBINATION, $event);
}
catch (\Exception $ex) {
// Any error
return $this->errorPage($ex);
}
$this->redirectToEditionTemplate();
}
}

View File

@@ -22,31 +22,19 @@
/*************************************************************************************/
namespace Thelia\Core\Event;
use Thelia\Model\Product;
class ProductCreateCombinationEvent extends ProductEvent
{
protected $use_default_pricing;
protected $attribute_av_list;
protected $currency_id;
public function __construct(Product $product, $use_default_pricing, $attribute_av_list)
public function __construct(Product $product, $attribute_av_list, $currency_id)
{
parent::__construct($product);
$this->use_default_pricing = $use_default_pricing;
$this->attribute_av_list = $attribute_av_list;
}
public function getUseDefaultPricing()
{
return $this->use_default_pricing;
}
public function setUseDefaultPricing($use_default_pricing)
{
$this->use_default_pricing = $use_default_pricing;
return $this;
$this->currency_id = $currency_id;
}
public function getAttributeAvList()
@@ -60,4 +48,17 @@ class ProductCreateCombinationEvent extends ProductEvent
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,47 @@
<?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 ProductDeleteCombinationEvent extends ProductEvent
{
protected $product_sale_element_id;
public function __construct(Product $product, $product_sale_element_id)
{
parent::__construct($product);
$this->product_sale_element_id = $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;
}
}

View File

@@ -175,6 +175,7 @@ class ProductSaleElements extends BaseLoop
->set("QUANTITY" , $PSEValue->getQuantity())
->set("IS_PROMO" , $PSEValue->getPromo() === 1 ? 1 : 0)
->set("IS_NEW" , $PSEValue->getNewness() === 1 ? 1 : 0)
->set("IS_DEFAULT" , $PSEValue->getIsDefault() === 1 ? 1 : 0)
->set("WEIGHT" , $PSEValue->getWeight())
->set("PRICE" , $price)
->set("PRICE_TAX" , $taxedPrice - $price)

View File

@@ -1,7 +1,11 @@
<div class="form-container">
{loop name="product.sales.elements.test" type="product_sale_elements" product=$product_id currency=$edit_currency_id backend_context="1"}
{/loop}
{elseloop rel="product.sales.elements.test"}
{form name="thelia.admin.product.details.modification"}
<form method="POST" action="{url path='/admin/products/details/save'}" {form_enctype form=$form} class="clearfix">
<form method="POST" action="{url path='/admin/product/default-price/update'}" {form_enctype form=$form} class="clearfix">
{include
file = "includes/inner-form-toolbar.html"
@@ -173,15 +177,25 @@
</div>
</form>
{/form}
{/elseloop}
{* -- Attribute combinations -------------------------------------------- *}
{module_include location='product_before_combinations'}
<div class="row">
<div class="col-md-12">
<div class="well well-sm">
{ifloop rel="product.sales.elements"}
<form method="POST" action="{url path='/admin/product/combinations/update'}">
{include
file = "includes/inner-form-toolbar.html"
hide_submit_buttons = false
show_currencies = true
page_url = "{url path='/admin/products/update' product_id=$ID}"
close_url = "{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}"
}
{module_include location='product_before_combinations'}
<table class="table table-striped table-condensed" id="category_list">
<caption>
@@ -203,6 +217,7 @@
<th class="text-center">{intl l='Price<br />w/o taxes (%currency)' currency=$currency_symbol}</th>
<th class="text-center">{intl l='Price<br />w/ taxes (%currency)' currency=$currency_symbol}</th>
<th class="text-center">{intl l='Weight (Kg)'}</th>
<th class="text-center">{intl l='Default'}</th>
<th class="text-center">{intl l='Is new'}</th>
<th class="text-center">{intl l='On sale'}</th>
<th class="text-center">{intl l='Sale price<br />w/o taxes (%currency)' currency=$currency_symbol}</th>
@@ -212,32 +227,32 @@
</thead>
<tbody>
{loop name="product.sales.elements" type="product_sale_elements" product=$product_id currency=$edit_currency_id}
{loop name="product.sales.elements" type="product_sale_elements" product=$product_id currency=$edit_currency_id backend_context="1"}
<tr>
<td>
{loop name="product.sales.elements.combinations" type="attribute_combination" product_sale_elements=$ID}
{loop name="product.sales.elements.combinations" type="attribute_combination" product_sale_elements=$ID backend_context="1"}
{$ATTRIBUTE_TITLE}&nbsp;
{/loop}
</td>
<td><input class="form-control text-right" type="text" name="quantity[{$ID}]" value="{format_number number=$QUANTITY}" /></td>
<td><input class="form-control text-right" type="text" name="price_wo_taxes[{$ID}]" value="{format_number number=$PRICE_TAX}" /></td>
<td><input class="form-control text-right" type="text" name="quantity[{$ID}]" value="{$QUANTITY}" /></td>
<td><input class="form-control text-right" type="text" name="price_wo_taxes[{$ID}]" value="{format_number number=$PRICE}" /></td>
<td><input class="form-control text-right" type="text" name="price_w_taxes[{$ID}]" value="{format_number number=$TAXED_PRICE}" /></td>
<td><input class="form-control text-right" type="text" name="weight[{$ID}]" value="{format_number number=$WEIGHT}" /></td>
<td><input class="form-control text-right" type="text" name="weight[{$ID}]" value="{$WEIGHT}" /></td>
<td>
<div class="make-switch switch-small" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input class="change-default" type="radio" name="on_sale[{$ID}]" value="{$ID}" {if $IS_PROMO}checked="checked"{/if}/>
</div>
<td class="text-center">
<input class="form-control" type="radio" name="default" value="{$ID}" {if $IS_DEFAULT}checked="checked"{/if}/>
</td>
<td>
<div class="make-switch switch-small" data-on="success" data-off="danger" data-on-label="<i class='glyphicon glyphicon-ok'></i>" data-off-label="<i class='glyphicon glyphicon-remove'></i>">
<input class="change-default" type="radio" name="is_new[{$ID}]" value="{$ID}" {if $IS_NEW}checked="checked"{/if}/>
</div>
<td class="text-center">
<input class="form-control" type="checkbox" name="on_sale[{$ID}]" value="{$ID}" {if $IS_PROMO}checked="checked"{/if}/>
</td>
<td><input class="form-control text-right" type="text" name="sale_price_wo_taxes[{$ID}]" value="{format_number number=$PROMO_PRICE_TAX}" /></td>
<td class="text-center">
<input class="form-control" type="checkbox" name="is_new[{$ID}]" value="{$ID}" {if $IS_NEW}checked="checked"{/if}/>
</td>
<td><input class="form-control text-right" type="text" name="sale_price_wo_taxes[{$ID}]" value="{format_number number=$PROMO_PRICE}" /></td>
<td><input class="form-control text-right" type="text" name="sale_price_w_taxes[{$ID}]" value="{format_number number=$TAXED_PROMO_PRICE}" /></td>
<td class="actions">
@@ -247,12 +262,28 @@
{/loop}
</tbody>
</table>
</div>
</div>
</div>
{module_include location='product_after_combinations'}
</div>
</form>
{/ifloop}
{elseloop rel="product.sales.elements"}
<p class="title title-without-tabs">{intl l='Attribute Combinations'}</p>
<div class="alert alert-info">
{intl
l='This product has no combination. The default price is used. <a data-toggle="modal" href="%url">Click here to create a new combination</a>'
url='#combination_creation_dialog'
}
</div>
{/elseloop}
{module_include location='product_after_combinations'}
</div>
</div>
</div>
{* -- Adding a new combination ------------------------------------------------- *}
@@ -314,17 +345,6 @@
</div>
</div>
{form_field form=$form field='isnew'}
<div class="form-group {if $error}has-error{/if}">
<div class="checkbox">
<label>
<input type="checkbox" id="use_default_princing" name="use_default_princing" value="1">
{intl l="Use default princing for this combination (you can change this later)"}
</label>
</div>
</div>
{/form_field}
{/capture}
{include
@@ -351,7 +371,7 @@
<input type="hidden" name="product_id" value="{$product_id}" />
<input type="hidden" name="current_tab" value="details" />
<input type="hidden" name="combination_id" id="combination_delete_id" value="" />
<input type="hidden" name="product_sale_element_id" id="combination_delete_id" value="" />
{module_include location='category_delete_form'}

View File

@@ -135,6 +135,11 @@
<script src="{$asset_url}"></script>
{/javascripts}
{javascripts file='assets/js/bootstrap-switch/bootstrap-switch.js'}
<script src="{$asset_url}"></script>
{/javascripts}
<script src="{url file='/tinymce/tinymce.min.js'}"></script>
<script>
tinymce.init({