* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6684 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminSuppliers extends AdminTab { protected $maxImageSize = 200000; public function __construct() { $this->table = 'supplier'; $this->className = 'Supplier'; $this->view = true; $this->edit = true; $this->delete = true; $this->_select = 'COUNT(p.`id_product`) AS products'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product` p ON (a.`id_supplier` = p.`id_supplier`)'; $this->_group = 'GROUP BY a.`id_supplier`'; $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'su'); $this->fieldsDisplay = array( 'id_supplier' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'name' => array('title' => $this->l('Name'), 'width' => 120), 'logo' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 'su', 'orderby' => false, 'search' => false), 'products' => array('title' => $this->l('Number of products'), 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true), 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) ); parent::__construct(); } public function viewsupplier() { global $cookie; if (!($supplier = $this->loadObject())) return; echo '

'.$supplier->name.'

'; $products = $supplier->getProductsLite((int)($cookie->id_lang)); echo '

'.$this->l('Total products:').' '.sizeof($products).'

'; foreach ($products AS $product) { $product = new Product($product['id_product'], false, (int)($cookie->id_lang)); echo '
'; if (!$product->hasAttributes()) { echo ' '.(!empty($product->reference) ? '' : '').' '.(!empty($product->ean13) ? '' : '').' '.(!empty($product->upc) ? '' : '').' '.(Configuration::get('PS_STOCK_MANAGEMENT') ? '' : '').'
'.$product->name.''.$this->l('Ref:').' '.$product->reference.''.$this->l('EAN13:').' '.$product->ean13.''.$this->l('UPC:').' '.$product->upc.''.$this->l('Qty:').' '.$product->quantity.'
'; } else { echo '

'.$product->name.'

'.(Configuration::get('PS_STOCK_MANAGEMENT') ? '' : '').' '; /* Build attributes combinaisons */ $combinaisons = $product->getAttributeCombinaisons((int)($cookie->id_lang)); foreach ($combinaisons AS $k => $combinaison) { $combArray[$combinaison['id_product_attribute']]['reference'] = $combinaison['reference']; $combArray[$combinaison['id_product_attribute']]['ean13'] = $combinaison['ean13']; $combArray[$combinaison['id_product_attribute']]['upc'] = $combinaison['upc']; $combArray[$combinaison['id_product_attribute']]['quantity'] = $combinaison['quantity']; $combArray[$combinaison['id_product_attribute']]['attributes'][] = array($combinaison['group_name'], $combinaison['attribute_name'], $combinaison['id_attribute']); } $irow = 0; foreach ($combArray AS $id_product_attribute => $product_attribute) { $list = ''; foreach ($product_attribute['attributes'] AS $attribute) $list .= $attribute[0].' - '.$attribute[1].', '; $list = rtrim($list, ', '); echo ' '.(Configuration::get('PS_STOCK_MANAGEMENT') ? '' : '').' '; } unset($combArray); echo '
'.$this->l('Attribute name').' '.$this->l('Reference').' '.$this->l('EAN13').' '.$this->l('UPC').''.$this->l('Quantity').'
'.stripslashes($list).' '.$product_attribute['reference'].''.$product_attribute['ean13'].''.$product_attribute['upc'].''.$product_attribute['quantity'].'
'; echo ''; } } } public function displayForm($isMainTab = true) { global $currentIndex; parent::displayForm(); if (!($supplier = $this->loadObject(true))) return; $langtags = 'description¤smeta_title¤smeta_keywords¤smeta_description'; echo '
'.($supplier->id ? '' : '').'
'.$this->l('Suppliers').'
* '.$this->l('Invalid characters:').' <>;=#{} 
'; foreach ($this->_languages as $language) echo '
'.$this->l('Invalid characters:').' <>;=#{} 

'.$this->l('Will appear in supplier list').'

'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'description'); echo '
'; echo $this->displayImage($supplier->id, _PS_SUPP_IMG_DIR_.$supplier->id.'.jpg', 350, NULL, NULL, true); echo '

'.$this->l('Upload supplier logo from your computer').'

'; foreach ($this->_languages as $language) echo '
'.$this->l('Forbidden characters:').' <>;=#{} 
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'smeta_title'); echo '
'; foreach ($this->_languages as $language) echo '
'.$this->l('Forbidden characters:').' <>;=#{} 
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'smeta_description'); echo '
'; foreach ($this->_languages as $language) echo '
'.$this->l('Forbidden characters:').' <>;=#{} 
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'smeta_keywords'); echo '
getFieldValue($supplier, 'active') ? 'checked="checked" ' : '').'/> getFieldValue($supplier, 'active') ? 'checked="checked" ' : '').'/>
* '.$this->l('Required field').'
'; } public function afterImageUpload() { /* Generate image with differents size */ if (($id_supplier = (int)(Tools::getValue('id_supplier'))) AND isset($_FILES) AND count($_FILES) AND file_exists(_PS_SUPP_IMG_DIR_.$id_supplier.'.jpg')) { $imagesTypes = ImageType::getImagesTypes('suppliers'); foreach ($imagesTypes AS $k => $imageType) { $file = _PS_SUPP_IMG_DIR_.$id_supplier.'.jpg'; imageResize($file, _PS_SUPP_IMG_DIR_.$id_supplier.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); } } } }