Started price tab

This commit is contained in:
franck
2013-09-23 00:57:03 +02:00
parent 22f3f49f79
commit 8781721512
12 changed files with 431 additions and 133 deletions

View File

@@ -60,6 +60,7 @@
<form name="thelia.admin.product.creation" class="Thelia\Form\ProductCreationForm"/>
<form name="thelia.admin.product.modification" class="Thelia\Form\ProductModificationForm"/>
<form name="thelia.admin.product.details.modification" class="Thelia\Form\ProductDetailsModificationForm"/>
<form name="thelia.admin.product.creation" class="Thelia\Form\ProductCreationForm"/>
<form name="thelia.admin.product.deletion" class="Thelia\Form\ProductModificationForm"/>

View File

@@ -250,6 +250,23 @@ class BaseAdminController extends BaseController
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute($routeId), $urlParameters));
}
/**
* Get the current edition currency ID, checking if a change was requested in the current request.
*/
protected function getCurrentEditionCurrency()
{
// 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)) {
return $edit_currency;
}
}
// Otherwise return the lang stored in session.
return $this->getSession()->getAdminEditionCurrency();
}
/**
* Get the current edition lang ID, checking if a change was requested in the current request.
*/
@@ -376,6 +393,9 @@ class BaseAdminController extends BaseController
// Find the current edit language ID
$edition_language = $this->getCurrentEditionLang();
// Find the current edit currency ID
$edition_currency = $this->getCurrentEditionCurrency();
// Prepare common template variables
$args = array_merge($args, array(
'locale' => $session->getLang()->getLocale(),
@@ -385,11 +405,16 @@ class BaseAdminController extends BaseController
'edit_language_id' => $edition_language->getId(),
'edit_language_locale' => $edition_language->getLocale(),
'edit_currency_id' => $edition_currency->getId(),
'current_url' => $this->getRequest()->getUri()
));
// Update the current edition language in session
$this->getSession()->setAdminEditionLang($edition_language);
// Update the current edition language & currency in session
$this->getSession()
->setAdminEditionLang($edition_language)
->setAdminEditionCurrency($edition_currency)
;
// Render the template.
try {

View File

@@ -152,11 +152,7 @@ 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;
}

View File

@@ -65,23 +65,6 @@ class Session extends BaseSession
return $this;
}
public function getAdminEditionLang()
{
$lang = $this->get('thelia.admin.edition.lang');
if (null === $lang) {
$lang = Lang::getDefaultLanguage();
}
return $lang;
}
public function setAdminEditionLang($langId)
{
$this->set('thelia.admin.edition.lang', $langId);
return $this;
}
public function setCurrency(Currency $currency)
{
$this->set("thelia.current.currency", $currency);
@@ -98,6 +81,43 @@ class Session extends BaseSession
return $currency;
}
// -- Admin lang and currency ----------------------------------------------
public function getAdminEditionCurrency()
{
$currency = $this->get('thelia.admin.edition.currency', null);
if (null === $currency) {
$currency = Currency::getDefaultCurrency();
}
return $currency;
}
public function setAdminEditionCurrency($currencyId)
{
$this->set('thelia.admin.edition.currency', $currencyId);
return $this;
}
public function getAdminEditionLang()
{
$lang = $this->get('thelia.admin.edition.lang');
if (null === $lang) {
$lang = Lang::getDefaultLanguage();
}
return $lang;
}
public function setAdminEditionLang($lang)
{
$this->set('thelia.admin.edition.lang', $lang);
return $this;
}
// -- Customer user --------------------------------------------------------
public function setCustomerUser(UserInterface $user)

View File

@@ -63,27 +63,32 @@ class ProductCreationForm extends BaseForm
"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")
))
;
if (! $change_mode) {
$this->formBuilder
->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)

View File

@@ -0,0 +1,90 @@
<?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\Form;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Core\Translation\Translator;
use Symfony\Component\Validator\Constraints\NotBlank;
class ProductDetailsModificationForm extends BaseForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
$this->formBuilder
->add("id", "integer", array(
"label" => Translator::getInstance()->trans("Prodcut ID *"),
"label_attr" => array("for" => "product_id_field"),
"constraints" => array(new GreaterThan(array('value' => 0)))
))
->add("price", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Product base price excluding taxes *"),
"label_attr" => array("for" => "price_field")
))
->add("price_with_tax", "number", array(
"label" => Translator::getInstance()->trans("Product base price including taxes *"),
"label_attr" => array("for" => "price_with_tax_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")
))
->add("quantity", "number", array(
"constraints" => array(new NotBlank()),
"label" => Translator::getInstance()->trans("Current quantity *"),
"label_attr" => array("for" => "quantity_field")
))
->add("sale_price", "number", array(
"label" => Translator::getInstance()->trans("Sale price *"),
"label_attr" => array("for" => "price_with_tax_field")
))
->add("onsale", "integer", array(
"label" => Translator::getInstance()->trans("This product is on sale"),
"label_attr" => array("for" => "onsale_field")
))
->add("isnew", "integer", array(
"label" => Translator::getInstance()->trans("Advertise this product as new"),
"label_attr" => array("for" => "isnew_field")
))
;
}
public function getName()
{
return "thelia_product_details_modification";
}
}

View File

@@ -98,10 +98,11 @@ class Product extends BaseProduct
->filterByDefaultCategory(true)
->findOne()
;
echo "newcat= $defaultCategoryId ";
var_dump($productCategory);
exit;
if ($productCategory == null || $productCategory->getCategoryId() != $defaultCategoryId) {
if ($productCategory == null || $productCategory->getCategoryId() != $defaultCategoryId) {
exit;
// Delete the old default category
if ($productCategory !== null) $productCategory->delete();

View File

@@ -81,7 +81,40 @@
{/if}
</p>
<div class="alert alert-danger">Please code me baby, oh yeah ! Code me NOW !</div>
<div class="table-responsive">
<table class="table table-striped table-condensed table-left-aligned">
<thead>
<tr>
<th>{intl l='ID'}</th>
<th>{intl l='Attribute Name'}</th>
{module_include location='product_attributes_table_header'}
</tr>
</thead>
<tbody>
{loop name="product-attributes" type="attribute" order="manual" product=$product_id backend_context="1" lang="$edit_language_id"}
<tr>
<td>{$ID}</td>
<td>{$TITLE}</td>
{module_include location='product_features_table_row'}
</tr>
{/loop}
{elseloop rel="product-attributes"}
<tr>
<td colspan="2">
<div class="alert alert-info">
{intl l="This product template does not contains any features"}
</div>
</td>
</tr>
{/elseloop}
</tbody>
</table>
</div>
</div>
</div>
</div>
@@ -111,7 +144,8 @@
<table class="table table-striped table-condensed table-left-aligned">
<thead>
<tr>
<th>{intl l='Feature Name'}</th>
<th>{intl l='ID'}</th>
<th>{intl l='Feature Name'}</th>
<th>{intl l='Feature value for this product'}</th>
{module_include location='product_features_table_header'}
@@ -122,6 +156,8 @@
<tbody>
{loop name="product-features" type="feature" order="manual" product=$product_id backend_context="1" lang="$edit_language_id"}
<tr>
<td>{$ID}</td>
<td>{$TITLE}</td>
<td>
@@ -176,7 +212,7 @@
{elseloop rel="product-features"}
<tr>
<td colspan="2">
<td colspan="3">
<div class="alert alert-info">
{intl l="This product template does not contains any features"}
</div>

View File

@@ -1,75 +0,0 @@
{loop name="product_edit" type="product" visible="*" id=$product_id backend_context="1" lang=$edit_language_id}
<div class="form-container">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">{intl l="Basic product information"}</div>
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-4">
{form_field form=$form field='price'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
{loop type="currency" name="default-currency" default_only="1" backend_context="1"}
<div class="input-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="col-lg-2 form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product price'}">
<span class="input-group-addon">{$SYMBOL}</span>
</div>
<div class="help-block">{intl l='Enter here the product price in the default currency (%title)' title=$NAME}</div>
{form_field form=$form field='currency'}
<input type="hidden" name="{$name}" value="{$ID}" />
{/form_field}
{/loop}
</div>
{/form_field}
</div>
<div class="col-lg-4">
{form_field form=$form field='tax_rule'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<div class="form-group">
<select id="{$label_attr.for}" required="required" name="{$name}" class="form-control">
<option value="">{intl l="Select a tax tule"}</option>
{loop name="tax" type="tax-rule" backend_context="1"}
<option value="{$ID}" {if $IS_DEFAULT}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
</div>
<div class="help-block">{intl l='Select here the tax applicable to this product'}</div>
</div>
{/form_field}
</div>
<div class="col-lg-4">
Price w/tax
</div>
</div>
{form_field form=$form field='weight'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label}: </label>
<div class="row">
<div class="col-lg-4">
<div class="input-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product weight'}">
<span class="input-group-addon">{intl l="Kg"}</span>
</div>
</div>
</div>
<div class="help-block">{intl l='Enter here the product weight, in Kilogrammes'}</div>
</div>
{/form_field}
</div>
</div>
{/loop}

View File

@@ -9,21 +9,19 @@ Parameters:
*}
<div class="row inner-toolbar">
<div class="col-md-6 inner-actions">
{* Display the top form toolbar, with edition flags, and save buttons *}
<div class="col-md-6 inner-actions">
<ul class="nav nav-pills">
{loop name="lang_list" type="lang"}
<li {if $ID == $edit_language_id}class="active"{/if}>
<a href="{url path={$page_url|default:$current_url} edit_language_id=$ID}" title="{intl l="Edit information in %lng" lng=$TITLE}">
<a href="{url path={$page_url|default:$current_url} edit_language_id=$ID}" title="{intl l='Edit information in %lng' lng=$TITLE}">
<img src="{image file="../assets/img/flags/{$CODE}.gif"}" alt="{intl l=$TITLE}" />
</a>
</li>
{/loop}
</ul>
</div>
</div>
<div class="col-md-6 inner-actions">
<div class="col-md-6 inner-actions">
{if $hide_submit_buttons != true}
<button type="submit" name="save_mode" value="stay" class="btn btn-default btn-success" title="{intl l='Save'}">{intl l='Save'} <span class="glyphicon glyphicon-ok"></span></button>
<button type="submit" name="save_mode" value="close" class="btn btn-default btn-info" title="{intl l='Save and close'}">{intl l='Save and close'} <span class="glyphicon glyphicon-remove"></span></button>
@@ -31,5 +29,5 @@ Parameters:
{if ! empty($close_url)}
<a href="{$close_url}" class="btn btn-default">{intl l='Close'} <span class="glyphicon glyphicon-remove"></span></a>
{/if}
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,197 @@
<div class="form-container">
{form name="thelia.admin.product.details.modification"}
<form method="POST" action="{url path='/admin/products/details/save'}" {form_enctype form=$form} class="clearfix">
{include
file = "includes/inner-form-toolbar.html"
hide_submit_buttons = false
page_url = "{url path='/admin/products/update' product_id=$ID}"
close_url = "{url path='/admin/categories' category_id=$DEFAULT_CATEGORY}"
}
{* Be sure to get the product ID, even if the form could not be validated *}
<input type="hidden" name="product_id" value="{$product_id}" />
<input type="hidden" name="current_tab" value="details" />
{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/categories' category_id=$DEFAULT_CATEGORY}" />
{/form_field}
{loop type="currency" name="product-currency" id=$edit_currency_id backend_context="1"}
{$currency_symbol = $SYMBOL}
{$currency_name = $NAME}
{form_field form=$form field='currency'}
<input type="hidden" name="{$name}" value="{$ID}" />
{/form_field}
{/loop}
<div class="row">
<div class="col-md-12">
<ul class="nav nav-pills">
<li class="disabled"><a href="#">{intl l='Edit prices in:'}</a></li>
{loop name="currency_list" type="currency"}
<li {if $ID == $edit_currency_id}class="active"{/if}>
<a href="{url noamp=1 path='/admin/products/update' edit_currency_id=$ID product_id=$product_id current_tab='details'}" title="{intl l='Edit prices in %curr' curr=$NAME}">
{$SYMBOL}
</a>
</li>
{/loop}
</ul>
</div>
</div>
<div class="row">
{* -- Pricing ------------------------------------------------------- *}
<div class="col-md-4">
<p class="title title-without-tabs">{intl l='Pricing'}</p>
<p></p> <!-- LAME !!! FIXME -->
{form_field form=$form field='price'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<div class="input-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product price'}">
<span class="input-group-addon">{$currency_symbol}</span>
</div>
</div>
{/form_field}
{form_field form=$form field='tax_rule'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<div class="form-group">
<select id="{$label_attr.for}" required="required" name="{$name}" class="form-control">
<option value="">{intl l="Select a tax tule"}</option>
{loop name="tax" type="tax-rule" backend_context="1"}
<option value="{$ID}" {if $IS_DEFAULT}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
</div>
</div>
{/form_field}
{form_field form=$form field='price_with_tax'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<div class="input-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product price'}">
<span class="input-group-addon">{$currency_symbol}</span>
</div>
</div>
{/form_field}
{module_include location='product_details_pricing_form'}
</div>
{* -- Promotion ------------------------------------------------- *}
<div class="col-md-4">
<p class="title title-without-tabs">{intl l='Promotion'}</p>
{form_field form=$form field='sale_price'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<div class="input-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product price'}">
<span class="input-group-addon">{$currency_symbol}</span>
</div>
</div>
{/form_field}
{form_field form=$form field='onsale'}
<div class="form-group {if $error}has-error{/if}">
<div class="checkbox">
<label>
<input type="checkbox" id="{$label_attr.for}" name="{$name}" value="1" {if $value != 0}checked="checked"{/if}>
{$label}
</label>
</div>
</div>
{/form_field}
{form_field form=$form field='isnew'}
<div class="form-group {if $error}has-error{/if}">
<div class="checkbox">
<label>
<input type="checkbox" id="{$label_attr.for}" name="{$name}" value="1" {if $value != 0}checked="checked"{/if}>
{$label}
</label>
</div>
</div>
{/form_field}
{module_include location='product_details_promotion_form'}
</div>
{* -- Shipping -------------------------------------------------- *}
<div class="col-md-4">
<p class="title title-without-tabs">{intl l='Shipping'}</p>
{form_field form=$form field='weight'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<div class="input-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Product weight'}">
<span class="input-group-addon">{intl l="Kg"}</span>
</div>
</div>
{/form_field}
<p class="title title-without-tabs">{intl l='Quantity'}</p>
{form_field form=$form field='quantity'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<div class="form-group">
<input type="text" id="{$label_attr.for}" required="required" name="{$name}" class="form-control" value="{$value}" title="{$label}" placeholder="{intl l='Current quantity'}">
</div>
</div>
{/form_field}
{module_include location='product_details_shipping_form'}
</div>
</div>
{/form}
{* -- Attribute combinations -------------------------------------------- *}
<div class="row">
<div class="col-md-12">
<p class="title title-without-tabs">{intl l='Attribute Combinations'}</p>
<div class="alert alert-info">
{intl l="This product has no attribute combination"}
</div>
</div> {* com *}
</div> {* row *}
</div>

View File

@@ -48,7 +48,7 @@
</li>
<li>
<a href="#price" data-toggle="tab">{intl l="Prices"}</a>
<a href="#details" data-toggle="tab">{intl l="Details"}</a>
</li>
<li><a href="#attributes"
@@ -73,6 +73,10 @@
{include file="includes/product-general-tab.html"}
</div>
<div class="tab-pane fade" id="details">
{include file="includes/product-details-tab.html"}
</div>
<div class="tab-pane fade" id="attributes">
<div class="text-center"><span class="loading">{intl l="Please wait, loading"}</span></div>
</div>