// Refactoring of shop class with new context
This commit is contained in:
+5
-11
@@ -78,18 +78,12 @@ if (empty($tab) and !sizeof($_POST))
|
||||
{
|
||||
echo '
|
||||
<span style="float:right">'.translate('You are currently view/configure your store for').' <b>';
|
||||
if (Shop::getContextType() == Shop::CONTEXT_ALL)
|
||||
if (Context::getContext()->shop->getContextType() == Shop::CONTEXT_ALL)
|
||||
echo 'all shops';
|
||||
elseif (Shop::getContextType() == Shop::CONTEXT_GROUP)
|
||||
{
|
||||
$group_shop = new GroupShop((int)Shop::getCurrentGroupShop());
|
||||
echo 'all shops of group shop <b>'.$group_shop->name.'</b>';
|
||||
}
|
||||
elseif (Shop::getContextType() == Shop::CONTEXT_SHOP)
|
||||
{
|
||||
$shop = new Shop((int)Shop::getCurrentShop());
|
||||
echo 'shop <b>'.$shop->name.'</b>';
|
||||
}
|
||||
elseif (Context::getContext()->shop->getContextType() == Shop::CONTEXT_GROUP)
|
||||
echo 'all shops of group shop <b>'.Context::getContext()->shop->getGroup()->name.'</b>';
|
||||
elseif (Context::getContext()->shop->getContextType() == Shop::CONTEXT_SHOP)
|
||||
echo 'shop <b>'.Context::getContext()->shop->name.'</b>';
|
||||
echo '</b>
|
||||
</span> ';
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ class AdminCatalog extends AdminTab
|
||||
if (!$id_category)
|
||||
{
|
||||
$home = true;
|
||||
$id_category = Context::getContext()->shop->id_category1;
|
||||
$id_category = Context::getContext()->shop->id_category;
|
||||
}
|
||||
$catalog_tabs = array('category', 'product');
|
||||
// Cleaning links
|
||||
|
||||
@@ -220,11 +220,8 @@ class AdminCategories extends AdminTab
|
||||
return;
|
||||
$active = $this->getFieldValue($obj, 'active');
|
||||
$customer_groups = $obj->getGroups();
|
||||
if (Shop::getContextType() == Shop::CONTEXT_SHOP)
|
||||
{
|
||||
$shop = new Shop(Shop::getCurrentShop());
|
||||
$id_category = $shop->id_category;
|
||||
}
|
||||
if ($context->shop->getContextType() == Shop::CONTEXT_SHOP)
|
||||
$id_category = $context->shop->id_category;
|
||||
else
|
||||
$id_category = (int)Tools::getValue('id_parent');
|
||||
|
||||
|
||||
@@ -589,7 +589,6 @@ class AdminImport extends AdminTab
|
||||
|
||||
public function productImport()
|
||||
{
|
||||
global $cookie;
|
||||
$this->receiveTab();
|
||||
$handle = $this->openCsvFile();
|
||||
$defaultLanguageId = (int)(Configuration::get('PS_LANG_DEFAULT'));
|
||||
@@ -788,7 +787,8 @@ class AdminImport extends AdminTab
|
||||
{
|
||||
$specificPrice = new SpecificPrice();
|
||||
$specificPrice->id_product = (int)($product->id);
|
||||
$specificPrice->id_shop = (int)(Shop::getCurrentShop());
|
||||
// @todo multishop specific price import
|
||||
$specificPrice->id_shop = $context->shop->getID();
|
||||
$specificPrice->id_currency = 0;
|
||||
$specificPrice->id_country = 0;
|
||||
$specificPrice->id_group = 0;
|
||||
@@ -849,7 +849,7 @@ class AdminImport extends AdminTab
|
||||
|
||||
if (isset($product->image) AND is_array($product->image) and sizeof($product->image))
|
||||
{
|
||||
$productHasImages = (bool)Image::getImages((int)($cookie->id_lang), (int)($product->id));
|
||||
$productHasImages = (bool)Image::getImages($context->language->id, (int)($product->id));
|
||||
foreach ($product->image AS $key => $url)
|
||||
if (!empty($url))
|
||||
{
|
||||
@@ -1239,9 +1239,9 @@ class AdminImport extends AdminTab
|
||||
|
||||
public function displayForm($isMainTab = true)
|
||||
{
|
||||
global $currentIndex, $cookie;
|
||||
parent::displayForm();
|
||||
|
||||
$context = Context::getContext();
|
||||
if ((Tools::getValue('import')) AND (isset($this->_warnings) AND !sizeof($this->_warnings)))
|
||||
echo '<div class="module_confirmation conf confirm"><img src="../img/admin/ok.gif" alt="" title="" style="margin-right:5px; float:left;" />'.$this->l('The .CSV file has been imported into your shop.').'</div>';
|
||||
|
||||
@@ -1270,7 +1270,7 @@ class AdminImport extends AdminTab
|
||||
echo '
|
||||
<fieldset class="width3">
|
||||
<legend><img src="../img/admin/import.gif" />'.$this->l('Upload').'</legend>
|
||||
<form action="'.$currentIndex.'&token='.$this->token.'" method="POST" enctype="multipart/form-data">
|
||||
<form action="'.$this->currentIndex.'&token='.$this->token.'" method="POST" enctype="multipart/form-data">
|
||||
<label class="clear">'.$this->l('Select a file').' </label>
|
||||
<div class="margin-form">
|
||||
<input name="file" type="file" /><br />'.$this->l('You can also upload your file by FTP and put it in').' '.realpath(dirname(__FILE__).'/../import/').'.
|
||||
@@ -1295,7 +1295,7 @@ class AdminImport extends AdminTab
|
||||
{
|
||||
echo '
|
||||
<div class="space">
|
||||
<form id="preview_import" action="'.$currentIndex.'&token='.$this->token.'" method="post" style="display:inline" enctype="multipart/form-data" class="clear" onsubmit="if ($(\'#truncate\').get(0).checked) {if (confirm(\''.$this->l('Are you sure you want to delete', __CLASS__, true, false).'\' + \' \' + $(\'#entity > option:selected\').text().toLowerCase() + \''.$this->l('?', __CLASS__, true, false).'\')){this.submit();} else {return false;}}">
|
||||
<form id="preview_import" action="'.$this->currentIndex.'&token='.$this->token.'" method="post" style="display:inline" enctype="multipart/form-data" class="clear" onsubmit="if ($(\'#truncate\').get(0).checked) {if (confirm(\''.$this->l('Are you sure you want to delete', __CLASS__, true, false).'\' + \' \' + $(\'#entity > option:selected\').text().toLowerCase() + \''.$this->l('?', __CLASS__, true, false).'\')){this.submit();} else {return false;}}">
|
||||
<fieldset style="float: left; width: 550px">
|
||||
<legend><img src="../img/admin/import.gif" />'.$this->l('Import').'</legend>
|
||||
<label class="clear">'.$this->l('Select which entity to import:').' </label>
|
||||
@@ -1321,7 +1321,7 @@ class AdminImport extends AdminTab
|
||||
<div class="margin-form">
|
||||
<select name="iso_lang">';
|
||||
foreach ($this->_languages AS $lang)
|
||||
echo '<option value="'.$lang['iso_code'].'" '.($lang['id_lang'] == $cookie->id_lang ? 'selected="selected"' : '').'>'.$lang['name'].'</option>';
|
||||
echo '<option value="'.$lang['iso_code'].'" '.($lang['id_lang'] == $context->language->id ? 'selected="selected"' : '').'>'.$lang['name'].'</option>';
|
||||
echo '</select></div><label for="convert" class="clear">'.$this->l('iso-8859-1 encoded file').' </label>
|
||||
<div class="margin-form">
|
||||
<input name="convert" id="convert" type="checkbox" style="margin-top: 6px;"/>
|
||||
@@ -1360,7 +1360,7 @@ class AdminImport extends AdminTab
|
||||
<script type="text/javascript">
|
||||
$("select#entity").change( function() {
|
||||
$("#entitie").html($("#entity > option:selected").text().toLowerCase());
|
||||
$.getJSON("'.dirname($currentIndex).'/ajax.php",
|
||||
$.getJSON("'.dirname($this->currentIndex).'/ajax.php",
|
||||
{
|
||||
getAvailableFields:1,
|
||||
entity: $("#entity").val()},
|
||||
@@ -1473,7 +1473,6 @@ class AdminImport extends AdminTab
|
||||
|
||||
public function displayCSV()
|
||||
{
|
||||
global $currentIndex;
|
||||
$importMatchs = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'import_match');
|
||||
|
||||
echo '
|
||||
@@ -1512,7 +1511,7 @@ class AdminImport extends AdminTab
|
||||
$res[] = '\''.$elem.'\'';
|
||||
|
||||
echo '
|
||||
<form action="'.$currentIndex.'&token='.$this->token.'" method="post" id="import_form" name="import_form">
|
||||
<form action="'.$this->currentIndex.'&token='.$this->token.'" method="post" id="import_form" name="import_form">
|
||||
'.$this->l('Skip').' <input type="text" size="2" name="skip" value="0" /> '.$this->l('lines').'.
|
||||
<input type="hidden" name="csv" value="'.Tools::getValue('csv').'" />
|
||||
<input type="hidden" name="convert" value="'.Tools::getValue('convert').'" />
|
||||
@@ -1626,8 +1625,6 @@ class AdminImport extends AdminTab
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
global $currentIndex;
|
||||
|
||||
if (Tools::isSubmit('submitFileUpload'))
|
||||
{
|
||||
if (isset($_FILES['file']) AND !empty($_FILES['file']['error']))
|
||||
@@ -1662,7 +1659,7 @@ class AdminImport extends AdminTab
|
||||
elseif (!file_exists($_FILES['file']['tmp_name']) OR !@move_uploaded_file($_FILES['file']['tmp_name'], dirname(__FILE__).'/../import/'.$_FILES['file']['name'].'.'.date('Ymdhis')))
|
||||
$this->_errors[] = $this->l('an error occurred while uploading and copying file');
|
||||
else
|
||||
Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=18');
|
||||
Tools::redirectAdmin($this->currentIndex.'&token='.Tools::getValue('token').'&conf=18');
|
||||
}
|
||||
elseif (Tools::isSubmit('submitImportFile'))
|
||||
$this->displayCSV();
|
||||
|
||||
@@ -286,17 +286,12 @@ class AdminModules extends AdminTab
|
||||
$toolbar .= '<tr>
|
||||
<th colspan="4">
|
||||
<input type="checkbox" name="activateModule" value="1" '.(($module->active) ? 'checked="checked"' : '').' '.$activateOnclick.' /> '.$this->l('Activate module for').' ';
|
||||
if (Shop::getContextType() == Shop::CONTEXT_SHOP)
|
||||
{
|
||||
$shop = new Shop((int)Shop::getCurrentShop());
|
||||
$toolbar .= 'shop <b>'.$shop->name.'</b>';
|
||||
}
|
||||
elseif (Shop::getContextType() == Shop::CONTEXT_GROUP)
|
||||
{
|
||||
$group_shop = new GroupShop((int)Shop::getCurrentGroupShop());
|
||||
$toolbar .= 'all shops of group shop <b>'.$group_shop->name.'</b>';
|
||||
}
|
||||
elseif (Shop::getContextType() == Shop::CONTEXT_ALL)
|
||||
$context = Context::getContext();
|
||||
if ($context->shop->getContextType() == Shop::CONTEXT_SHOP)
|
||||
$toolbar .= 'shop <b>'.$context->shop->name.'</b>';
|
||||
elseif ($context->shop->getContextType() == Shop::CONTEXT_GROUP)
|
||||
$toolbar .= 'all shops of group shop <b>'.$context->shop->getGroup()->name.'</b>';
|
||||
else
|
||||
$toolbar .= 'all shops';
|
||||
$toolbar .= '</th>
|
||||
</tr>';
|
||||
|
||||
@@ -1169,7 +1169,7 @@ class AdminProducts extends AdminTab
|
||||
/* Update an existing product */
|
||||
if (isset($id) AND !empty($id))
|
||||
{
|
||||
$object = new $this->className($id, false, NULL, Shop::getCurrentShop(true));
|
||||
$object = new $this->className($id);
|
||||
if (Validate::isLoadedObject($object))
|
||||
{
|
||||
$this->_removeTaxFromEcotax();
|
||||
@@ -1402,7 +1402,7 @@ class AdminProducts extends AdminTab
|
||||
{
|
||||
global $currentIndex, $cookie;
|
||||
|
||||
$id_shop = Shop::getCurrentShop(true);
|
||||
$id_shop = Context::getContext()->shop->getID();
|
||||
|
||||
if (($id_category = (int)Tools::getValue('id_category')))
|
||||
$currentIndex .= '&id_category='.$id_category;
|
||||
@@ -3816,7 +3816,7 @@ class AdminProducts extends AdminTab
|
||||
if ($id = (int)(Tools::getValue($this->identifier)) AND Validate::isUnsignedId($id))
|
||||
{
|
||||
if (!$this->_object)
|
||||
$this->_object = new $this->className($id, false, NULL, (int)Shop::getCurrentShop(true));
|
||||
$this->_object = new $this->className($id);
|
||||
if (Validate::isLoadedObject($this->_object))
|
||||
return $this->_object;
|
||||
$this->_errors[] = Tools::displayError('Object cannot be loaded (not found)');
|
||||
|
||||
@@ -44,36 +44,34 @@ class AdminStockMvt extends AdminTab
|
||||
'employee' => array('title' => $this->l('Employee'), 'width' => 100, 'havingFilter' => true),
|
||||
);
|
||||
|
||||
global $cookie;
|
||||
$context = Context::getContext();
|
||||
|
||||
$this->_select = 'CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, CONCAT(e.lastname, \' \', e.firstname) employee, mrl.name reason';
|
||||
$this->_join = 'INNER JOIN '._DB_PREFIX_.'stock stock ON a.id_stock = stock.id_stock '.Shop::sqlSharedStock('stock', Shop::getCurrentShop(), Shop::getCurrentGroupShop()).'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (stock.id_product = pl.id_product AND pl.id_lang = '.(int)$cookie->id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (a.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$cookie->id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (stock.id_product = pl.id_product AND pl.id_lang = '.(int)$context->language->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (a.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$context->language->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = stock.id_product_attribute)
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$cookie->id_lang.')';
|
||||
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$context->language->id.')';
|
||||
$this->_group = 'GROUP BY a.id_stock_mvt';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
global $cookie;
|
||||
if (Tools::isSubmit('rebuildStock'))
|
||||
StockMvt::addMissingMvt((int)$cookie->id_employee, false);
|
||||
StockMvt::addMissingMvt($context->employee->id, false);
|
||||
return parent::postProcess();
|
||||
}
|
||||
|
||||
public function displayForm($isMainTab = true)
|
||||
{
|
||||
global $currentIndex, $cookie;
|
||||
parent::displayForm();
|
||||
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
$dl = 'name';
|
||||
echo '<form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'&addstock_mvt_reason" method="post">
|
||||
echo '<form action="'.$this->currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'&addstock_mvt_reason" method="post">
|
||||
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
|
||||
<fieldset><legend><img src="../img/admin/search.gif" />'.$this->l('Stock Movement').'</legend>
|
||||
<label>'.$this->l('Name:').'</label>
|
||||
@@ -102,11 +100,10 @@ class AdminStockMvt extends AdminTab
|
||||
|
||||
public function viewstock_mvt()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$context = Context::getContext();
|
||||
$stockMvt = new StockMvt((int)Tools::getValue('id_stock_mvt'));
|
||||
$product = new Product((int)$stockMvt->id_product, true, (int)$cookie->id_lang);
|
||||
$movements = $product->getStockMvts((int)$cookie->id_lang);
|
||||
$product = new Product((int)$stockMvt->id_product, true, $context->language->id);
|
||||
$movements = $product->getStockMvts($context->language->id);
|
||||
|
||||
echo '<h2>'.$this->l('Stock Movements for').' '.$product->name.'</h2>
|
||||
<table cellspacing="0" cellpadding="0" class="table widthfull">
|
||||
@@ -130,7 +127,7 @@ class AdminStockMvt extends AdminTab
|
||||
<td>'.$mvt['reason'].'</td>
|
||||
<td>'.$mvt['employee'].'</td>
|
||||
<td>#'.$mvt['id_order'].'</td>
|
||||
<td>'.Tools::displayDate($mvt['date_add'], (int)($cookie->id_lang)).'</td>
|
||||
<td>'.Tools::displayDate($mvt['date_add'], $context->language->id).'</td>
|
||||
</tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
@@ -138,9 +135,8 @@ class AdminStockMvt extends AdminTab
|
||||
|
||||
public function display()
|
||||
{
|
||||
global $currentIndex, $cookie;
|
||||
|
||||
$old_post = false;
|
||||
$context = Context::getContext();
|
||||
|
||||
if (!isset($_GET['addstock_mvt_reason']) OR (Tools::isSubmit('submitAddstock_mvt_reason') AND Tools::getValue('id_stock_mvt_reason')))
|
||||
{
|
||||
@@ -153,7 +149,7 @@ class AdminStockMvt extends AdminTab
|
||||
if (!isset($_GET['view'.$this->table]))
|
||||
echo '
|
||||
<fieldset>
|
||||
<form method="post" action="'.$currentIndex.'&token='.$this->token.'&rebuildMvt=1">
|
||||
<form method="post" action="'.$this->currentIndex.'&token='.$this->token.'&rebuildMvt=1">
|
||||
<label for="stock_rebuild">'.$this->l('Calculate the movement of inventory missing').'</label>
|
||||
<div class="margin-form">
|
||||
<input class="button" type="submit" name="rebuildStock" value="'.$this->l('Submit').'" />
|
||||
@@ -182,7 +178,7 @@ class AdminStockMvt extends AdminTab
|
||||
'sign' => array('title' => $this->l('Sign'), 'width' => 15, 'align' => 'center', 'type' => 'select', 'icon' => array(-1 => 'arrow_down.png', 1 => 'arrow_up.png'), 'orderby' => false),
|
||||
'name' => array('title' => $this->l('Name'), 'width' => 500));
|
||||
|
||||
$reasons = StockMvtReason::getStockMvtReasons((int)$cookie->id_lang);
|
||||
$reasons = StockMvtReason::getStockMvtReasons($context->language->id);
|
||||
$this->_fieldsOptions = array('PS_STOCK_MVT_REASON_DEFAULT' => array('title' => $this->l('Default Stock Movement reason:'),
|
||||
'cast' => 'intval',
|
||||
'type' => 'select',
|
||||
|
||||
Reference in New Issue
Block a user