// Norm and doc for Shop class

This commit is contained in:
rMalie
2012-05-30 09:50:10 +00:00
parent 50a439ba3b
commit e91ca5cc13
4 changed files with 107 additions and 46 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ class CookieCore
$this->_content = array(); $this->_content = array();
$this->_expire = isset($expire) ? (int)($expire) : (time() + 1728000); $this->_expire = isset($expire) ? (int)($expire) : (time() + 1728000);
$this->_name = md5($name); $this->_name = md5($name);
$this->_path = trim(Context::getContext()->shop->getPhysicalURI().$path, '/\\').'/'; $this->_path = trim(Context::getContext()->shop->physical_uri.$path, '/\\').'/';
if ($this->_path{0} != '/') $this->_path = '/'.$this->_path; if ($this->_path{0} != '/') $this->_path = '/'.$this->_path;
$this->_path = rawurlencode($this->_path); $this->_path = rawurlencode($this->_path);
$this->_path = str_replace('%2F', '/', $this->_path); $this->_path = str_replace('%2F', '/', $this->_path);
+21 -21
View File
@@ -72,14 +72,14 @@ class ImageManagerCore
// We need to resize */ // We need to resize */
else else
{ {
$ratioX = $x / ($y / $size); $ratio_x = $x / ($y / $size);
if ($ratioX > $max_x) if ($ratio_x > $max_x)
{ {
$ratioX = $max_x; $ratio_x = $max_x;
$size = $y / ($x / $max_x); $size = $y / ($x / $max_x);
} }
ImageManager::resize($image, _PS_TMP_IMG_DIR_.$cache_image, $ratioX, $size, $image_type); ImageManager::resize($image, _PS_TMP_IMG_DIR_.$cache_image, $ratio_x, $size, $image_type);
} }
} }
return '<img src="'._PS_TMP_IMG_.$cache_image.(!$disable_cache ? '?time='.time() : '').'" alt="" class="imgm" />'; return '<img src="'._PS_TMP_IMG_.$cache_image.(!$disable_cache ? '?time='.time() : '').'" alt="" class="imgm" />';
@@ -122,43 +122,43 @@ class ImageManagerCore
if ($width_diff > 1 && $height_diff > 1) if ($width_diff > 1 && $height_diff > 1)
{ {
$nextWidth = $src_width; $next_width = $src_width;
$nextHeight = $src_height; $next_height = $src_height;
} }
else else
{ {
if (Configuration::get('PS_IMAGE_GENERATION_METHOD') == 2 || (!Configuration::get('PS_IMAGE_GENERATION_METHOD') && $width_diff > $height_diff)) if (Configuration::get('PS_IMAGE_GENERATION_METHOD') == 2 || (!Configuration::get('PS_IMAGE_GENERATION_METHOD') && $width_diff > $height_diff))
{ {
$nextHeight = $dst_height; $next_height = $dst_height;
$nextWidth = round(($src_width * $nextHeight) / $src_height); $next_width = round(($src_width * $next_height) / $src_height);
$dst_width = (int)(!Configuration::get('PS_IMAGE_GENERATION_METHOD') ? $dst_width : $nextWidth); $dst_width = (int)(!Configuration::get('PS_IMAGE_GENERATION_METHOD') ? $dst_width : $next_width);
} }
else else
{ {
$nextWidth = $dst_width; $next_width = $dst_width;
$nextHeight = round($src_height * $dst_width / $src_width); $next_height = round($src_height * $dst_width / $src_width);
$dst_height = (int)(!Configuration::get('PS_IMAGE_GENERATION_METHOD') ? $dst_height : $nextHeight); $dst_height = (int)(!Configuration::get('PS_IMAGE_GENERATION_METHOD') ? $dst_height : $next_height);
} }
} }
$destImage = imagecreatetruecolor($dst_width, $dst_height); $dest_image = imagecreatetruecolor($dst_width, $dst_height);
// If image is a PNG and the output is PNG, fill with transparency. Else fill with white background. // If image is a PNG and the output is PNG, fill with transparency. Else fill with white background.
if ($file_type == 'png' && $type == IMAGETYPE_PNG) if ($file_type == 'png' && $type == IMAGETYPE_PNG)
{ {
imagealphablending($destImage, false); imagealphablending($dest_image, false);
imagesavealpha($destImage, true); imagesavealpha($dest_image, true);
$transparent = imagecolorallocatealpha($destImage, 255, 255, 255, 127); $transparent = imagecolorallocatealpha($dest_image, 255, 255, 255, 127);
imagefilledrectangle($destImage, 0, 0, $dst_width, $dst_height, $transparent); imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $transparent);
} }
else else
{ {
$white = imagecolorallocate($destImage, 255, 255, 255); $white = imagecolorallocate($dest_image, 255, 255, 255);
imagefilledrectangle ($destImage, 0, 0, $dst_width, $dst_height, $white); imagefilledrectangle ($dest_image, 0, 0, $dst_width, $dst_height, $white);
} }
imagecopyresampled($destImage, $src_image, (int)(($dst_width - $nextWidth) / 2), (int)(($dst_height - $nextHeight) / 2), 0, 0, $nextWidth, $nextHeight, $src_width, $src_height); imagecopyresampled($dest_image, $src_image, (int)(($dst_width - $next_width) / 2), (int)(($dst_height - $next_height) / 2), 0, 0, $next_width, $next_height, $src_width, $src_height);
return (ImageManager::write($file_type, $destImage, $dst_file)); return (ImageManager::write($file_type, $dest_image, $dst_file));
} }
/** /**
+1 -1
View File
@@ -268,7 +268,7 @@ class FrontControllerCore extends Controller
elseif (Tools::getValue('fc') == 'module' && $module_name != '' && new $module_name() instanceof PaymentModule) elseif (Tools::getValue('fc') == 'module' && $module_name != '' && new $module_name() instanceof PaymentModule)
$page_name = 'module-payment-submit'; $page_name = 'module-payment-submit';
// @retrocompatibility Are we in a module ? // @retrocompatibility Are we in a module ?
elseif (preg_match('#^'.preg_quote($this->context->shop->getPhysicalURI(), '#').'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m)) elseif (preg_match('#^'.preg_quote($this->context->shop->physical_uri, '#').'modules/([a-zA-Z0-9_-]+?)/(.*)$#', $_SERVER['REQUEST_URI'], $m))
$page_name = 'module-'.$m[1].'-'.str_replace(array('.php', '/'), array('', '-'), $m[2]); $page_name = 'module-'.$m[1].'-'.str_replace(array('.php', '/'), array('', '-'), $m[2]);
else else
{ {
+84 -23
View File
@@ -30,23 +30,40 @@
*/ */
class ShopCore extends ObjectModel class ShopCore extends ObjectModel
{ {
/** @var int ID of shop group */
public $id_shop_group; public $id_shop_group;
public $id_theme;
public $name; /** @var int ID of shop category */
public $active = true;
public $id_category; public $id_category;
/** @var int ID of shop theme */
public $id_theme;
/** @var string Shop name */
public $name;
public $active = true;
public $deleted; public $deleted;
/** @var string Shop theme name (read only) */
public $theme_name; public $theme_name;
/** @var string Shop theme directory (read only) */
public $theme_directory; public $theme_directory;
/** @var string Physical uri of main url (read only) */
public $physical_uri; public $physical_uri;
/** @var string Virtual uri of main url (read only) */
public $virtual_uri; public $virtual_uri;
/** @var string Domain of main url (read only) */
public $domain; public $domain;
/** @var string Domain SSL of main url (read only) */
public $domain_ssl; public $domain_ssl;
/** /** @var ShopGroup Shop group object */
* @var ShopGroup
*/
protected $group; protected $group;
/** /**
@@ -115,8 +132,13 @@ class ShopCore extends ObjectModel
), ),
); );
protected static $context; /** @var int Store the current context of shop (CONTEXT_ALL, CONTEXT_GROUP, CONTEXT_SHOP) */
protected static $context;
/** @var int ID shop in the current context (will be empty if context is not CONTEXT_SHOP) */
protected static $context_id_shop; protected static $context_id_shop;
/** @var int ID shop group in the current context (will be empty if context is CONTEXT_ALL) */
protected static $context_id_shop_group; protected static $context_id_shop_group;
/** /**
@@ -132,6 +154,13 @@ class ShopCore extends ObjectModel
const SHARE_CUSTOMER = 'share_customer'; const SHARE_CUSTOMER = 'share_customer';
const SHARE_ORDER = 'share_order'; const SHARE_ORDER = 'share_order';
/**
* On shop instance, get its theme and URL data too
*
* @param int $id
* @param int $id_lang
* @param int $id_shop
*/
public function __construct($id = null, $id_lang = null, $id_shop = null) public function __construct($id = null, $id_lang = null, $id_shop = null)
{ {
parent::__construct($id, $id_lang, $id_shop); parent::__construct($id, $id_lang, $id_shop);
@@ -159,6 +188,13 @@ class ShopCore extends ObjectModel
} }
} }
/**
* Add a shop, and clear the cache
*
* @param bool $autodate
* @param bool $null_values
* @return bool
*/
public function add($autodate = true, $null_values = false) public function add($autodate = true, $null_values = false)
{ {
$res = parent::add($autodate, $null_values); $res = parent::add($autodate, $null_values);
@@ -166,6 +202,11 @@ class ShopCore extends ObjectModel
return $res; return $res;
} }
/**
* Remove a shop only if it has no dependencies, and remove its associations
*
* @return bool
*/
public function delete() public function delete()
{ {
if (Shop::hasDependency($this->id) || !$res = parent::delete()) if (Shop::hasDependency($this->id) || !$res = parent::delete())
@@ -360,11 +401,6 @@ class ShopCore extends ObjectModel
return $this->physical_uri.$this->virtual_uri; return $this->physical_uri.$this->virtual_uri;
} }
public function getPhysicalURI()
{
return $this->physical_uri;
}
/** /**
* Get shop URL * Get shop URL
* *
@@ -420,7 +456,7 @@ class ShopCore extends ObjectModel
*/ */
public function isDefaultShop() public function isDefaultShop()
{ {
return ($this->id == Configuration::get('PS_SHOP_DEFAULT')); return $this->id == Configuration::get('PS_SHOP_DEFAULT');
} }
/** /**
@@ -664,9 +700,19 @@ class ShopCore extends ObjectModel
*/ */
public static function getShopById($id, $identifier, $table) public static function getShopById($id, $identifier, $table)
{ {
return Db::getInstance()->executeS('SELECT `id_shop`, `'.bqSQL($identifier).'` FROM `'._DB_PREFIX_.bqSQL($table).'_shop` WHERE `'.bqSQL($identifier).'` = '.(int)$id); return Db::getInstance()->executeS('
SELECT `id_shop`, `'.bqSQL($identifier).'`
FROM `'._DB_PREFIX_.bqSQL($table).'_shop`
WHERE `'.bqSQL($identifier).'` = '.(int)$id
);
} }
/**
* Change the current shop context
*
* @param int $type Shop::CONTEXT_ALL | Shop::CONTEXT_GROUP | Shop::CONTEXT_SHOP
* @param int $id ID shop if CONTEXT_SHOP or id shop group if CONTEXT_GROUP
*/
public static function setContext($type, $id = null) public static function setContext($type, $id = null)
{ {
// Always use global context for mono-shop mode // Always use global context for mono-shop mode
@@ -697,16 +743,31 @@ class ShopCore extends ObjectModel
self::$context = $type; self::$context = $type;
} }
/**
* Get current context of shop
*
* @return int
*/
public static function getContext() public static function getContext()
{ {
return self::$context; return self::$context;
} }
/**
* Get current ID of shop if context is CONTEXT_SHOP
*
* @return int
*/
public static function getContextShopID() public static function getContextShopID()
{ {
return self::$context_id_shop; return self::$context_id_shop;
} }
/**
* Get current ID of shop group if context is CONTEXT_SHOP or CONTEXT_GROUP
*
* @return int
*/
public static function getContextShopGroupID() public static function getContextShopGroupID()
{ {
return self::$context_id_shop_group; return self::$context_id_shop_group;
@@ -885,15 +946,6 @@ class ShopCore extends ObjectModel
), $m['id_module']); ), $m['id_module']);
} }
/**
* @deprecated 1.5.0 Use shop->id
*/
public static function getCurrentShop()
{
Tools::displayAsDeprecated();
return Context::getContext()->shop->id;
}
/** /**
* @static * @static
* @param int $id * @param int $id
@@ -924,4 +976,13 @@ class ShopCore extends ObjectModel
return $array; return $array;
} }
/**
* @deprecated 1.5.0 Use shop->id
*/
public static function getCurrentShop()
{
Tools::displayAsDeprecated();
return Context::getContext()->shop->id;
}
} }