From f15b96383c3d88637faa81e927c69485036d3326 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 10:20:59 +0200 Subject: [PATCH 01/52] cart template --- templates/default/cart.html | 153 ++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 templates/default/cart.html diff --git a/templates/default/cart.html b/templates/default/cart.html new file mode 100644 index 000000000..8ab707f7b --- /dev/null +++ b/templates/default/cart.html @@ -0,0 +1,153 @@ +{extends file="layout.tpl"} + +{block name="breadcrumb"} + +{/block} + +{block name="main-content"} +
+
+ +

Your Cart

+ + + +
+ + + + + + + + + + + + + + + + + + + + {loop type="cart" name="cartloop"} + + + + + + + + + + {/loop} + + + + + + + + + +
  + + Name + + + Price + + + Qty + + + Total +
+ + {assign "cart_count" $LOOP_COUNT} + {ifloop rel='product-image'} + {loop type="image" name="product-image" product=$PRODUCT_ID limit="1" width="118" height="85" force_return="true"} + Product #{$cart_count} + {/loop} + {/ifloop} + {elseloop rel="product-image"} + {images file='assets/img/product/1/118x85.png'}Product #{$LOOP_COUNT}{/images} + {/elseloop} + +

+ Product #{$LOOP_COUNT} +

+
+
+
Available :
+
In Stock
+
No.
+
{$REF}
+ {*
Select Size
+
Large
+
Select Delivery Date
+
Jan 2, 2013
+
Additional Option
+
Option 1
*} +
+
+ Remove +
+
$50.00
+ instead of $59.99 +
+
+ +
+
+ $100.00 +
 Total TTC +
+ $200.00 +
+
+ + Continue Shopping + +
+ +
+ + + +
+ + +{/block} \ No newline at end of file From b6bc6994fc007254bd8a9b64456a24471244303e Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 10:53:15 +0200 Subject: [PATCH 02/52] WIP : Install wizard --- .../Controller/Install/InstallController.php | 3 ++- core/lib/Thelia/Install/CheckPermission.php | 25 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php index 40e6643db..75594868a 100644 --- a/core/lib/Thelia/Controller/Install/InstallController.php +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -42,9 +42,10 @@ class InstallController extends BaseInstallController public function checkPermission() { + var_dump('step2'); //$this->verifyStep(2); - //$permission = new CheckPermission(); + $permission = new CheckPermission(); $this->getSession()->set("step", 2); return $this->render("step-2.html"); diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index db73330cf..e57185c36 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -31,9 +31,10 @@ namespace Thelia\Install; */ class CheckPermission extends BaseInstall { - const CONF = "const"; - const LOG = "log"; - const CACHE = "cache"; + + const DIR_CONF = 'local/config'; + const DIR_LOG = 'log'; + const DIR_CACHE = 'cache'; private $directories = array(); private $validation = array(); @@ -44,22 +45,22 @@ class CheckPermission extends BaseInstall $this->directories = array( - self::CONF => THELIA_ROOT . "local/config", - self::LOG => THELIA_ROOT . "log", - self::CACHE => THELIA_ROOT . "cache" + self::DIR_CONF => THELIA_ROOT . 'local/config', + self::DIR_LOG => THELIA_ROOT . 'DIR_LOG', + self::DIR_CACHE => THELIA_ROOT . 'DIR_CACHE' ); $this->validation = array( - self::CONF => array( - "text" => sprintf("config directory(%s)...", $this->directories[self::CONF]), + self::DIR_CONF => array( + "text" => sprintf("config directory(%s)...", $this->directories[self::DIR_CONF]), "status" => true ), - self::LOG => array( - "text" => sprintf("cache directory(%s)...", $this->directories[self::LOG]), + self::DIR_LOG => array( + "text" => sprintf("DIR_CACHE directory(%s)...", $this->directories[self::DIR_LOG]), "status" => true ), - self::CACHE => array( - "text" => sprintf("log directory(%s)...", $this->directories[self::CACHE]), + self::DIR_CACHE => array( + "text" => sprintf("DIR_LOG directory(%s)...", $this->directories[self::DIR_CACHE]), "status" => true ) ); From 2857d0621c468820e2e05fb8bfdcacd3861bf2c7 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 11:14:23 +0200 Subject: [PATCH 03/52] cart page --- core/lib/Thelia/Core/Template/Loop/Cart.php | 12 +++++++++++- core/lib/Thelia/Model/CartItem.php | 12 ++++++++++++ core/lib/Thelia/Model/Product.php | 2 +- core/lib/Thelia/Model/ProductSaleElements.php | 4 ++-- templates/default/cart.html | 16 +++++++++++----- templates/default/product.html | 4 ++-- 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Cart.php b/core/lib/Thelia/Core/Template/Loop/Cart.php index f65afdf40..17437387e 100755 --- a/core/lib/Thelia/Core/Template/Loop/Cart.php +++ b/core/lib/Thelia/Core/Template/Loop/Cart.php @@ -13,6 +13,7 @@ use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; +use Thelia\Model\CountryQuery; class Cart extends BaseLoop { @@ -82,7 +83,6 @@ class Cart extends BaseLoop foreach ($cartItems as $cartItem) { $product = $cartItem->getProduct(); - //$product->setLocale($this->request->getSession()->getLocale()); $loopResultRow = new LoopResultRow($result, $cartItem, $this->versionable, $this->timestampable, $this->countable); @@ -92,6 +92,16 @@ class Cart extends BaseLoop $loopResultRow->set("QUANTITY", $cartItem->getQuantity()); $loopResultRow->set("PRICE", $cartItem->getPrice()); $loopResultRow->set("PRODUCT_ID", $product->getId()); + $loopResultRow->set("PRODUCT_URL", $product->getUrl($this->request->getSession()->getLang()->getLocale())) + ->set("PRICE", $cartItem->getPrice()) + ->set("PROMO_PRICE", $cartItem->getPromoPrice()) + ->set("TAXED_PRICE", $cartItem->getTaxedPrice( + CountryQuery::create()->findOneById(64) // @TODO : make it magic + )) + ->set("PROMO_TAXED_PRICE", $cartItem->getTaxedPromoPrice( + CountryQuery::create()->findOneById(64) // @TODO : make it magic + )) + ->set("IS_PROMO", $cartItem->getPromo() === 1 ? 1 : 0); $result->addRow($loopResultRow); } diff --git a/core/lib/Thelia/Model/CartItem.php b/core/lib/Thelia/Model/CartItem.php index 5ef6048a5..f6a34011d 100755 --- a/core/lib/Thelia/Model/CartItem.php +++ b/core/lib/Thelia/Model/CartItem.php @@ -8,6 +8,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\CartItem as BaseCartItem; use Thelia\Model\ConfigQuery; use Thelia\Core\Event\CartEvent; +use Thelia\TaxEngine\Calculator; class CartItem extends BaseCartItem { @@ -64,4 +65,15 @@ class CartItem extends BaseCartItem return $this; } + public function getTaxedPrice(Country $country) + { + $taxCalculator = new Calculator(); + return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPrice()), 2); + } + + public function getTaxedPromoPrice(Country $country) + { + $taxCalculator = new Calculator(); + return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPromoPrice()), 2); + } } diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 06c4640d0..28951fb44 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -28,6 +28,6 @@ class Product extends BaseProduct public function getTaxedPrice(Country $country) { $taxCalculator = new Calculator(); - return $taxCalculator->load($this, $country)->getTaxedPrice($this->getRealLowestPrice()); + return round($taxCalculator->load($this, $country)->getTaxedPrice($this->getRealLowestPrice()), 2); } } diff --git a/core/lib/Thelia/Model/ProductSaleElements.php b/core/lib/Thelia/Model/ProductSaleElements.php index 184e37d0a..6a95c37f3 100755 --- a/core/lib/Thelia/Model/ProductSaleElements.php +++ b/core/lib/Thelia/Model/ProductSaleElements.php @@ -32,12 +32,12 @@ class ProductSaleElements extends BaseProductSaleElements public function getTaxedPrice(Country $country) { $taxCalculator = new Calculator(); - return $taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPrice()); + return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPrice()), 2); } public function getTaxedPromoPrice(Country $country) { $taxCalculator = new Calculator(); - return $taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPromoPrice()); + return round($taxCalculator->load($this->getProduct(), $country)->getTaxedPrice($this->getPromoPrice()), 2); } } diff --git a/templates/default/cart.html b/templates/default/cart.html index 8ab707f7b..e3107b34e 100644 --- a/templates/default/cart.html +++ b/templates/default/cart.html @@ -88,11 +88,17 @@
Option 1
*} - Remove + Remove -
$50.00
- instead of $59.99 + {if $IS_PROMO == 1} + {assign "real_price" $PROMO_TAXED_PRICE} +
{currency attr="symbol"} {$PROMO_TAXED_PRICE}
+ instead of {currency attr="symbol"} {$TAXED_PRICE} + {else} + {assign "real_price" $TAXED_PRICE} +
{currency attr="symbol"} {$TAXED_PRICE}
+ {/if}
@@ -100,7 +106,7 @@
- $100.00 + {currency attr="symbol"} {$real_price * $QUANTITY} @@ -120,7 +126,7 @@ - Continue Shopping + Continue Shopping diff --git a/templates/default/product.html b/templates/default/product.html index 7c62eb740..f2b58d4ba 100644 --- a/templates/default/product.html +++ b/templates/default/product.html @@ -94,13 +94,13 @@ online_only : http://schema.org/OnlineOnly --> {if $IS_PROMO } - {loop name="productSaleElements_promo" type="product_sale_elements" product="{$ID}" limit="1"} + {loop name="productSaleElements_promo" type="product_sale_elements" product="{$ID}" limit="1" order="min_price"} {assign var="default_product_sale_elements" value="$ID"} {intl l="Special Price:"} {format_number number="{$TAXED_PROMO_PRICE}"} {currency attr="symbol"} {intl l="Regular Price:"} {format_number number="{$TAXED_PRICE}"} {currency attr="symbol"} {/loop} {else} - {intl l="Special Price:"} {format_number number="{$BEST_TAXED_PRICE}"} {currency attr="symbol"} + {intl l="Special Price:"} {format_number number="{$TAXED_PRICE}"} {currency attr="symbol"} {/if} From e0a48df23eb860d38a477df68e0967627106ec9e Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 13:15:35 +0200 Subject: [PATCH 04/52] cart integration --- .../Thelia/Config/Resources/routing/front.xml | 6 + core/lib/Thelia/Core/Template/Loop/Cart.php | 2 + .../Smarty/Plugins/DataAccessFunctions.php | 10 +- core/lib/Thelia/Model/Cart.php | 25 +- core/lib/Thelia/Model/CartItem.php | 5 + templates/default/cart.html | 221 ++++++++++-------- templates/default/cart_billing.html | 141 +++++++++++ 7 files changed, 304 insertions(+), 106 deletions(-) create mode 100644 templates/default/cart_billing.html diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index adbb7d529..cea964153 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -97,6 +97,12 @@ Thelia\Controller\Front\DefaultController::noAction cart + + + Thelia\Controller\Front\DefaultController::noAction + cart_billing + + Thelia\Controller\Front\CartController::addItem diff --git a/core/lib/Thelia/Core/Template/Loop/Cart.php b/core/lib/Thelia/Core/Template/Loop/Cart.php index 17437387e..3c8724d68 100755 --- a/core/lib/Thelia/Core/Template/Loop/Cart.php +++ b/core/lib/Thelia/Core/Template/Loop/Cart.php @@ -83,6 +83,7 @@ class Cart extends BaseLoop foreach ($cartItems as $cartItem) { $product = $cartItem->getProduct(); + $productSaleElement = $cartItem->getProductSaleElements(); $loopResultRow = new LoopResultRow($result, $cartItem, $this->versionable, $this->timestampable, $this->countable); @@ -93,6 +94,7 @@ class Cart extends BaseLoop $loopResultRow->set("PRICE", $cartItem->getPrice()); $loopResultRow->set("PRODUCT_ID", $product->getId()); $loopResultRow->set("PRODUCT_URL", $product->getUrl($this->request->getSession()->getLang()->getLocale())) + ->set("STOCK", $productSaleElement->getQuantity()) ->set("PRICE", $cartItem->getPrice()) ->set("PROMO_PRICE", $cartItem->getPromoPrice()) ->set("TAXED_PRICE", $cartItem->getTaxedPrice( diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index 802dfcff2..cc99bfe50 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -31,6 +31,7 @@ use Thelia\Core\Template\ParserContext; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Model\CategoryQuery; use Thelia\Model\ContentQuery; +use Thelia\Model\CountryQuery; use Thelia\Model\CurrencyQuery; use Thelia\Model\FolderQuery; use Thelia\Model\Product; @@ -160,9 +161,16 @@ class DataAccessFunctions extends AbstractSmartyPlugin $result = ""; switch($params["attr"]) { case "count_item": - $result = $cart->getCartItems()->count(); break; + case "total_price": + $result = $cart->getTotalAmount(); + break; + case "total_taxed_price": + $result = $cart->getTaxedAmount( + CountryQuery::create()->findOneById(64) // @TODO : make it magic + ); + break; } return $result; diff --git a/core/lib/Thelia/Model/Cart.php b/core/lib/Thelia/Model/Cart.php index dcb65f88e..78e19daa4 100755 --- a/core/lib/Thelia/Model/Cart.php +++ b/core/lib/Thelia/Model/Cart.php @@ -8,6 +8,7 @@ use Thelia\Model\Base\Cart as BaseCart; use Thelia\Model\ProductSaleElementsQuery; use Thelia\Model\ProductPriceQuery; use Thelia\Model\CartItemQuery; +use Thelia\TaxEngine\Calculator; class Cart extends BaseCart { @@ -72,9 +73,25 @@ class Cart extends BaseCart ; } - public function getTaxedAmount() + public function getTaxedAmount(Country $country) { + $taxCalculator = new Calculator(); + $total = 0; + + foreach($this->getCartItems() as $cartItem) { + $subtotal = $cartItem->getRealPrice(); + $subtotal -= $cartItem->getDiscount(); + /* we round it for the unit price, before the quantity factor */ + $subtotal = round($taxCalculator->load($cartItem->getProduct(), $country)->getTaxedPrice($subtotal), 2); + $subtotal *= $cartItem->getQuantity(); + + $total += $subtotal; + } + + $total -= $this->getDiscount(); + + return $total; } public function getTotalAmount() @@ -82,7 +99,11 @@ class Cart extends BaseCart $total = 0; foreach($this->getCartItems() as $cartItem) { - $total += $cartItem->getPrice()-$cartItem->getDiscount(); + $subtotal = $cartItem->getRealPrice(); + $subtotal -= $cartItem->getDiscount(); + $subtotal *= $cartItem->getQuantity(); + + $total += $subtotal; } $total -= $this->getDiscount(); diff --git a/core/lib/Thelia/Model/CartItem.php b/core/lib/Thelia/Model/CartItem.php index f6a34011d..a1fb3601a 100755 --- a/core/lib/Thelia/Model/CartItem.php +++ b/core/lib/Thelia/Model/CartItem.php @@ -65,6 +65,11 @@ class CartItem extends BaseCartItem return $this; } + public function getRealPrice() + { + return $this->getPromo() == 1 ? $this->getPromoPrice() : $this->getPrice(); + } + public function getTaxedPrice(Country $country) { $taxCalculator = new Calculator(); diff --git a/templates/default/cart.html b/templates/default/cart.html index e3107b34e..6f91d8581 100644 --- a/templates/default/cart.html +++ b/templates/default/cart.html @@ -4,7 +4,7 @@ @@ -23,112 +23,117 @@ 4 Secure payment -
- - - - - - - - - - - - - - - - - - +
  - - Name - - - Price - - - Qty - - - Total -
+ + + + + + + + + + + + + + + + + - {loop type="cart" name="cartloop"} + {loop type="cart" name="cartloop"} - - - - - - - + + + + + + + - {/loop} + {/loop} - - - - - - - - -
  + + Name + + + Price + + + Qty + + + Total +
- - {assign "cart_count" $LOOP_COUNT} - {ifloop rel='product-image'} - {loop type="image" name="product-image" product=$PRODUCT_ID limit="1" width="118" height="85" force_return="true"} - Product #{$cart_count} - {/loop} - {/ifloop} - {elseloop rel="product-image"} - {images file='assets/img/product/1/118x85.png'}Product #{$LOOP_COUNT}{/images} - {/elseloop} - -

- Product #{$LOOP_COUNT} -

-
-
-
Available :
-
In Stock
-
No.
-
{$REF}
- {*
Select Size
-
Large
-
Select Delivery Date
-
Jan 2, 2013
-
Additional Option
-
Option 1
*} -
-
- Remove -
- {if $IS_PROMO == 1} - {assign "real_price" $PROMO_TAXED_PRICE} -
{currency attr="symbol"} {$PROMO_TAXED_PRICE}
- instead of {currency attr="symbol"} {$TAXED_PRICE} - {else} - {assign "real_price" $TAXED_PRICE} -
{currency attr="symbol"} {$TAXED_PRICE}
- {/if} -
-
- -
-
- {currency attr="symbol"} {$real_price * $QUANTITY} -
+ + {assign "cart_count" $LOOP_COUNT} + {ifloop rel='product-image'} + {loop type="image" name="product-image" product=$PRODUCT_ID limit="1" width="118" height="85" force_return="true"} + Product #{$cart_count} + {/loop} + {/ifloop} + {elseloop rel="product-image"} + {images file='assets/img/product/1/118x85.png'}Product #{$cart_count}{/images} + {/elseloop} + +

+ Product #{$LOOP_COUNT} +

+
+
+
Available :
+
In Stock
+
No.
+
{$REF}
+ {*
Select Size
+
Large
+
Select Delivery Date
+
Jan 2, 2013
+
Additional Option
+
Option 1
*} +
+
+ Remove +
+ {if $IS_PROMO == 1} + {assign "real_price" $PROMO_TAXED_PRICE} +
{currency attr="symbol"} {$PROMO_TAXED_PRICE}
+ instead of {currency attr="symbol"} {$TAXED_PRICE} + {else} + {assign "real_price" $TAXED_PRICE} +
{currency attr="symbol"} {$TAXED_PRICE}
+ {/if} +
+
+ + + + +
+
+ {currency attr="symbol"} {$real_price * $QUANTITY} +
 Total TTC -
- $200.00 -
-
+ + + +   + Total TTC + +
+ {currency attr="symbol"} {cart attr="total_taxed_price"} +
+ + + + - Continue Shopping - - + Continue Shopping + Proceed checkout @@ -154,6 +159,16 @@ +{/block} - +{block name="javascript-initialization"} + {/block} \ No newline at end of file diff --git a/templates/default/cart_billing.html b/templates/default/cart_billing.html new file mode 100644 index 000000000..d44753e48 --- /dev/null +++ b/templates/default/cart_billing.html @@ -0,0 +1,141 @@ +{extends file="layout.tpl"} + +{block name="breadcrumb"} + +{/block} + +{block name="main-content"} +
+
+ +

Your Cart

+ + + +
+
+
+ Add a new address + Chose your delivery address +
+
+ + + + {loop type="address" name="customer.addresses" customer="current"} + + + + + + + + {/loop} + + + +
+
+ +
+
Choose your delivery method
+
+
+ +
+
+ +
+
+
+ + Back + + +
+
+
+ + + +{/block} + +{block name="javascript-initialization"} + +{/block} \ No newline at end of file From c7b3aea7f08f6a0442ce0b0a8686e043e3121932 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 14:31:34 +0200 Subject: [PATCH 05/52] cart integration --- core/lib/Thelia/Core/Template/Element/LoopResult.php | 2 +- core/lib/Thelia/Core/Template/Loop/Feed.php | 11 ++++++++--- core/lib/Thelia/Module/DeliveryModuleInterface.php | 7 +++++-- local/modules/Colissimo/Colissimo.php | 5 +++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Element/LoopResult.php b/core/lib/Thelia/Core/Template/Element/LoopResult.php index f86ab203d..45b690fc0 100755 --- a/core/lib/Thelia/Core/Template/Element/LoopResult.php +++ b/core/lib/Thelia/Core/Template/Element/LoopResult.php @@ -37,7 +37,7 @@ class LoopResult implements \Iterator public function __construct($modelCollection = null) { $this->position = 0; - if ($modelCollection instanceof ObjectCollection || $modelCollection instanceof PropelModelPager) { + if ($modelCollection instanceof ObjectCollection || $modelCollection instanceof PropelModelPager || is_array($modelCollection)) { $this->modelCollection = $modelCollection; } } diff --git a/core/lib/Thelia/Core/Template/Loop/Feed.php b/core/lib/Thelia/Core/Template/Loop/Feed.php index 8e155a666..a40f84647 100755 --- a/core/lib/Thelia/Core/Template/Loop/Feed.php +++ b/core/lib/Thelia/Core/Template/Loop/Feed.php @@ -73,9 +73,14 @@ class Feed extends BaseLoop $limit = min(count($items), $this->getLimit()); - $loopResult = new LoopResult(); - + $indexes = array(); for ($idx = 0; $idx < $limit; $idx++) { + $indexes[] = $idx; + } + + $loopResult = new LoopResult($query); + + foreach ($indexes as $idx) { $item = $items[$idx]; @@ -87,7 +92,7 @@ class Feed extends BaseLoop $date = $item->get_date('d/m/Y'); - $loopResultRow = new LoopResultRow(); + $loopResultRow = new LoopResultRow($loopResult, $item, $this->versionable, $this->timestampable, $this->countable); $loopResultRow->set("URL", $item->get_permalink()); $loopResultRow->set("TITLE", $item->get_title()); diff --git a/core/lib/Thelia/Module/DeliveryModuleInterface.php b/core/lib/Thelia/Module/DeliveryModuleInterface.php index ba218ac4d..72f8769bc 100644 --- a/core/lib/Thelia/Module/DeliveryModuleInterface.php +++ b/core/lib/Thelia/Module/DeliveryModuleInterface.php @@ -23,13 +23,16 @@ namespace Thelia\Module; +use Thelia\Model\Country; + interface DeliveryModuleInterface extends BaseModuleInterface { /** - * * calculate and return delivery price * + * @param Country $country + * * @return mixed */ - public function calculate($country = null); + public function calculate(Country $country); } diff --git a/local/modules/Colissimo/Colissimo.php b/local/modules/Colissimo/Colissimo.php index 4d24cc059..2fe9cd0b9 100644 --- a/local/modules/Colissimo/Colissimo.php +++ b/local/modules/Colissimo/Colissimo.php @@ -25,6 +25,7 @@ namespace Colissimo; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; +use Thelia\Model\Country; use Thelia\Module\BaseModule; use Thelia\Module\DeliveryModuleInterface; @@ -57,10 +58,10 @@ class Colissimo extends BaseModule implements DeliveryModuleInterface * * calculate and return delivery price * - * @param null $country + * @param Country $country * @return mixed */ - public function calculate($country = null) + public function calculate(Country $country) { // TODO: Implement calculate() method. return 2; From b151325e572c9c23a1940e9565462c2abe29ee6f Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 15:07:41 +0200 Subject: [PATCH 06/52] WIP : Install wizard : step 2 file permission --- .../Controller/Install/InstallController.php | 70 ++++++- core/lib/Thelia/Install/BaseInstall.php | 15 +- core/lib/Thelia/Install/CheckPermission.php | 183 ++++++++++++++---- templates/install/layout.tpl | 1 - templates/install/step-2.html | 15 +- 5 files changed, 232 insertions(+), 52 deletions(-) diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php index 75594868a..648ae843e 100644 --- a/core/lib/Thelia/Controller/Install/InstallController.php +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -26,12 +26,14 @@ use Thelia\Install\CheckPermission; /** * Class InstallController + * * @package Thelia\Controller\Install - * @author Manuel Raynaud + * @author Manuel Raynaud + * @author Guillaume MOREL */ class InstallController extends BaseInstallController { - public function index() + public function indexAction() { //$this->verifyStep(1); @@ -40,57 +42,109 @@ class InstallController extends BaseInstallController return $this->render("index.html"); } - public function checkPermission() + /** + * Integration tests + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function checkPermissionAction() { + $args = array(); var_dump('step2'); //$this->verifyStep(2); - $permission = new CheckPermission(); + $checkPermission = new CheckPermission(true, $this->getTranslator()); + $args['isValid'] = $isValid = $checkPermission->exec(); + $args['validationMessages'] = $checkPermission->getValidationMessages(); $this->getSession()->set("step", 2); - return $this->render("step-2.html"); + + return $this->render("step-2.html", $args); } + /** + * Database connexion tests + * + * @return \Symfony\Component\HttpFoundation\Response + */ public function databaseConnection() { + var_dump('step 3 bis'); + } + + /** + * Database connexion tests + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function databaseConnectionAction() + { + var_dump('step 3'); + exit(); //$this->verifyStep(2); //$permission = new CheckPermission(); $this->getSession()->set("step", 3); + return $this->render("step-3.html"); } - public function databaseSelection() + /** + * Database selection + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function databaseSelectionAction() { //$this->verifyStep(2); //$permission = new CheckPermission(); $this->getSession()->set("step", 4); + return $this->render("step-4.html"); } - public function generalInformation() + /** + * Set general informations + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function generalInformationAction() { //$this->verifyStep(2); //$permission = new CheckPermission(); $this->getSession()->set("step", 5); + return $this->render("step-5.html"); } - public function thanks() + /** + * Display Thanks page + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function thanksAction() { //$this->verifyStep(2); //$permission = new CheckPermission(); $this->getSession()->set("step", 6); + return $this->render("thanks.html"); } + /** + * Verify each steps and redirect if one step has already been passed + * + * @param int $step Step number + * + * @return bool + */ protected function verifyStep($step) { $session = $this->getSession(); diff --git a/core/lib/Thelia/Install/BaseInstall.php b/core/lib/Thelia/Install/BaseInstall.php index 11b8d0999..86928236a 100644 --- a/core/lib/Thelia/Install/BaseInstall.php +++ b/core/lib/Thelia/Install/BaseInstall.php @@ -25,15 +25,28 @@ use Thelia\Install\Exception\AlreadyInstallException; /** * Class BaseInstall + * * @author Manuel Raynaud */ abstract class BaseInstall { + /** @var bool If Installation wizard is launched by CLI */ + protected $isConsoleMode = true; + /** - * Verify if an installation already exists + * Constructor + * + * @param bool $verifyInstall Verify if an installation already exists */ public function __construct($verifyInstall = true) { + + // Check if install wizard is launched via CLI + if (php_sapi_name() == 'cli') { + $this->isConsoleMode = true; + } else { + $this->isConsoleMode = false; + } /* TODO : activate this part if (file_exists(THELIA_ROOT . '/local/config/database.yml') && $verifyInstall) { throw new AlreadyInstallException("Thelia is already installed"); diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index e57185c36..d924bac35 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -23,57 +23,172 @@ namespace Thelia\Install; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use Symfony\Component\Translation\TranslatorInterface; +use Thelia\Core\Translation\Translator; + /** * Class CheckPermission + * + * Take care of integration tests (files permissions) + * * @package Thelia\Install - * @author Manuel Raynaud + * @author Manuel Raynaud + * @author Guillaume MOREL */ class CheckPermission extends BaseInstall { - const DIR_CONF = 'local/config'; - const DIR_LOG = 'log'; - const DIR_CACHE = 'cache'; + const DIR_CONF = 'local/config'; + const DIR_LOG = 'log'; + const DIR_CACHE = 'cache'; - private $directories = array(); - private $validation = array(); - private $valid = true; + /** @var array Directory needed to be writable */ + protected $directoriesToBeWritable = array( + self::DIR_CONF, + self::DIR_LOG, + self::DIR_CACHE, + ); - public function __construct($verifyInstall = true) + protected $validationMessages = array(); + + /** @var bool If permissions are OK */ + protected $isValid = true; + + /** @var TranslatorInterface Translator Service */ + protected $translator = null; + + /** + * Constructor + * + * @param bool $verifyInstall If verify install + * @param Translator $translator Translator Service + * necessary for install wizard + */ + public function __construct($verifyInstall = true, Translator $translator = null) { + $this->translator = $translator; - - $this->directories = array( - self::DIR_CONF => THELIA_ROOT . 'local/config', - self::DIR_LOG => THELIA_ROOT . 'DIR_LOG', - self::DIR_CACHE => THELIA_ROOT . 'DIR_CACHE' - ); - - $this->validation = array( - self::DIR_CONF => array( - "text" => sprintf("config directory(%s)...", $this->directories[self::DIR_CONF]), - "status" => true - ), - self::DIR_LOG => array( - "text" => sprintf("DIR_CACHE directory(%s)...", $this->directories[self::DIR_LOG]), - "status" => true - ), - self::DIR_CACHE => array( - "text" => sprintf("DIR_LOG directory(%s)...", $this->directories[self::DIR_CACHE]), - "status" => true - ) - ); + foreach ($this->directoriesToBeWritable as $directory) { + $this->validationMessages[$directory] = array( + 'text' => '', + 'hint' => '', + 'status' => true + ); + } parent::__construct($verifyInstall); } + /** + * Perform file permission check + * + * @return bool + */ public function exec() { - foreach ($this->directories as $key => $directory) { - if(is_writable($directory) === false) { - $this->valid = false; - $this->validation[$key]["status"] = false; + foreach ($this->directoriesToBeWritable as $directory) { + $fullDirectory = THELIA_ROOT . $directory; + $this->validationMessages[$directory]['text'] = $this->getI18nText($fullDirectory, true); + if (is_writable($fullDirectory) === false) { + if (!$this->makeDirectoryWritable($fullDirectory)) { + $this->isValid = false; + $this->validationMessages[$directory]['status'] = false; + $this->validationMessages[$directory]['text'] = $this->getI18nText($fullDirectory, false); + $this->validationMessages[$directory]['hint'] = $this->getI18nHint($fullDirectory); + } } } + + return $this->isValid; } -} \ No newline at end of file + + /** + * Get validation messages + * + * @return array + */ + public function getValidationMessages() + { + return $this->validationMessages; + } + + /** + * Make a directory writable (recursively) + * + * @param string $directory path to directory + * + * @return bool + */ + protected function makeDirectoryWritable($directory) + { + chmod($directory, 0777); + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($directory) + ); + foreach ($iterator as $item) { + chmod($item, 0777); + } + + return (is_writable(THELIA_ROOT . $directory) === true); + } + + + + /** + * Get Translated text about the directory state + * + * @param string $directory Directory being checked + * @param bool $isValid If directory permission is valid + * + * @return string + */ + protected function getI18nText($directory, $isValid) + { + if ($this->translator !== null) { + if ($isValid) { + $sentence = 'Your directory %directory% is writable'; + } else { + $sentence = 'Your directory %directory% is not writable'; + } + + $translatedText = $this->translator->trans( + $sentence, + array( + '%directory%' => $directory + ), + 'install-wizard' + ); + } else { + $translatedText = sprintf('Your directory %s needs to be writable', $directory); + } + + return $translatedText; + } + + /** + * Get Translated hint about the directory state + * + * @param string $directory Directory being checked + * + * @return string + */ + protected function getI18nHint($directory) + { + if ($this->translator !== null) { + $sentence = 'chmod 777 %directory% on your server with admin rights could help'; + $translatedText = $this->translator->trans( + $sentence, + array( + '%directory%' => $directory + ), + 'install-wizard' + ); + } else { + $translatedText = sprintf('chmod 777 %s on your server with admin rights could help', $directory); + } + + return $translatedText; + } +} diff --git a/templates/install/layout.tpl b/templates/install/layout.tpl index 4539ce32f..6b38292e2 100644 --- a/templates/install/layout.tpl +++ b/templates/install/layout.tpl @@ -38,7 +38,6 @@ - {intl l='Édité par OpenStudio'} - {intl l='Forum Thelia'} - {intl l='Contributions Thelia'} - {intl l='interface par Steaw-Webdesign'}

{module_include location='in_footer'} diff --git a/templates/install/step-2.html b/templates/install/step-2.html index fc24d25cb..a05267c7c 100644 --- a/templates/install/step-2.html +++ b/templates/install/step-2.html @@ -24,15 +24,14 @@
-

We will check some rights to files and directories...

+

{intl l="Checking directory permissions ..."}

    -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • -
  • Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
  • + {foreach from=$validationMessages item=validationMessage} +
  • + {$validationMessage.text nofilter} + {if !$validationMessage.status} - {$validationMessage.hint nofilter}{/if} +
  • + {/foreach}
From bca2b58e416c9fb1d01aa55f9165d7f3151657bb Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 15:07:58 +0200 Subject: [PATCH 07/52] Merge master --- local/modules/Colissimo/Colissimo.php | 0 local/modules/Colissimo/Config/config.xml | 0 local/modules/Colissimo/Config/plugin.xml | 0 local/modules/Colissimo/Config/schema.xml | 0 local/modules/DebugBar/Config/config.xml | 0 local/modules/DebugBar/Config/plugin.xml | 0 local/modules/DebugBar/Config/schema.xml | 0 local/modules/DebugBar/DataCollector/PropelCollector.php | 0 local/modules/DebugBar/DebugBar.php | 0 local/modules/DebugBar/Listeners/DebugBarListeners.php | 0 local/modules/DebugBar/Smarty/Plugin/DebugBar.php | 0 11 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 local/modules/Colissimo/Colissimo.php mode change 100644 => 100755 local/modules/Colissimo/Config/config.xml mode change 100644 => 100755 local/modules/Colissimo/Config/plugin.xml mode change 100644 => 100755 local/modules/Colissimo/Config/schema.xml mode change 100644 => 100755 local/modules/DebugBar/Config/config.xml mode change 100644 => 100755 local/modules/DebugBar/Config/plugin.xml mode change 100644 => 100755 local/modules/DebugBar/Config/schema.xml mode change 100644 => 100755 local/modules/DebugBar/DataCollector/PropelCollector.php mode change 100644 => 100755 local/modules/DebugBar/DebugBar.php mode change 100644 => 100755 local/modules/DebugBar/Listeners/DebugBarListeners.php mode change 100644 => 100755 local/modules/DebugBar/Smarty/Plugin/DebugBar.php diff --git a/local/modules/Colissimo/Colissimo.php b/local/modules/Colissimo/Colissimo.php old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/config.xml b/local/modules/Colissimo/Config/config.xml old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/plugin.xml b/local/modules/Colissimo/Config/plugin.xml old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/schema.xml b/local/modules/Colissimo/Config/schema.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/config.xml b/local/modules/DebugBar/Config/config.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/plugin.xml b/local/modules/DebugBar/Config/plugin.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/schema.xml b/local/modules/DebugBar/Config/schema.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/DataCollector/PropelCollector.php b/local/modules/DebugBar/DataCollector/PropelCollector.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/DebugBar.php b/local/modules/DebugBar/DebugBar.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Listeners/DebugBarListeners.php b/local/modules/DebugBar/Listeners/DebugBarListeners.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Smarty/Plugin/DebugBar.php b/local/modules/DebugBar/Smarty/Plugin/DebugBar.php old mode 100644 new mode 100755 From d8b5df416214f83de2f047f4c2aeeb35003a1530 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 15:24:08 +0200 Subject: [PATCH 08/52] delivery process --- .../Thelia/Core/Template/Loop/Delivery.php | 15 +++++++-- core/lib/Thelia/Module/BaseModule.php | 3 ++ install/insert.sql | 3 +- local/config/schema.xml | 3 +- templates/default/cart_billing.html | 31 ++++++++++++------- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Delivery.php b/core/lib/Thelia/Core/Template/Loop/Delivery.php index a0e9ebb7a..b679e5061 100644 --- a/core/lib/Thelia/Core/Template/Loop/Delivery.php +++ b/core/lib/Thelia/Core/Template/Loop/Delivery.php @@ -22,9 +22,12 @@ /*************************************************************************************/ namespace Thelia\Core\Template\Loop; +use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Loop\Argument\Argument; +use Thelia\Model\CountryQuery; +use Thelia\Module\BaseModule; /** * Class Delivery @@ -39,7 +42,7 @@ class Delivery extends BaseSpecificModule $collection = parent::getArgDefinitions(); $collection->addArgument( - Argument::createIntTypeArgument("country") + Argument::createIntTypeArgument("country", null, true) ); return $collection; @@ -50,6 +53,14 @@ class Delivery extends BaseSpecificModule $search = parent::exec($pagination); /* manage translations */ $locale = $this->configureI18nProcessing($search); + + $search->filterByType(BaseModule::DELIVERY_MODULE_TYPE, Criteria::EQUAL); + + $country = $this->getCountry(); + if(null !== $country) { + //@todo + } + /* perform search */ $deliveryModules = $this->search($search, $pagination); @@ -73,7 +84,7 @@ class Delivery extends BaseSpecificModule ->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO')) ->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION')) ->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM')) - ->set('PRICE', $moduleInstance->calculate($this->getCountry())) + ->set('PRICE', $moduleInstance->calculate(CountryQuery::create()->findPk($country))) ; $loopResult->addRow($loopResultRow); diff --git a/core/lib/Thelia/Module/BaseModule.php b/core/lib/Thelia/Module/BaseModule.php index 9d76e08f3..a13403482 100755 --- a/core/lib/Thelia/Module/BaseModule.php +++ b/core/lib/Thelia/Module/BaseModule.php @@ -28,6 +28,9 @@ use Symfony\Component\DependencyInjection\ContainerAware; abstract class BaseModule extends ContainerAware { + const CLASSIC_MODULE_TYPE = 1; + const DELIVERY_MODULE_TYPE = 2; + const PAYMENT_MODULE_TYPE = 3; public function __construct() { diff --git a/install/insert.sql b/install/insert.sql index 03fbc690c..a49dc7231 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -28,7 +28,8 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat INSERT INTO `module` (`id`, `code`, `type`, `activate`, `position`, `full_namespace`, `created_at`, `updated_at`) VALUES -(1, 'DebugBar', 1, 1, 1, 'DebugBar\\DebugBar', NOW(), NOW()); +(1, 'DebugBar', 1, 1, 1, 'DebugBar\\DebugBar', NOW(), NOW()), +(2, 'Colissimo', 2, 1, 1, 'Colissimo\\Colissimo', NOW(), NOW()); INSERT INTO `customer_title`(`id`, `by_default`, `position`, `created_at`, `updated_at`) VALUES (1, 1, 1, NOW(), NOW()), diff --git a/local/config/schema.xml b/local/config/schema.xml index 49a76ebed..186bdbfd6 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1,4 +1,4 @@ - + @@ -80,6 +80,7 @@ + diff --git a/templates/default/cart_billing.html b/templates/default/cart_billing.html index d44753e48..8720bf696 100644 --- a/templates/default/cart_billing.html +++ b/templates/default/cart_billing.html @@ -48,18 +48,29 @@ @@ -83,18 +94,14 @@
Choose your delivery method
+ {loop type="delivery" name="deliveries" force_return="true"}
-
- -
+ {/loop}
From 361e9e11260ecf4ddc5d4ef3aba33af5077b1086 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 16:12:04 +0200 Subject: [PATCH 09/52] delivery process --- .../Thelia/Core/Template/Loop/Delivery.php | 15 ++-- .../Template/Loop/ProductSaleElements.php | 2 +- .../Smarty/Plugins/DataAccessFunctions.php | 11 +++ install/insert.sql | 11 ++- templates/default/cart_billing.html | 69 ++++++++++++++++++- 5 files changed, 98 insertions(+), 10 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Delivery.php b/core/lib/Thelia/Core/Template/Loop/Delivery.php index b679e5061..dea302797 100644 --- a/core/lib/Thelia/Core/Template/Loop/Delivery.php +++ b/core/lib/Thelia/Core/Template/Loop/Delivery.php @@ -42,7 +42,7 @@ class Delivery extends BaseSpecificModule $collection = parent::getArgDefinitions(); $collection->addArgument( - Argument::createIntTypeArgument("country", null, true) + Argument::createIntTypeArgument("country") ); return $collection; @@ -56,9 +56,14 @@ class Delivery extends BaseSpecificModule $search->filterByType(BaseModule::DELIVERY_MODULE_TYPE, Criteria::EQUAL); - $country = $this->getCountry(); - if(null !== $country) { - //@todo + $countryId = $this->getCountry(); + if(null !== $countryId) { + $country = CountryQuery::create()->findPk($countryId); + if(null === $country) { + throw new \InvalidArgumentException('Cannot found country id: `' . $countryId . '` in delivery loop'); + } + } else { + $country = CountryQuery::create()->findOneByByDefault(1); } /* perform search */ @@ -84,7 +89,7 @@ class Delivery extends BaseSpecificModule ->set('CHAPO', $deliveryModule->getVirtualColumn('i18n_CHAPO')) ->set('DESCRIPTION', $deliveryModule->getVirtualColumn('i18n_DESCRIPTION')) ->set('POSTSCRIPTUM', $deliveryModule->getVirtualColumn('i18n_POSTSCRIPTUM')) - ->set('PRICE', $moduleInstance->calculate(CountryQuery::create()->findPk($country))) + ->set('PRICE', $moduleInstance->calculate($country)) ; $loopResult->addRow($loopResultRow); diff --git a/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php b/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php index 980ade454..e27626129 100755 --- a/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php +++ b/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php @@ -115,7 +115,7 @@ class ProductSaleElements extends BaseLoop $currencyId = $this->getCurrency(); if (null !== $currencyId) { - $currency = CurrencyQuery::create()->findOneById($currencyId); + $currency = CurrencyQuery::create()->findPk($currencyId); if (null === $currency) { throw new \InvalidArgumentException('Cannot found currency id: `' . $currency . '` in product_sale_elements loop'); } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index cc99bfe50..bb220531c 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -155,6 +155,16 @@ class DataAccessFunctions extends AbstractSmartyPlugin } } + public function countryDataAccess($params, $smarty) + { + $defaultCountry = CountryQuery::create()->findOneByByDefault(1); + + switch($params["attr"]) { + case "default": + return $defaultCountry->getId(); + } + } + public function cartDataAccess($params, $smarty) { $cart = $this->getCart($this->request); @@ -287,6 +297,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin new SmartyPluginDescriptor('function', 'content', $this, 'contentDataAccess'), new SmartyPluginDescriptor('function', 'folder', $this, 'folderDataAccess'), new SmartyPluginDescriptor('function', 'currency', $this, 'currencyDataAccess'), + new SmartyPluginDescriptor('function', 'country', $this, 'countryDataAccess'), new SmartyPluginDescriptor('function', 'lang', $this, 'langDataAccess'), new SmartyPluginDescriptor('function', 'cart', $this, 'cartDataAccess'), ); diff --git a/install/insert.sql b/install/insert.sql index 01d7fbce2..348e447c2 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -31,6 +31,11 @@ INSERT INTO `module` (`id`, `code`, `type`, `activate`, `position`, `full_namesp (1, 'DebugBar', 1, 1, 1, 'DebugBar\\DebugBar', NOW(), NOW()), (2, 'Colissimo', 2, 1, 1, 'Colissimo\\Colissimo', NOW(), NOW()); +INSERT INTO `thelia_2`.`module_i18n` (`id`, `locale`, `title`, `description`, `chapo`, `postscriptum`) VALUES +('2', 'en_US', '72h delivery', NULL, NULL, NULL), +('2', 'fr_FR', 'Livraison par colissimo en 72h', NULL, NULL, NULL); + + INSERT INTO `customer_title`(`id`, `by_default`, `position`, `created_at`, `updated_at`) VALUES (1, 1, 1, NOW(), NOW()), (2, 0, 2, NOW(), NOW()), @@ -44,13 +49,13 @@ INSERT INTO `customer_title_i18n` (`id`, `locale`, `short`, `long`) VALUES (3, 'fr_FR', 'Mlle', 'Madamemoiselle'), (3, 'en_US', 'Miss', 'Miss'); -INSERT INTO `currency` (`id` ,`code` ,`symbol` ,`rate`, `position` ,`by_default` ,`created_at` ,`updated_at`) +INSERT INTO `currency` (`id`, `code`, `symbol`, `rate`, `position`, `by_default`, `created_at`, `updated_at`) VALUES -(1, 'EUR', '€', '1', 1, '1', NOW() , NOW()), +(1, 'EUR', '€', '1', 1, '1', NOW(), NOW()), (2, 'USD', '$', '1.26', 2, '0', NOW(), NOW()), (3, 'GBP', '£', '0.89', 3, '0', NOW(), NOW()); -INSERT INTO `currency_i18n` (`id` ,`locale` ,`name`) +INSERT INTO `currency_i18n` (`id`, `locale`, `name`) VALUES (1, 'fr_FR', 'Euro'), (1, 'en_US', 'Euro'), diff --git a/templates/default/cart_billing.html b/templates/default/cart_billing.html index 8720bf696..123596609 100644 --- a/templates/default/cart_billing.html +++ b/templates/default/cart_billing.html @@ -25,6 +25,73 @@
+ +
+
+ Add a new address + Chose your billing address +
+
+
  • - M. DUPONT Jean - Agency XY + {loop type="title" name="customer.title.info" id=$TITLE}{$SHORT}{/loop} {$LASTNAME|upper} {$FIRSTNAME|ucwords} + {$COMPANY}
  • - street name of my business
    - 75000 - City, Country + {$ADDRESS1} + {if $ADDRESS2 != ""} +
    {$ADDRESS2} + {/if} + {if $ADDRESS3 != ""} +
    {$ADDRESS3} + {/if} +
    {$ZIPCODE} + {$CITY}, {loop type="country" name="customer.country.info" id=$COUNTRY}{$TITLE}{/loop}
  • - +33 09 08 07 06 05 + {if $CELLPHONE != ""} + {$CELLPHONE} + {/if} + {if $PHONE != ""} +
    {$PHONE} + {/if}
+ + + {loop type="address" name="customer.addresses" customer="current"} + + + + + + + + {/loop} + + + + + +
Add a new address @@ -98,7 +165,7 @@
{/loop} From bf3bc02f8b8c5e01bd810065fdc3ed2fa35848ed Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 16:46:12 +0200 Subject: [PATCH 10/52] fix fixture dependant unit test --- install/faker.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install/faker.php b/install/faker.php index 66303f05a..11aad8651 100755 --- a/install/faker.php +++ b/install/faker.php @@ -189,7 +189,7 @@ try { $featureList = array(); for($i=0; $i<4; $i++) { $feature = new Thelia\Model\Feature(); - $feature->setVisible(rand(1, 10)>7 ? 0 : 1); + $feature->setVisible(1); $feature->setPosition($i); setI18n($faker, $feature); @@ -257,7 +257,7 @@ try { for($i=0; $i<4; $i++) { $folder = new Thelia\Model\Folder(); $folder->setParent(0); - $folder->setVisible(rand(1, 10)>7 ? 0 : 1); + $folder->setVisible(1); $folder->setPosition($i); setI18n($faker, $folder); @@ -270,7 +270,7 @@ try { for($j=1; $jsetParent($folder->getId()); - $subfolder->setVisible(rand(1, 10)>7 ? 0 : 1); + $subfolder->setVisible(1); $subfolder->setPosition($j); setI18n($faker, $subfolder); @@ -283,7 +283,7 @@ try { for($k=0; $kaddFolder($subfolder); - $content->setVisible(rand(1, 10)>7 ? 0 : 1); + $content->setVisible(1); $content->setPosition($k); setI18n($faker, $content); @@ -418,7 +418,7 @@ function createProduct($faker, $category, $position, $template, &$productIdList) $product = new Thelia\Model\Product(); $product->setRef($category->getId() . '_' . $position . '_' . $faker->randomNumber(8)); $product->addCategory($category); - $product->setVisible(rand(1, 10)>7 ? 0 : 1); + $product->setVisible(1); $product->setPosition($position); $product->setTaxRuleId(1); $product->setTemplate($template); @@ -440,7 +440,7 @@ function createCategory($faker, $parent, $position, &$categoryIdList, $contentId { $category = new Thelia\Model\Category(); $category->setParent($parent); - $category->setVisible(rand(1, 10)>7 ? 0 : 1); + $category->setVisible(1); $category->setPosition($position); setI18n($faker, $category); From cfc52c4e7fade57c5d5f5f157eab6a3c84de5cc9 Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 18:15:09 +0200 Subject: [PATCH 11/52] Working : install wizard : type inference --- core/lib/Thelia/Controller/BaseController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 19e62a400..d5c54e991 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -31,6 +31,7 @@ use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Router; use Thelia\Core\Security\SecurityContext; +use Thelia\Core\Translation\Translator; use Thelia\Tools\URL; use Thelia\Tools\Redirect; use Thelia\Core\Template\ParserContext; @@ -89,7 +90,7 @@ class BaseController extends ContainerAware * * return the Translator * - * @return mixed \Thelia\Core\Translation\Translator + * @return Translator */ public function getTranslator() { From afa9a46abf332ee2850996d2c078b9be8e253172 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Mon, 16 Sep 2013 18:55:29 +0200 Subject: [PATCH 12/52] order delivery form --- core/lib/Thelia/Config/Resources/config.xml | 2 + .../Thelia/Config/Resources/routing/front.xml | 15 ++- .../Controller/Front/OrderController.php | 79 ++++++++++++++ core/lib/Thelia/Core/Event/OrderEvent.php | 101 ++++++++++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 9 +- .../Core/HttpFoundation/Session/Session.php | 20 ++-- core/lib/Thelia/Form/OrderDelivery.php | 94 ++++++++++++++++ templates/default/cart.html | 2 +- templates/default/cart_billing.html | 4 +- 9 files changed, 307 insertions(+), 19 deletions(-) create mode 100755 core/lib/Thelia/Controller/Front/OrderController.php create mode 100755 core/lib/Thelia/Core/Event/OrderEvent.php create mode 100755 core/lib/Thelia/Form/OrderDelivery.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 691cf2198..0eda0c37b 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -58,6 +58,8 @@ + + diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index cea964153..a8b91a05d 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -98,11 +98,6 @@ cart - - Thelia\Controller\Front\DefaultController::noAction - cart_billing - - Thelia\Controller\Front\CartController::addItem @@ -117,6 +112,16 @@ cart + + Thelia\Controller\Front\DefaultController::noAction + cart_billing + + + + Thelia\Controller\Front\OrderController::deliver + cart_billing + + diff --git a/core/lib/Thelia/Controller/Front/OrderController.php b/core/lib/Thelia/Controller/Front/OrderController.php new file mode 100755 index 000000000..0508b4dc9 --- /dev/null +++ b/core/lib/Thelia/Controller/Front/OrderController.php @@ -0,0 +1,79 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Controller\Front; + +use Propel\Runtime\Exception\PropelException; +use Thelia\Form\Exception\FormValidationException; +use Thelia\Core\Event\OrderEvent; +use Thelia\Core\Event\TheliaEvents; +use Symfony\Component\HttpFoundation\Request; +use Thelia\Model\Order; + +class OrderController extends BaseFrontController +{ + /** + * set billing address + * set delivery address + * set delivery module + */ + public function deliver() + { + $orderEvent = $this->getOrderEvent(); + //$orderEvent->setBillingAddress($this->getRequest()->get("billing-address")); + $orderEvent->setDeliveryAddress($this->getRequest()->get("delivery-address")); + $orderEvent->setDeliveryModule($this->getRequest()->get("delivery-module")); + + try { + //$this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_BILLING_ADDRESS, $orderEvent); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent); + + $this->redirectSuccess(); + } catch (PropelException $e) { + $this->getParserContext()->setGeneralError($e->getMessage()); + } + + } + + protected function getOrderEvent() + { + $order = $this->getOrder($this->getRequest()); + + return new OrderEvent($order); + } + + public function getOrder(Request $request) + { + $session = $request->getSession(); + + if (null !== $order = $session->getOrder()) { + return $order; + } + + $order = new Order(); + + $session->setOrder($order); + + return $order; + } +} diff --git a/core/lib/Thelia/Core/Event/OrderEvent.php b/core/lib/Thelia/Core/Event/OrderEvent.php new file mode 100755 index 000000000..8b6762e99 --- /dev/null +++ b/core/lib/Thelia/Core/Event/OrderEvent.php @@ -0,0 +1,101 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + +use Thelia\Model\Address; +use Thelia\Model\AddressQuery; +use Thelia\Model\Module; +use Thelia\Model\Order; + +class OrderEvent extends ActionEvent +{ + protected $order = null; + protected $billingAddress = null; + protected $deliveryAddress = null; + protected $deliveryModule = null; + + /** + * @param Order $order + */ + public function __construct(Order $order) + { + $this->order = $order; + } + + /** + * @param Address $address + */ + public function setBillingAddress(Address $address) + { + $this->deliveryAddress = $address->getId(); + } + + /** + * @param Address $address + */ + public function setDeliveryAddress(Address $address) + { + $this->deliveryAddress = $address->getId(); + } + + /** + * @param Module $module + */ + public function setDeliveryModule(Module $module) + { + $this->deliveryModule = $module->getId(); + } + + /** + * @return null|Order + */ + public function getOrder() + { + return $this->order; + } + + /** + * @return array|mixed|Address + */ + public function getBillingAddress() + { + return AddressQuery::create()->findPk($this->billingAddress); + } + + /** + * @return array|mixed|Address + */ + public function getDeliveryAddress() + { + return AddressQuery::create()->findPk($this->deliveryAddress); + } + + /** + * @return array|mixed|Address + */ + public function getDeliveryModule() + { + return AddressQuery::create()->findPk($this->deliveryModule); + } +} diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 2867762aa..02256a360 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -218,13 +218,20 @@ final class TheliaEvents const CART_DELETEITEM = "action.deleteArticle"; + /** + * Order linked event + */ + const ORDER_SET_BILLING_ADDRESS = "action.order.setBillingAddress"; + const ORDER_SET_DELIVERY_ADDRESS = "action.order.setDeliveryAddress"; + const ORDER_SET_DELIVERY_MODULE = "action.order.setDeliveryModule"; + /** * Sent on image processing */ const IMAGE_PROCESS = "action.processImage"; /** - * Sent on cimage cache clear request + * Sent on image cache clear request */ const IMAGE_CLEAR_CACHE = "action.clearImageCache"; diff --git a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php index e9e3d50bf..5edd007b3 100755 --- a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php +++ b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php @@ -29,6 +29,7 @@ use Thelia\Exception\InvalidCartException; use Thelia\Model\CartQuery; use Thelia\Model\Cart; use Thelia\Model\Currency; +use Thelia\Model\Order; use Thelia\Tools\URL; use Thelia\Model\Lang; @@ -43,6 +44,8 @@ use Thelia\Model\Lang; class Session extends BaseSession { /** + * @param bool $forceDefault + * * @return \Thelia\Model\Lang|null */ public function getLang($forceDefault = true) @@ -205,22 +208,19 @@ class Session extends BaseSession return $this; } - /** - * assign delivery id in session - * - * @param $delivery_id - * @return $this - */ - public function setDelivery($delivery_id) + // -- Order ------------------------------------------------------------------ + + + public function setOrder(Order $order) { - $this->set("thelia.delivery_id", $delivery_id); + $this->set("thelia.order", $order); return $this; } - public function getDelivery() + public function getOrder() { - return $this->get("thelia.delivery_id"); + return $this->get("thelia.order"); } diff --git a/core/lib/Thelia/Form/OrderDelivery.php b/core/lib/Thelia/Form/OrderDelivery.php new file mode 100755 index 000000000..d0ee0efb3 --- /dev/null +++ b/core/lib/Thelia/Form/OrderDelivery.php @@ -0,0 +1,94 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints; +use Symfony\Component\Validator\ExecutionContextInterface; +use Thelia\Model\AddressQuery; +use Thelia\Model\ConfigQuery; +use Thelia\Core\Translation\Translator; +use Thelia\Model\ModuleQuery; +use Thelia\Module\BaseModule; + +/** + * Class OrderDelivery + * @package Thelia\Form + * @author Etienne Roudeix + */ +class OrderDelivery extends BaseForm +{ + protected function buildForm() + { + $this->formBuilder + ->add("delivery-address", "integer", array( + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + "methods" => array( + array($this, "verifyDeliveryAddress") + ) + )) + ) + )) + ->add("delivery-module", "integer", array( + "constraints" => array( + new Constraints\NotBlank(), + new Constraints\Callback(array( + "methods" => array( + array($this, "verifyDeliveryModule") + ) + )) + ) + )); + } + + public function verifyDeliveryAddress($value, ExecutionContextInterface $context) + { + $address = AddressQuery::create() + ->findPk($value); + + if(null === $address) { + $context->addViolation("Address ID not found"); + } elseif($address->getCustomerId() !== $this->request->getSession()->getCustomerUser()->getId()) { + $context->addViolation("Address does not belong to you"); + } + } + + public function verifyDeliveryModule($value, ExecutionContextInterface $context) + { + $module = ModuleQuery::create() + ->filterByType(BaseModule::DELIVERY_MODULE_TYPE) + ->filterByActivate(1) + ->filterById($value) + ->find(); + + if(null === $module) { + $context->addViolation("Delivery module ID not found"); + } + } + + public function getName() + { + return "thelia_order_delivery"; + } +} \ No newline at end of file diff --git a/templates/default/cart.html b/templates/default/cart.html index 6f91d8581..483e34436 100644 --- a/templates/default/cart.html +++ b/templates/default/cart.html @@ -133,7 +133,7 @@ Continue Shopping - Proceed checkout + Proceed checkout diff --git a/templates/default/cart_billing.html b/templates/default/cart_billing.html index 123596609..45c6eadf1 100644 --- a/templates/default/cart_billing.html +++ b/templates/default/cart_billing.html @@ -24,7 +24,7 @@ 4 Secure payment
- +
@@ -164,7 +164,7 @@ {loop type="delivery" name="deliveries" force_return="true"}
From 63472b9f80e1be15a736bd38a1bc921f7ec515f4 Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 19:00:28 +0200 Subject: [PATCH 13/52] WIP : install wizard : step 1, 2, 3 --- core/lib/Thelia/Config/Resources/config.xml | 2 + .../Config/Resources/routing/install.xml | 12 +- .../Controller/Install/InstallController.php | 162 +++++++++++--- core/lib/Thelia/Form/InstallStep3Form.php | 111 ++++++++++ core/lib/Thelia/Install/BaseInstall.php | 5 +- .../Install/CheckDatabaseConnection.php | 100 +++++++++ core/lib/Thelia/Install/CheckPermission.php | 202 +++++++++++++++++- templates/install/index.html | 2 +- templates/install/layout.tpl | 6 +- templates/install/step-2.html | 4 +- templates/install/step-3.html | 74 +++++-- 11 files changed, 612 insertions(+), 68 deletions(-) create mode 100755 core/lib/Thelia/Form/InstallStep3Form.php create mode 100644 core/lib/Thelia/Install/CheckDatabaseConnection.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 691cf2198..b90ca3e45 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -40,6 +40,8 @@ + + diff --git a/core/lib/Thelia/Config/Resources/routing/install.xml b/core/lib/Thelia/Config/Resources/routing/install.xml index 37ddde487..720761b40 100644 --- a/core/lib/Thelia/Config/Resources/routing/install.xml +++ b/core/lib/Thelia/Config/Resources/routing/install.xml @@ -5,27 +5,27 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - Thelia\Controller\Install\InstallController::index + Thelia\Controller\Install\InstallController::indexAction - Thelia\Controller\Install\InstallController::checkPermission + Thelia\Controller\Install\InstallController::checkPermissionAction - Thelia\Controller\Install\InstallController::databaseConnection + Thelia\Controller\Install\InstallController::databaseConnectionAction - Thelia\Controller\Install\InstallController::databaseSelection + Thelia\Controller\Install\InstallController::databaseSelectionAction - Thelia\Controller\Install\InstallController::generalInformation + Thelia\Controller\Install\InstallController::generalInformationAction - Thelia\Controller\Install\InstallController::thanks + Thelia\Controller\Install\InstallController::thanksAction diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php index 648ae843e..a6b0d975d 100644 --- a/core/lib/Thelia/Controller/Install/InstallController.php +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -22,7 +22,12 @@ /*************************************************************************************/ namespace Thelia\Controller\Install; +use Thelia\Form\Exception\FormValidationException; +use Thelia\Form\InstallStep3Form; +use Thelia\Install\CheckDatabaseConnection; use Thelia\Install\CheckPermission; +use Thelia\Install\Exception\AlreadyInstallException; +use Thelia\Install\Exception\InstallException; /** * Class InstallController @@ -35,9 +40,14 @@ class InstallController extends BaseInstallController { public function indexAction() { - //$this->verifyStep(1); + $args = array(); + try { + //$this->verifyStep(1); // @todo implement + $this->getSession()->set("step", 1); + } catch (AlreadyInstallException $e) { + $args['isAlreadyInstalled'] = true; + } - $this->getSession()->set("step", 1); return $this->render("index.html"); } @@ -49,29 +59,22 @@ class InstallController extends BaseInstallController */ public function checkPermissionAction() { + try { + //$this->verifyStep(2); // @todo implement + $checkPermission = new CheckPermission(true, $this->getTranslator()); + $args['isValid'] = $isValid = $checkPermission->exec(); + $args['validationMessages'] = $checkPermission->getValidationMessages(); + + $this->getSession()->set("step", 2); + } catch (AlreadyInstallException $e) { + $args['isAlreadyInstalled'] = true; + } $args = array(); - var_dump('step2'); - //$this->verifyStep(2); - $checkPermission = new CheckPermission(true, $this->getTranslator()); - $args['isValid'] = $isValid = $checkPermission->exec(); - $args['validationMessages'] = $checkPermission->getValidationMessages(); - - $this->getSession()->set("step", 2); return $this->render("step-2.html", $args); } - /** - * Database connexion tests - * - * @return \Symfony\Component\HttpFoundation\Response - */ - public function databaseConnection() - { - var_dump('step 3 bis'); - } - /** * Database connexion tests * @@ -79,15 +82,95 @@ class InstallController extends BaseInstallController */ public function databaseConnectionAction() { - var_dump('step 3'); - exit(); - //$this->verifyStep(2); + $args = array(); - //$permission = new CheckPermission(); + try { + //$this->verifyStep(2); // @todo implement - $this->getSession()->set("step", 3); + if ($this->getRequest()->isMethod('POST')) { + // Create the form from the request + $step3Form = new InstallStep3Form($this->getRequest()); - return $this->render("step-3.html"); + $message = false; + try { + // Check the form against constraints violations + $form = $this->validateForm($step3Form, 'POST'); + + // Get the form field values + $data = $form->getData(); + var_dump('data', $data); + + // @todo implement tests + try { + new CheckDatabaseConnection( + $data['host'], + $data['user'], + $data['password'], + $data['port'], + true, + $this->getTranslator() + ); + + $this->getSession()->set('install', array( + 'host' =>$data['host'], + 'user' => $data['user'], + 'password' => $data['password'], + 'port' => $data['port'] + ) + ); + } catch (InstallException $e) { + $message = $this->getTranslator()->trans( + 'Can\'t connect with these credentials to this server', + array(), + 'install-wizard' + ); + } + + // $this->redirect( + // str_replace( + // '{id}', + // $couponEvent->getCoupon()->getId(), + // $creationForm->getSuccessUrl() + // ) + // ); + } catch (FormValidationException $e) { + // Invalid data entered + $message = $this->getTranslator()->trans( + 'Please check your input:', + array(), + 'install-wizard' + ); + + } catch (\Exception $e) { + // Any other error + $message = $this->getTranslator()->trans( + 'Sorry, an error occurred:', + array(), + 'install-wizard' + ); + } + + if ($message !== false) { + // Mark the form as with error + $step3Form->setErrorMessage($message); + + // Send the form and the error to the parser + $this->getParserContext() + ->addForm($step3Form) + ->setGeneralError($message); + } + } + + $this->getSession()->set("step", 3); + + $args['edit_language_locale'] = $this->getSession()->getLang()->getLocale(); + $args['formAction'] = 'install/step/3'; + + } catch (AlreadyInstallException $e) { + $args['isAlreadyInstalled'] = true; + } + + return $this->render('step-3.html', $args); } /** @@ -97,7 +180,14 @@ class InstallController extends BaseInstallController */ public function databaseSelectionAction() { - //$this->verifyStep(2); + $args = array(); + try { + + } catch (AlreadyInstallException $e) { + $args['isAlreadyInstalled'] = true; + } + + //$this->verifyStep(2); // @todo implement //$permission = new CheckPermission(); @@ -107,13 +197,19 @@ class InstallController extends BaseInstallController } /** - * Set general informations + * Set general information * * @return \Symfony\Component\HttpFoundation\Response */ public function generalInformationAction() { - //$this->verifyStep(2); + $args = array(); + try { + + } catch (AlreadyInstallException $e) { + $args['isAlreadyInstalled'] = true; + } + //$this->verifyStep(2); // @todo implement //$permission = new CheckPermission(); @@ -129,7 +225,13 @@ class InstallController extends BaseInstallController */ public function thanksAction() { - //$this->verifyStep(2); + $args = array(); + try { + + } catch (AlreadyInstallException $e) { + $args['isAlreadyInstalled'] = true; + } + //$this->verifyStep(2); // @todo implement //$permission = new CheckPermission(); @@ -162,5 +264,7 @@ class InstallController extends BaseInstallController } break; } + + return true; } } diff --git a/core/lib/Thelia/Form/InstallStep3Form.php b/core/lib/Thelia/Form/InstallStep3Form.php new file mode 100755 index 000000000..9388f14db --- /dev/null +++ b/core/lib/Thelia/Form/InstallStep3Form.php @@ -0,0 +1,111 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints\GreaterThan; +use Symfony\Component\Validator\Constraints\NotBlank; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/29/13 + * Time: 3:45 PM + * + * Allow to build a form Install Step 3 Database connection + * + * @package Coupon + * @author Guillaume MOREL + * + */ +class InstallStep3Form extends BaseForm +{ + /** + * Build Coupon form + * + * @return void + */ + protected function buildForm() + { + $this->formBuilder + ->add( + 'host', + 'text', + array( + 'constraints' => array( + new NotBlank() + ) + ) + ) + ->add( + 'user', + 'text', + array( + 'constraints' => array( + new NotBlank() + ) + ) + ) + ->add( + 'password', + 'text', + array( + 'constraints' => array( + new NotBlank() + ) + ) + ) + ->add( + 'port', + 'text', + array( + 'constraints' => array( + new NotBlank(), + new GreaterThan( + array( + 'value' => 0 + ) + ) + ) + ) + ) + ->add( + 'locale', + 'hidden', + array( + 'constraints' => array( + new NotBlank() + ) + ) + ); + } + + /** + * Get form name + * + * @return string + */ + public function getName() + { + return 'thelia_install_step3'; + } +} diff --git a/core/lib/Thelia/Install/BaseInstall.php b/core/lib/Thelia/Install/BaseInstall.php index 86928236a..aa41140dd 100644 --- a/core/lib/Thelia/Install/BaseInstall.php +++ b/core/lib/Thelia/Install/BaseInstall.php @@ -37,6 +37,8 @@ abstract class BaseInstall * Constructor * * @param bool $verifyInstall Verify if an installation already exists + * + * @throws Exception\AlreadyInstallException */ public function __construct($verifyInstall = true) { @@ -47,10 +49,9 @@ abstract class BaseInstall } else { $this->isConsoleMode = false; } - /* TODO : activate this part if (file_exists(THELIA_ROOT . '/local/config/database.yml') && $verifyInstall) { throw new AlreadyInstallException("Thelia is already installed"); - }*/ + } $this->exec(); diff --git a/core/lib/Thelia/Install/CheckDatabaseConnection.php b/core/lib/Thelia/Install/CheckDatabaseConnection.php new file mode 100644 index 000000000..50c117d22 --- /dev/null +++ b/core/lib/Thelia/Install/CheckDatabaseConnection.php @@ -0,0 +1,100 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Install; + +use PDO; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use Symfony\Component\Translation\TranslatorInterface; +use Thelia\Core\Translation\Translator; +use Thelia\Install\Exception\InstallException; + + +/** + * Class CheckDatabaseConnection + * + * Take care of integration tests (database connection) + * + * @package Thelia\Install + * @author Manuel Raynaud + * @author Guillaume MOREL + */ +class CheckDatabaseConnection extends BaseInstall +{ + protected $validationMessages = array(); + + /** @var bool If permissions are OK */ + protected $isValid = true; + + /** @var TranslatorInterface Translator Service */ + protected $translator = null; + + /** @var string Database host information */ + protected $host = null; + + /** @var string Database user information */ + protected $user = null; + + /** @var string Database password information */ + protected $password = null; + + /** @var int Database port information */ + protected $port = null; + + /** + * Constructor + * + * @param string $host Database host information + * @param string $user Database user information + * @param string $password Database password information + * @param int $port Database port information + * @param bool $verifyInstall If verify install + * @param Translator $translator Translator Service + * necessary for install wizard + */ + public function __construct($host, $user, $password, $port, $verifyInstall = true, Translator $translator = null) + { + $this->host = $host; + $this->user = $user; + $this->password = $password; + $this->port = $port; + + parent::__construct($verifyInstall); + } + + /** + * Perform database connection check + * + * @return bool + */ + public function exec() + { + $link = mysql_connect($this->host . ':' . $this->port, $this->user, $this->password); + if (!$link) { + throw new InstallException('Can\'t connect to the given credentials'); + } + mysql_close($link); + } + +} diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index d924bac35..d07b8ed83 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -52,6 +52,13 @@ class CheckPermission extends BaseInstall self::DIR_CACHE, ); + /** @var array Minimum server configuration necessary */ + protected $minServerConfigurationNecessary = array( + 'memory_limit' => 134217728, + 'post_max_size' => 20971520, + 'upload_max_filesize' => 2097152 + ); + protected $validationMessages = array(); /** @var bool If permissions are OK */ @@ -71,6 +78,12 @@ class CheckPermission extends BaseInstall { $this->translator = $translator; + $this->validationMessages['php_version'] = array( + 'text' => $this->getI18nPhpVersionText('5.4', phpversion(), true), + 'hint' => $this->getI18nPhpVersionHint(), + 'status' => true + ); + foreach ($this->directoriesToBeWritable as $directory) { $this->validationMessages[$directory] = array( 'text' => '', @@ -78,6 +91,14 @@ class CheckPermission extends BaseInstall 'status' => true ); } + foreach ($this->minServerConfigurationNecessary as $key => $value) { + $this->validationMessages[$key] = array( + 'text' => '', + 'hint' => $this->getI18nConfigHint(), + 'status' => true + ); + } + parent::__construct($verifyInstall); } @@ -88,19 +109,35 @@ class CheckPermission extends BaseInstall */ public function exec() { + if (version_compare(phpversion(), '5.4', '<')) { + $this->validationMessages['php_version'] = $this->getI18nPhpVersionText('5.4', phpversion(), false); + } + foreach ($this->directoriesToBeWritable as $directory) { $fullDirectory = THELIA_ROOT . $directory; - $this->validationMessages[$directory]['text'] = $this->getI18nText($fullDirectory, true); + $this->validationMessages[$directory]['text'] = $this->getI18nDirectoryText($fullDirectory, true); if (is_writable($fullDirectory) === false) { if (!$this->makeDirectoryWritable($fullDirectory)) { $this->isValid = false; $this->validationMessages[$directory]['status'] = false; - $this->validationMessages[$directory]['text'] = $this->getI18nText($fullDirectory, false); - $this->validationMessages[$directory]['hint'] = $this->getI18nHint($fullDirectory); + $this->validationMessages[$directory]['text'] = $this->getI18nDirectoryText($fullDirectory, false); + $this->validationMessages[$directory]['hint'] = $this->getI18nDirectoryHint($fullDirectory); } } } + foreach ($this->minServerConfigurationNecessary as $key => $value) { + $this->validationMessages[$key]['text'] = $this->getI18nConfigText($key, $this->formatBytes($value), ini_get($key), true); + if (!$this->verifyServerMemoryValues($key, $value)) { + $this->isValid = false; + $this->validationMessages[$key]['status'] = false; + $this->validationMessages[$key]['text'] = $this->getI18nConfigText($key, $this->formatBytes($value), ini_get($key), false);; + } + } + + + + return $this->isValid; } @@ -144,7 +181,7 @@ class CheckPermission extends BaseInstall * * @return string */ - protected function getI18nText($directory, $isValid) + protected function getI18nDirectoryText($directory, $isValid) { if ($this->translator !== null) { if ($isValid) { @@ -174,7 +211,7 @@ class CheckPermission extends BaseInstall * * @return string */ - protected function getI18nHint($directory) + protected function getI18nDirectoryHint($directory) { if ($this->translator !== null) { $sentence = 'chmod 777 %directory% on your server with admin rights could help'; @@ -191,4 +228,159 @@ class CheckPermission extends BaseInstall return $translatedText; } + + + /** + * Get Translated text about the directory state + * Not usable with CLI + * + * @param string $key .ini file key + * @param string $expectedValue Expected server value + * @param string $currentValue Actual server value + * @param bool $isValid If server configuration is valid + * + * @return string + */ + protected function getI18nConfigText($key, $expectedValue, $currentValue, $isValid) + { + if ($isValid) { + $sentence = 'Your %key% server configuration (currently %currentValue%) is well enough to run Thelia2 (%expectedValue% needed)'; + } else { + $sentence = 'Your %key% server configuration (currently %currentValue%) is not sufficient enough in order to run Thelia2 (%expectedValue% needed)'; + } + + $translatedText = $this->translator->trans( + $sentence, + array( + '%key%' => $key, + '%expectedValue%' => $expectedValue, + '%currentValue%' => $currentValue, + ), + 'install-wizard' + ); + + return $translatedText; + } + + /** + * Get Translated hint about the config requirement issue + * + * @return string + */ + protected function getI18nConfigHint() + { + $sentence = 'Modifying this value on your server php.ini file with admin rights could help'; + $translatedText = $this->translator->trans( + $sentence, + array(), + 'install-wizard' + ); + + return $translatedText; + } + + /** + * Get Translated hint about the PHP version requirement issue + * + * @param string $expectedValue + * @param string $currentValue + * @param bool $isValid + * + * @return string + */ + protected function getI18nPhpVersionText($expectedValue, $currentValue, $isValid) + { + if ($this->translator !== null) { + if ($isValid) { + $sentence = 'Your PHP version %currentValue% is well enough to run Thelia2 (%expectedValue% needed)'; + } else { + $sentence = 'Your PHP version %currentValue% is not sufficient enough to run Thelia2 (%expectedValue% needed)'; + } + + $translatedText = $this->translator->trans( + $sentence, + array( + '%expectedValue%' => $expectedValue, + '%currentValue%' => $currentValue, + ), + 'install-wizard' + ); + } else { + $translatedText = sprintf('Thelia needs at least PHP %s (%s currently)', $expectedValue, $currentValue); + } + + return $translatedText; + } + + /** + * Get Translated hint about the config requirement issue + * + * @return string + */ + protected function getI18nPhpVersionHint() + { + $sentence = 'Upgrading your version of PHP with admin rights could help'; + $translatedText = $this->translator->trans( + $sentence, + array(), + 'install-wizard' + ); + + return $translatedText; + } + + /** + * Check if a server memory value is met or not + * + * @param string $key .ini file key + * @param int $necessaryValueInBytes Expected value in bytes + * + * @return bool + */ + protected function verifyServerMemoryValues($key, $necessaryValueInBytes) + { + $serverValueInBytes = $this->returnBytes(ini_get($key)); + + return ($serverValueInBytes >= $necessaryValueInBytes); + } + + /** + * Return bytes from memory .ini value + * + * @param string $val .ini value + * + * @return int + */ + protected function returnBytes($val) + { + $val = trim($val); + $last = strtolower($val[strlen($val)-1]); + switch($last) { + // The 'G' modifier is available since PHP 5.1.0 + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + + return $val; + } + + /** + * Convert bytes to readable string + * + * @param int $bytes bytes + * @param int $precision conversion precision + * + * @return string + */ + protected function formatBytes($bytes, $precision = 2) + { + $base = log($bytes) / log(1024); + $suffixes = array('', 'k', 'M', 'G', 'T'); + + return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)]; + } } diff --git a/templates/install/index.html b/templates/install/index.html index dd1d5f62b..b7843d528 100644 --- a/templates/install/index.html +++ b/templates/install/index.html @@ -34,7 +34,7 @@
diff --git a/templates/install/layout.tpl b/templates/install/layout.tpl index 6b38292e2..1497d7ea5 100644 --- a/templates/install/layout.tpl +++ b/templates/install/layout.tpl @@ -26,8 +26,12 @@
{* -- Main page content section ----------------------------------------- *} + {if $isAlreadyInstalled} +
{intl l='Thelia is already installed'}
+ {else} + {block name="main-content"}Put here the content of the template{/block} + {/if} - {block name="main-content"}Put here the content of the template{/block} {* -- Footer section ---------------------------------------------------- *} diff --git a/templates/install/step-2.html b/templates/install/step-2.html index a05267c7c..fbd34ddb5 100644 --- a/templates/install/step-2.html +++ b/templates/install/step-2.html @@ -37,8 +37,8 @@ diff --git a/templates/install/step-3.html b/templates/install/step-3.html index cb4157dd7..f93b0182b 100644 --- a/templates/install/step-3.html +++ b/templates/install/step-3.html @@ -23,29 +23,59 @@ -
- - -
- - -
-
- - -
-
- - -
- + {form name="thelia.install.step3"} +
+ {if ! empty($general_error) } +
{$general_error}
+ {/if} -
- - + {form_hidden_fields form=$form} + + {form_field form=$form field='locale'} + + {/form_field} + +
+ {form_field form=$form field='host'} +
+ + + {if $error}{$message}{/if} +
+ {/form_field} + + {form_field form=$form field='user'} +
+ + + {if $error}{$message}{/if} +
+ {/form_field} + + {form_field form=$form field='password'} +
+ + + {if $error}{$message}{/if} +
+ {/form_field} + + {form_field form=$form field='port'} +
+ + + {if $error}{$message}{/if} +
+ {/form_field} +
+ + Back + + {/form} + @@ -209,8 +291,16 @@ {block name="javascript-initialization"} {/block} \ No newline at end of file From 347e5e5089f7305b7dae2eab222795cfca40e557 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 17 Sep 2013 19:52:20 +0200 Subject: [PATCH 47/52] fix postage display --- templates/default/order_invoice.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/default/order_invoice.html b/templates/default/order_invoice.html index 033c46838..865fdb267 100644 --- a/templates/default/order_invoice.html +++ b/templates/default/order_invoice.html @@ -149,7 +149,7 @@ Total TTC
- {currency attr="symbol"} {cart attr="total_taxed_price"} + {currency attr="symbol"} {{cart attr="total_taxed_price"} + {order attr="postage"}}
From 03375a65b3cd7d385d6435e8d773cac41accc33a Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 17 Sep 2013 20:07:50 +0200 Subject: [PATCH 48/52] payment loop --- core/lib/Thelia/Config/Resources/config.xml | 1 + templates/default/order_invoice.html | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 326f52145..c0199652d 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -24,6 +24,7 @@ + diff --git a/templates/default/order_invoice.html b/templates/default/order_invoice.html index 865fdb267..b08283c6c 100644 --- a/templates/default/order_invoice.html +++ b/templates/default/order_invoice.html @@ -258,11 +258,15 @@ {/form_field} + {form_field form=$form field='payment-module'} +
Choose your payment method
    - $value) { ?> + + {loop type="payment" name="payments" force_return="true"} +
  • - + + {/loop} +
+ {/form_field} + Back From da7f9e07c407f3d70f2aea053270bebbddb1ea80 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 17 Sep 2013 20:15:28 +0200 Subject: [PATCH 49/52] create test for UrlRewritingTrait --- core/lib/Thelia/Model/RewritingUrl.php | 12 +-- .../Thelia/Model/Tools/UrlRewritingTrait.php | 9 +- .../Tests/Rewriting/ProductRewriteTest.php | 88 +++++++++++++++++++ 3 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php diff --git a/core/lib/Thelia/Model/RewritingUrl.php b/core/lib/Thelia/Model/RewritingUrl.php index 9dd826d01..a13777c41 100644 --- a/core/lib/Thelia/Model/RewritingUrl.php +++ b/core/lib/Thelia/Model/RewritingUrl.php @@ -2,25 +2,25 @@ namespace Thelia\Model; +use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\RewritingUrl as BaseRewritingUrl; use Thelia\Model\RewritingUrlQuery; class RewritingUrl extends BaseRewritingUrl { - public function preSave(ConnectionInterface $con = null) + public function postInsert(ConnectionInterface $con = null) { - if($this->getRedirected() == 0) { - //check if rewriting url alredy exists and put redirect to 1 + if(null !== $this->getRedirected()) { + //check if rewriting url alredy exists and put redirect to the new one RewritingUrlQuery::create() ->filterByView($this->getView()) ->filterByViewId($this->getViewId()) ->filterByViewLocale($this->getViewLocale()) + ->filterByRedirected($this->getId(), Criteria::NOT_IN) ->update(array( - "redirect" => 1 + "Redirected" => $this->getId() )); } - - return true; } } diff --git a/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php b/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php index c9154a0db..1b9087626 100644 --- a/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php +++ b/core/lib/Thelia/Model/Tools/UrlRewritingTrait.php @@ -55,17 +55,13 @@ trait UrlRewritingTrait { public function generateRewrittenUrl($locale) { if ($this->isNew()) { - throw new \RuntimeException(sprintf('Object %s must be save before generating url', $this->getRewrittenUrlViewName())); + throw new \RuntimeException(sprintf('Object %s must be saved before generating url', $this->getRewrittenUrlViewName())); } // Borrowed from http://stackoverflow.com/questions/2668854/sanitizing-strings-to-make-them-url-and-filename-safe $this->setLocale($locale); - $title = $this->getTitle(); - - if (null === $title) { - throw new \RuntimeException(sprintf('Impossible to generate url if title does not exists for the locale %s', $locale)); - } + $title = $this->getTitle() ?: $this->getRef(); // Replace all weird characters with dashes $string = preg_replace('/[^\w\-~_\.]+/u', '-', $title); @@ -88,7 +84,6 @@ trait UrlRewritingTrait { ->setView($this->getRewrittenUrlViewName()) ->setViewId($this->getId()) ->setViewLocale($locale) - ->setRedirected(0) ->save() ; } diff --git a/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php b/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php new file mode 100644 index 000000000..c38773814 --- /dev/null +++ b/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php @@ -0,0 +1,88 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Rewriting; +use Thelia\Model\Product; +use Thelia\Model\ProductQuery; + + +/** + * Class ProductRewriteTest + * @package Thelia\Tests\Rewriting + * @author Manuel Raynaud + */ +class ProductRewriteTest extends \PHPUnit_Framework_TestCase +{ + protected static $productId; + + public static function setUpBeforeClass() + { + $product = new Product(); + $product->setRef(sprintf("TestRewrittenProduct%s",uniqid())) + ->setPosition(1) + ->setVisible(1) + ->setLocale('en_US') + ->setTitle('My english super Title') + ->setLocale('fr_FR') + ->setTitle('Mon super titre en français') + ->save(); + + self::$productId = $product->getId(); + } + + /** + * @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl + */ + public function testFrenchRewrittenUrl() + { + $product = ProductQuery::create()->findPk(self::$productId); + + $rewrittenUrl = $product->generateRewrittenUrl('fr_FR'); + $this->assertNotNull($rewrittenUrl, "rewritten url can not be null"); + $this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $rewrittenUrl); + //mon-super-titre-en-français-2.html + } + + /** + * @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl + */ + public function testEnglishRewrittenUrl() + { + $product = ProductQuery::create()->findPk(self::$productId); + + $rewrittenUrl = $product->generateRewrittenUrl('en_US'); + $this->assertNotNull($rewrittenUrl, "rewritten url can not be null"); + $this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage Object product must be saved before generating url + */ + public function testOnNotSavedProduct() + { + $product = new Product(); + + $product->generateRewrittenUrl('fr_FR'); + } +} \ No newline at end of file From f068539e79ef1fd42213579fa52aa27782b171b0 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 17 Sep 2013 20:16:51 +0200 Subject: [PATCH 50/52] add covers annotation in ProductRewriteTest --- core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php b/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php index c38773814..b6601289d 100644 --- a/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php +++ b/core/lib/Thelia/Tests/Rewriting/ProductRewriteTest.php @@ -76,6 +76,7 @@ class ProductRewriteTest extends \PHPUnit_Framework_TestCase } /** + * @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl * @expectedException \RuntimeException * @expectedExceptionMessage Object product must be saved before generating url */ From e4b36098c75b6e2a70f9a7836a7707692a07f04b Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 17 Sep 2013 20:29:09 +0200 Subject: [PATCH 51/52] fix typo and remove url generation in postInsert model --- core/lib/Thelia/Controller/Admin/CategoryController.php | 2 +- core/lib/Thelia/Controller/Admin/ProductController.php | 2 +- core/lib/Thelia/Model/Category.php | 1 - core/lib/Thelia/Model/Content.php | 5 ----- core/lib/Thelia/Model/Folder.php | 5 ----- core/lib/Thelia/Model/FolderI18n.php | 6 ++++++ core/lib/Thelia/Model/Product.php | 1 - core/lib/Thelia/Model/ProductI18n.php | 6 ++++++ 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index 8c74c31ec..4d0d15ef1 100755 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -133,7 +133,7 @@ class CategoryController extends AbstractCrudController 'description' => $object->getDescription(), 'postscriptum' => $object->getPostscriptum(), 'visible' => $object->getVisible(), - 'url' => $object->getRewritenUrl($this->getCurrentEditionLocale()), + 'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()), 'parent' => $object->getParent() ); diff --git a/core/lib/Thelia/Controller/Admin/ProductController.php b/core/lib/Thelia/Controller/Admin/ProductController.php index e1b651e60..b167922e0 100644 --- a/core/lib/Thelia/Controller/Admin/ProductController.php +++ b/core/lib/Thelia/Controller/Admin/ProductController.php @@ -141,7 +141,7 @@ class ProductController extends AbstractCrudController 'description' => $object->getDescription(), 'postscriptum' => $object->getPostscriptum(), 'visible' => $object->getVisible(), - 'url' => $object->getRewritenUrl($this->getCurrentEditionLocale()), + 'url' => $object->getRewrittenUrl($this->getCurrentEditionLocale()), 'parent' => $object->getParent() ); diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 204896674..347a0f7f7 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -79,7 +79,6 @@ class Category extends BaseCategory */ public function postInsert(ConnectionInterface $con = null) { - //$this->generateRewrittenUrl($this->getLocale()); $this->dispatchEvent(TheliaEvents::AFTER_CREATECATEGORY, new CategoryEvent($this)); } diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 4d9cf9f3a..10ed2afe3 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -39,9 +39,4 @@ class Content extends BaseContent return true; } - - public function postInsert(ConnectionInterface $con = null) - { - //$this->generateRewrittenUrl($this->getLocale()); - } } diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index e32505d9d..f9006fbd7 100755 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -70,9 +70,4 @@ class Folder extends BaseFolder return true; } - - public function postInsert(ConnectionInterface $con = null) - { - //$this->generateRewrittenUrl($this->getLocale()); - } } diff --git a/core/lib/Thelia/Model/FolderI18n.php b/core/lib/Thelia/Model/FolderI18n.php index d1044452b..7ede39502 100755 --- a/core/lib/Thelia/Model/FolderI18n.php +++ b/core/lib/Thelia/Model/FolderI18n.php @@ -2,8 +2,14 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\FolderI18n as BaseFolderI18n; class FolderI18n extends BaseFolderI18n { + public function postInsert(ConnectionInterface $con = null) + { + $folder = $this->getFolder(); + $folder->generateRewrittenUrl($this->getLocale()); + } } diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index be534298e..fbac7c71a 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -119,7 +119,6 @@ class Product extends BaseProduct */ public function postInsert(ConnectionInterface $con = null) { - //$this->generateRewrittenUrl($this->getLocale()); $this->dispatchEvent(TheliaEvents::AFTER_CREATEPRODUCT, new ProductEvent($this)); } diff --git a/core/lib/Thelia/Model/ProductI18n.php b/core/lib/Thelia/Model/ProductI18n.php index 7507bceb1..6ec3ac4a3 100755 --- a/core/lib/Thelia/Model/ProductI18n.php +++ b/core/lib/Thelia/Model/ProductI18n.php @@ -2,8 +2,14 @@ namespace Thelia\Model; +use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\ProductI18n as BaseProductI18n; class ProductI18n extends BaseProductI18n { + public function postInsert(ConnectionInterface $con = null) + { + $product = $this->getProduct(); + $product->generateRewrittenUrl($this->getLocale()); + } } From 294c48f8abd5e48090a4dc32fa18eb7679f70904 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Tue, 17 Sep 2013 20:32:51 +0200 Subject: [PATCH 52/52] fix content faker --- install/faker.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install/faker.php b/install/faker.php index 3d48fc0e1..eed6db11a 100755 --- a/install/faker.php +++ b/install/faker.php @@ -281,7 +281,7 @@ try { $folder = new Thelia\Model\Folder(); $folder->setParent(0); $folder->setVisible(1); - $folder->setPosition($i); + $folder->setPosition($i+1); setI18n($faker, $folder); $folder->save(); @@ -294,11 +294,11 @@ try { $document->setFolderId($folder->getId()); generate_document($document, 1, 'folder', $folder->getId()); - for($j=1; $jsetParent($folder->getId()); $subfolder->setVisible(1); - $subfolder->setPosition($j); + $subfolder->setPosition($j+1); setI18n($faker, $subfolder); $subfolder->save(); @@ -311,7 +311,7 @@ try { $document->setFolderId($folder->getId()); generate_document($document, 1, 'folder', $subfolder->getId()); - for($k=0; $kaddFolder($subfolder); @@ -320,8 +320,8 @@ try { $collection->prepend($contentFolders[0]->setDefaultFolder(1)); $content->setContentFolders($collection); - $content->setVisible(rand(1, 10)>7 ? 0 : 1); - $content->setPosition($k); + $content->setVisible(1); + $content->setPosition($k+1); setI18n($faker, $content); $content->save();