Merge branch 'master' into template
Conflicts: core/lib/Thelia/Core/Event/TheliaEvents.php core/lib/Thelia/Model/Base/Module.php core/lib/Thelia/Model/Base/ModuleQuery.php core/lib/Thelia/Model/Map/ModuleTableMap.php install/thelia.sql local/config/schema.xml
This commit is contained in:
@@ -15,6 +15,8 @@ class Category extends BaseCategory
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
use \Thelia\Model\Tools\UrlRewritingTrait;
|
||||
|
||||
/**
|
||||
* @return int number of child for the current category
|
||||
*/
|
||||
@@ -23,30 +25,12 @@ class Category extends BaseCategory
|
||||
return CategoryQuery::countChild($this->getId());
|
||||
}
|
||||
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::getInstance()->retrieve('category', $this->getId(), $locale)->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new category.
|
||||
*
|
||||
* @param string $title the category title
|
||||
* @param int $parent the ID of the parent category
|
||||
* @param string $locale the locale of the title
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function create($title, $parent, $locale)
|
||||
{
|
||||
$this
|
||||
->setLocale($locale)
|
||||
->setTitle($title)
|
||||
->setParent($parent)
|
||||
->setVisible(1)
|
||||
->setPosition($this->getNextPosition($parent))
|
||||
;
|
||||
|
||||
$this->save();
|
||||
}
|
||||
protected function getRewritenUrlViewName() {
|
||||
return 'category';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -71,18 +55,38 @@ class Category extends BaseCategory
|
||||
return $countProduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByParent($this->getParent());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
$this->generateRewritenUrl($this->getLocale());
|
||||
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATECATEGORY, new CategoryEvent($this));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function postInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_CREATECATEGORY, new CategoryEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATECATEGORY, new CategoryEvent($this));
|
||||
@@ -90,16 +94,27 @@ class Category extends BaseCategory
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function postUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_UPDATECATEGORY, new CategoryEvent($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_DELETECATEGORY, new CategoryEvent($this));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function postDelete(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_DELETECATEGORY, new CategoryEvent($this));
|
||||
|
||||
@@ -3,8 +3,26 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\CategoryDocument as BaseCategoryDocument;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class CategoryDocument extends BaseCategoryDocument
|
||||
class CategoryDocument extends BaseCategoryDocument
|
||||
{
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByCategory($this->getCategory());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,26 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\CategoryImage as BaseCategoryImage;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class CategoryImage extends BaseCategoryImage
|
||||
class CategoryImage extends BaseCategoryImage
|
||||
{
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByCategory($this->getCategory());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,41 @@ namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\Content as BaseContent;
|
||||
use Thelia\Tools\URL;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class Content extends BaseContent
|
||||
{
|
||||
public function getUrl($locale)
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
use \Thelia\Model\Tools\UrlRewritingTrait;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getRewritenUrlViewName() {
|
||||
return 'content';
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
|
||||
// TODO: Find the default folder for this content,
|
||||
// and generate the position relative to this folder
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
return URL::getInstance()->retrieve('content', $this->getId(), $locale)->toString();
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
$this->generateRewritenUrl($this->getLocale());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,26 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\ContentDocument as BaseContentDocument;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class ContentDocument extends BaseContentDocument
|
||||
class ContentDocument extends BaseContentDocument
|
||||
{
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByContent($this->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,26 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\ContentImage as BaseContentImage;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class ContentImage extends BaseContentImage
|
||||
class ContentImage extends BaseContentImage
|
||||
{
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
}
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByContent($this->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,23 @@ namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\Folder as BaseFolder;
|
||||
use Thelia\Tools\URL;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class Folder extends BaseFolder
|
||||
{
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
use \Thelia\Model\Tools\UrlRewritingTrait;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getRewritenUrlViewName() {
|
||||
return 'folder';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int number of contents for the folder
|
||||
*/
|
||||
@@ -15,11 +29,6 @@ class Folder extends BaseFolder
|
||||
return FolderQuery::countChild($this->getId());
|
||||
}
|
||||
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::getInstance()->retrieve('folder', $this->getId(), $locale)->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* count all products for current category and sub categories
|
||||
@@ -43,4 +52,23 @@ class Folder extends BaseFolder
|
||||
return $contentsCount;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByParent($this->getParent());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
$this->generateRewritenUrl($this->getLocale());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,26 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\FolderDocument as BaseFolderDocument;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class FolderDocument extends BaseFolderDocument
|
||||
class FolderDocument extends BaseFolderDocument
|
||||
{
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByFolder($this->getFolder());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,26 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\FolderImage as BaseFolderImage;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class FolderImage extends BaseFolderImage
|
||||
class FolderImage extends BaseFolderImage
|
||||
{
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByFolder($this->getFolder());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,19 +6,29 @@ use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Model\Base\Product as BaseProduct;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\TaxEngine\Calculator;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class Product extends BaseProduct
|
||||
{
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::getInstance()->retrieve('product', $this->getId(), $locale)->toString();
|
||||
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
|
||||
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
use \Thelia\Model\Tools\UrlRewritingTrait;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getRewritenUrlViewName() {
|
||||
return 'product';
|
||||
}
|
||||
|
||||
public function getRealLowestPrice($virtualColumnName = 'real_lowest_price')
|
||||
{
|
||||
try {
|
||||
$amount = $this->getVirtualColumn($virtualColumnName);
|
||||
} catch(PropelException $e) {
|
||||
}
|
||||
catch(PropelException $e) {
|
||||
throw new PropelException("Virtual column `$virtualColumnName` does not exist in Product::getRealLowestPrice");
|
||||
}
|
||||
|
||||
@@ -30,4 +40,26 @@ class Product extends BaseProduct
|
||||
$taxCalculator = new Calculator();
|
||||
return round($taxCalculator->load($this, $country)->getTaxedPrice($this->getRealLowestPrice()), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our default category
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
|
||||
// TODO: Find the default category for this product,
|
||||
// and generate the position relative to this category
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
$this->generateRewritenUrl($this->getLocale());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,27 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\ProductDocument as BaseProductDocument;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class ProductDocument extends BaseProductDocument
|
||||
class ProductDocument extends BaseProductDocument
|
||||
{
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByProduct($this->getProduct());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,26 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\Base\ProductImage as BaseProductImage;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
|
||||
class ProductImage extends BaseProductImage
|
||||
class ProductImage extends BaseProductImage
|
||||
{
|
||||
use \Thelia\Model\Tools\PositionManagementTrait;
|
||||
|
||||
/**
|
||||
* Calculate next position relative to our parent
|
||||
*/
|
||||
protected function addCriteriaToPositionQuery($query) {
|
||||
$query->filterByProduct($this->getProduct());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$this->setPosition($this->getNextPosition());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
78
core/lib/Thelia/Model/Tools/UrlRewritingTrait.php
Normal file
78
core/lib/Thelia/Model/Tools/UrlRewritingTrait.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Model\Tools;
|
||||
|
||||
use Thelia\Tools\URL;
|
||||
/**
|
||||
* A trait for managing Rewriten URLs from model classes
|
||||
*/
|
||||
trait UrlRewritingTrait {
|
||||
|
||||
/**
|
||||
* @returns string the view name of the rewriten object (e.g., 'category', 'product')
|
||||
*/
|
||||
protected abstract function getRewritenUrlViewName();
|
||||
|
||||
/**
|
||||
* Get the object URL for the given locale, rewriten if rewriting is enabled.
|
||||
*
|
||||
* @param string $locale a valid locale (e.g. en_US)
|
||||
*/
|
||||
public function getUrl($locale)
|
||||
{
|
||||
return URL::getInstance()->retrieve($this->getRewritenUrlViewName(), $this->getId(), $locale)->toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a rewriten URL from the object title, and store it in the rewriting table
|
||||
*
|
||||
* @param string $locale a valid locale (e.g. en_US)
|
||||
*/
|
||||
public function generateRewritenUrl($locale)
|
||||
{
|
||||
URL::getInstance()->generateRewritenUrl($this->getRewritenUrlViewName(), $this->getId(), $locale, $this->getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* return the rewriten URL for the given locale
|
||||
*
|
||||
* @param string $locale a valid locale (e.g. en_US)
|
||||
*/
|
||||
public function getRewritenUrl($locale)
|
||||
{
|
||||
return "fake url - TODO";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rewriten URL for the given locale
|
||||
*
|
||||
* @param string $locale a valid locale (e.g. en_US)
|
||||
*/
|
||||
public function setRewritenUrl($locale, $url)
|
||||
{
|
||||
// TODO - code me !
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user