Merge branch 'master' into frontend
Conflicts: templates/default/I18n/fr_FR.php
This commit is contained in:
@@ -16,10 +16,12 @@ define('DS' , DIRECTORY_SEPARATOR);
|
||||
$loader = require __DIR__ . "/vendor/autoload.php";
|
||||
|
||||
if (!file_exists(THELIA_ROOT . '/local/config/database.yml') && !defined('THELIA_INSTALL_MODE')) {
|
||||
$request = \Thelia\Core\HttpFoundation\Request::createFromGlobals();
|
||||
header('location: '.$request->getSchemeAndHttpHost() . '/install');
|
||||
exit;
|
||||
$sapi = php_sapi_name();
|
||||
if (substr($sapi, 0, 3) == 'cli') {
|
||||
define('THELIA_INSTALL_MODE', true);
|
||||
} else {
|
||||
$request = \Thelia\Core\HttpFoundation\Request::createFromGlobals();
|
||||
header('location: '.$request->getSchemeAndHttpHost() . '/install');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
/*else {
|
||||
define('THELIA_INSTALL_MODE',true);
|
||||
}*/
|
||||
|
||||
@@ -257,7 +257,7 @@ class Install extends ContainerAwareCommand
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
if (is_null($answer)) {
|
||||
throw new \RuntimeException("You must specify database host");
|
||||
throw new \RuntimeException("You must specify a database host");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
@@ -266,12 +266,12 @@ class Install extends ContainerAwareCommand
|
||||
|
||||
$connectionInfo["dbName"] = $dialog->askAndValidate(
|
||||
$output,
|
||||
$this->decorateInfo("Database Name (if database does not exists, Thelia will try to create it) : "),
|
||||
$this->decorateInfo("Database name (if database does not exist, Thelia will try to create it) : "),
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
|
||||
if (is_null($answer)) {
|
||||
throw new \RuntimeException("You must specify database name");
|
||||
throw new \RuntimeException("You must specify a database name");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
@@ -280,12 +280,12 @@ class Install extends ContainerAwareCommand
|
||||
|
||||
$connectionInfo["username"] = $dialog->askAndValidate(
|
||||
$output,
|
||||
$this->decorateInfo("Databse username : "),
|
||||
$this->decorateInfo("Database username : "),
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
|
||||
if (is_null($answer)) {
|
||||
throw new \RuntimeException("You must sprcify database username");
|
||||
throw new \RuntimeException("You must specify a database username");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
|
||||
@@ -48,7 +48,7 @@ class HomeController extends BaseAdminController
|
||||
/* sales */
|
||||
$saleSeries = new \stdClass();
|
||||
$saleSeries->color = $this->getRequest()->query->get('sales_color', '#adadad');
|
||||
$saleSeries->data = OrderQuery::getSaleStats(
|
||||
$saleSeries->data = OrderQuery::getMonthlySaleStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y'))
|
||||
);
|
||||
@@ -56,7 +56,7 @@ class HomeController extends BaseAdminController
|
||||
/* new customers */
|
||||
$newCustomerSeries = new \stdClass();
|
||||
$newCustomerSeries->color = $this->getRequest()->query->get('customers_color', '#f39922');
|
||||
$newCustomerSeries->data = CustomerQuery::getNewCustomersStats(
|
||||
$newCustomerSeries->data = CustomerQuery::getMonthlyNewCustomersStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y'))
|
||||
);
|
||||
@@ -64,7 +64,7 @@ class HomeController extends BaseAdminController
|
||||
/* orders */
|
||||
$orderSeries = new \stdClass();
|
||||
$orderSeries->color = $this->getRequest()->query->get('orders_color', '#5cb85c');
|
||||
$orderSeries->data = OrderQuery::getOrdersStats(
|
||||
$orderSeries->data = OrderQuery::getMonthlyOrdersStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y'))
|
||||
);
|
||||
@@ -80,7 +80,7 @@ class HomeController extends BaseAdminController
|
||||
/* cancelled orders */
|
||||
$cancelledOrderSeries = new \stdClass();
|
||||
$cancelledOrderSeries->color = $this->getRequest()->query->get('cancelled_orders_color', '#d9534f');
|
||||
$cancelledOrderSeries->data = OrderQuery::getOrdersStats(
|
||||
$cancelledOrderSeries->data = OrderQuery::getMonthlyOrdersStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y')),
|
||||
array(5)
|
||||
|
||||
@@ -36,6 +36,7 @@ use Thelia\Model\ContentQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\Tools\ModelCriteriaTools;
|
||||
@@ -247,6 +248,97 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
return ConfigQuery::read($key, $default);
|
||||
}
|
||||
|
||||
public function StatsAccess($params, $smarty)
|
||||
{
|
||||
if (false === array_key_exists("key", $params)) {
|
||||
throw new \InvalidArgumentException(sprintf("missing key attribute in stats access function"));
|
||||
}
|
||||
if (false === array_key_exists("startDate", $params) || $params['startDate'] === '') {
|
||||
throw new \InvalidArgumentException(sprintf("missing startDate attribute in stats access function"));
|
||||
}
|
||||
if (false === array_key_exists("endDate", $params) || $params['endDate'] === '') {
|
||||
throw new \InvalidArgumentException(sprintf("missing endDate attribute in stats access function"));
|
||||
}
|
||||
|
||||
if (false !== array_key_exists("includeShipping", $params) && $params['includeShipping'] == 'false') {
|
||||
$includeShipping = false;
|
||||
} else {
|
||||
$includeShipping = true;
|
||||
}
|
||||
|
||||
if($params['startDate'] == 'today') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->setTime(0, 0, 0);
|
||||
} elseif($params['startDate'] == 'yesterday') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->setTime(0, 0, 0);
|
||||
$startDate->modify('-1 day');
|
||||
} elseif($params['startDate'] == 'this_month') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->modify('first day of this month');
|
||||
$startDate->setTime(0, 0, 0);
|
||||
} elseif($params['startDate'] == 'last_month') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->modify('first day of last month');
|
||||
$startDate->setTime(0, 0, 0);
|
||||
} elseif($params['startDate'] == 'this_year') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->modify('first day of January this year');
|
||||
$startDate->setTime(0, 0, 0);
|
||||
} elseif($params['startDate'] == 'last_year') {
|
||||
$startDate = new \DateTime();
|
||||
$startDate->modify('first day of December last year');
|
||||
$startDate->setTime(0, 0, 0);
|
||||
} else {
|
||||
try {
|
||||
$startDate = new \DateTime($params['startDate']);
|
||||
} catch(\Exception $e) {
|
||||
throw new \InvalidArgumentException(sprintf("invalid startDate attribute '%s' in stats access function", $params['startDate']));
|
||||
}
|
||||
}
|
||||
|
||||
if($params['endDate'] == 'today') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->setTime(0, 0, 0);
|
||||
} elseif($params['endDate'] == 'yesterday') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->setTime(0, 0, 0);
|
||||
$endDate->modify('-1 day');
|
||||
} elseif($params['endDate'] == 'this_month') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->modify('last day of this month');
|
||||
$endDate->setTime(0, 0, 0);
|
||||
} elseif($params['endDate'] == 'last_month') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->modify('last day of last month');
|
||||
$endDate->setTime(0, 0, 0);
|
||||
} elseif($params['endDate'] == 'this_year') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->modify('last day of December this year');
|
||||
$endDate->setTime(0, 0, 0);
|
||||
} elseif($params['endDate'] == 'last_year') {
|
||||
$endDate = new \DateTime();
|
||||
$endDate->modify('last day of January last year');
|
||||
$endDate->setTime(0, 0, 0);
|
||||
} else {
|
||||
try {
|
||||
$endDate = new \DateTime($params['endDate']);
|
||||
} catch(\Exception $e) {
|
||||
throw new \InvalidArgumentException(sprintf("invalid endDate attribute '%s' in stats access function", $params['endDate']));
|
||||
}
|
||||
}
|
||||
|
||||
switch( $params['key'] ) {
|
||||
case 'sales' :
|
||||
return OrderQuery::getSaleStats($startDate, $endDate, $includeShipping);
|
||||
case 'orders' :
|
||||
return OrderQuery::getOrderStats($startDate, $endDate, array(1,2,3,4));
|
||||
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf("invalid key attribute '%s' in stats access function", $params['key']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $objectLabel
|
||||
* @param $params
|
||||
@@ -358,6 +450,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
new SmartyPluginDescriptor('function', 'cart', $this, 'cartDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'order', $this, 'orderDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'config', $this, 'ConfigDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'stats', $this, 'StatsAccess'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,11 @@ class Translator extends BaseTranslator
|
||||
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->container->get('request')->getSession()->getLang()->getLocale();
|
||||
if($this->container->isScopeActive('request') && $this->container->has('request')) {
|
||||
return $this->container->get('request')->getSession()->getLang()->getLocale();
|
||||
}
|
||||
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ class CustomerQuery extends BaseCustomerQuery {
|
||||
return self::create()->findOneByEmail($email);
|
||||
}
|
||||
|
||||
public static function getNewCustomersStats($month, $year)
|
||||
public static function getMonthlyNewCustomersStats($month, $year)
|
||||
{
|
||||
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
||||
|
||||
|
||||
@@ -50,11 +50,12 @@ class Order extends BaseOrder
|
||||
/**
|
||||
* calculate the total amount
|
||||
*
|
||||
* @param int $tax
|
||||
* @param int $tax
|
||||
* @param bool $includePostage
|
||||
*
|
||||
* @return int|string|Base\double
|
||||
* @return float|int|string
|
||||
*/
|
||||
public function getTotalAmount(&$tax = 0)
|
||||
public function getTotalAmount(&$tax = 0, $includePostage = true)
|
||||
{
|
||||
$amount = 0;
|
||||
$tax = 0;
|
||||
@@ -76,7 +77,13 @@ class Order extends BaseOrder
|
||||
$tax += round($taxAmount->getVirtualColumn('total_tax'), 2) * $orderProduct->getQuantity();
|
||||
}
|
||||
|
||||
return $amount + $tax + $this->getPostage(); // @todo : manage discount
|
||||
$total = $amount + $tax;
|
||||
|
||||
if(false !== $includePostage) {
|
||||
$total += $this->getPostage();
|
||||
}
|
||||
|
||||
return $total; // @todo : manage discount
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,7 +55,7 @@ class OrderQuery extends BaseOrderQuery
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public static function getSaleStats($month, $year)
|
||||
public static function getMonthlySaleStats($month, $year)
|
||||
{
|
||||
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
||||
|
||||
@@ -75,7 +75,7 @@ class OrderQuery extends BaseOrderQuery
|
||||
return $stats;
|
||||
}
|
||||
|
||||
public static function getOrdersStats($month, $year, $status = null)
|
||||
public static function getMonthlyOrdersStats($month, $year, $status = null)
|
||||
{
|
||||
$numberOfDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);
|
||||
|
||||
@@ -121,5 +121,42 @@ class OrderQuery extends BaseOrderQuery
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $startDate
|
||||
* @param \DateTime $endDate
|
||||
* @param $includeShipping
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getSaleStats(\DateTime $startDate, \DateTime $endDate, $includeShipping)
|
||||
{
|
||||
$amount = 0;
|
||||
foreach(self::create()
|
||||
->filterByStatusId(array(2,3,4), Criteria::IN)
|
||||
->filterByCreatedAt(sprintf("%s 00:00:00", $startDate->format('Y-m-d')), Criteria::GREATER_EQUAL)
|
||||
->filterByCreatedAt(sprintf("%s 23:59:59", $endDate->format('Y-m-d')), Criteria::LESS_EQUAL)
|
||||
->find() as $order) {
|
||||
$tax = 0;
|
||||
$amount += $order->getTotalAmount($tax, $includeShipping);
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $startDate
|
||||
* @param \DateTime $endDate
|
||||
* @param $status
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getOrderStats(\DateTime $startDate, \DateTime $endDate, $status = array(1,2,3,4))
|
||||
{
|
||||
return self::create()
|
||||
->filterByStatusId($status, Criteria::IN)
|
||||
->filterByCreatedAt(sprintf("%s 00:00:00", $startDate->format('Y-m-d')), Criteria::GREATER_EQUAL)
|
||||
->filterByCreatedAt(sprintf("%s 23:59:59", $endDate->format('Y-m-d')), Criteria::LESS_EQUAL)
|
||||
->count();
|
||||
}
|
||||
|
||||
} // OrderQuery
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element type="xs:string" name="name"/>
|
||||
<xs:element type="xs:string" name="name" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element type="xs:string" name="company" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element type="xs:string" name="email"/>
|
||||
<xs:element type="xs:string" name="email" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element type="xs:anyURI" name="website" minOccurs="0" maxOccurs="1"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
@@ -52,13 +52,13 @@
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:element>
|
||||
<xs:element name="prerequis" minOccurs="0" maxOccurs="1">
|
||||
<xs:element name="required" minOccurs="0" maxOccurs="1">
|
||||
<xs:annotation>
|
||||
<xs:documentation>Les plugins qui doivent déjà être présents</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="plugin" maxOccurs="unbounded" minOccurs="0">
|
||||
<xs:element name="module" maxOccurs="unbounded" minOccurs="0">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
|
||||
Reference in New Issue
Block a user