Exemplo n.º 1
0
function upgrade_module_1_5_0($module)
{
    /* Get existing values as default */
    $default_width = (int) Configuration::get('HOMESLIDER_WIDTH');
    $default_speed = (int) Configuration::get('HOMESLIDER_SPEED');
    $default_pause = (int) Configuration::get('HOMESLIDER_PAUSE');
    $default_loop = (int) Configuration::get('HOMESLIDER_LOOP');
    $res = true;
    // Clean existing
    Configuration::deleteByName('HOMESLIDER_WIDTH');
    Configuration::deleteByName('HOMESLIDER_SPEED');
    Configuration::deleteByName('HOMESLIDER_PAUSE');
    Configuration::deleteByName('HOMESLIDER_LOOP');
    $shops = Shop::getContextListShopID();
    $shop_groups_list = array();
    /* Setup each shop */
    foreach ($shops as $shop_id) {
        $shop_group_id = (int) Shop::getGroupFromShop($shop_id, true);
        if (!in_array($shop_group_id, $shop_groups_list)) {
            $shop_groups_list[] = $shop_group_id;
        }
        /* Sets up configuration */
        $res = Configuration::updateValue('HOMESLIDER_WIDTH', $default_width, false, $shop_group_id, $shop_id);
        $res &= Configuration::updateValue('HOMESLIDER_SPEED', $default_speed, false, $shop_group_id, $shop_id);
        $res &= Configuration::updateValue('HOMESLIDER_PAUSE', $default_pause, false, $shop_group_id, $shop_id);
        $res &= Configuration::updateValue('HOMESLIDER_LOOP', $default_loop, false, $shop_group_id, $shop_id);
    }
    /* Sets up Shop Group configuration */
    if (count($shop_groups_list)) {
        foreach ($shop_groups_list as $shop_group_id) {
            $res = Configuration::updateValue('HOMESLIDER_WIDTH', $default_width, false, $shop_group_id);
            $res &= Configuration::updateValue('HOMESLIDER_SPEED', $default_speed, false, $shop_group_id);
            $res &= Configuration::updateValue('HOMESLIDER_PAUSE', $default_pause, false, $shop_group_id);
            $res &= Configuration::updateValue('HOMESLIDER_LOOP', $default_loop, false, $shop_group_id);
        }
    }
    /* Sets up Global configuration */
    $res = Configuration::updateValue('HOMESLIDER_WIDTH', $default_width);
    $res &= Configuration::updateValue('HOMESLIDER_SPEED', $default_speed);
    $res &= Configuration::updateValue('HOMESLIDER_PAUSE', $default_pause);
    $res &= Configuration::updateValue('HOMESLIDER_LOOP', $default_loop);
    return $res;
}
 public function __construct()
 {
     $this->name = 'tdpsthemeoptionpanel';
     $this->tab = 'front_office_features';
     $this->version = '2.0.1';
     //2.0.1 theme options for all themesdeveloper themes
     $this->author = 'ThemesDeveloper';
     $this->secure_key = Tools::encrypt($this->name);
     $this->default_language = (int) Configuration::get('PS_LANG_DEFAULT');
     $this->languages = Language::getLanguages(false);
     parent::__construct();
     $this->displayName = $this->l('Barberry Theme Options Panel');
     $this->description = $this->l('Barberry Prestashop Themes Option Panel By ThemesDeveloper');
     $this->module_path = _PS_MODULE_DIR_ . $this->name . '/';
     $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
     $this->tdpsBaseModeURL = __PS_BASE_URI__ . 'modules/tdpsthemeoptionpanel/';
     $this->backofficImage = __PS_BASE_URI__ . 'modules/tdpsthemeoptionpanel/img/';
     $this->backofficJS = __PS_BASE_URI__ . 'modules/tdpsthemeoptionpanel/js/';
     $this->backofficCSS = __PS_BASE_URI__ . 'modules/tdpsthemeoptionpanel/css/';
     $this->patternsURL = __PS_BASE_URI__ . 'modules/tdpsthemeoptionpanel/bg/';
     $this->patternsDIR = _PS_MODULE_DIR_ . 'tdpsthemeoptionpanel/bg/';
     $this->themeImageURL = _PS_BASE_URL_SSL_ . __PS_BASE_URI__ . 'themes/barberry/img/barberry/';
     $this->themeCSSURL = __PS_BASE_URI__ . 'themes/barberry/css/barberry/';
     $this->themeJSURL = __PS_BASE_URI__ . 'themes/barberry/js/barberry/';
     $this->themeImage = __PS_BASE_URI__ . 'themes/barberry/img/';
     $this->tdshopBaseURL = _PS_BASE_URL_ . __PS_BASE_URI__;
     $this->getBgPatern();
     $shop_name = array();
     $shop_group = array();
     $gettdshop = Shop::getShops();
     foreach ($gettdshop as $totalshopgroup) {
         $shopgroup = Shop::getGroupFromShop($totalshopgroup['id_shop'], false);
         $shop_name[$totalshopgroup['id_shop']] = $totalshopgroup['name'];
         $shop_group[$totalshopgroup['id_shop_group']] = $shopgroup['name'];
     }
     $this->idshop = $shop_name;
     $this->idshopgroup = $shop_group;
     $this->tdThemeOption();
 }
Exemplo n.º 3
0
 /**
  * For a given {product, product attribute} gets warehouse list
  *
  * @param int $id_product ID of the product
  * @param int $id_product_attribute Optional, uses 0 if this product does not have attributes
  * @param int $id_shop Optional, ID of the shop. Uses the context shop id (@see Context::shop)
  * @return array Warehouses (ID, reference/name concatenated)
  */
 public static function getProductWarehouseList($id_product, $id_product_attribute = 0, $id_shop = null)
 {
     // if it's a pack, returns warehouses if and only if some products use the advanced stock management
     if (Pack::isPack($id_product)) {
         $warehouses = Warehouse::getPackWarehouses($id_product);
         $res = array();
         foreach ($warehouses as $warehouse) {
             $res[]['id_warehouse'] = $warehouse;
         }
         return $res;
     }
     $share_stock = false;
     if ($id_shop === null) {
         if (Shop::getContext() == Shop::CONTEXT_GROUP) {
             $shop_group = Shop::getContextShopGroup();
         } else {
             $shop_group = Context::getContext()->shop->getGroup();
             $id_shop = (int) Context::getContext()->shop->id;
         }
         $share_stock = $shop_group->share_stock;
     } else {
         $shop_group = Shop::getGroupFromShop($id_shop);
         $share_stock = $shop_group['share_stock'];
     }
     if ($share_stock) {
         $ids_shop = Shop::getShops(true, (int) $shop_group->id, true);
     } else {
         $ids_shop = array((int) $id_shop);
     }
     $query = new DbQuery();
     $query->select('wpl.id_warehouse, CONCAT(w.reference, " - ", w.name) as name');
     $query->from('warehouse_product_location', 'wpl');
     $query->innerJoin('warehouse_shop', 'ws', 'ws.id_warehouse = wpl.id_warehouse AND id_shop IN (' . implode(',', array_map('intval', $ids_shop)) . ')');
     $query->innerJoin('warehouse', 'w', 'ws.id_warehouse = w.id_warehouse');
     $query->where('id_product = ' . (int) $id_product);
     $query->where('id_product_attribute = ' . (int) $id_product_attribute);
     $query->where('w.deleted = 0');
     $query->groupBy('wpl.id_warehouse');
     return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
 }
Exemplo n.º 4
0
    public function getFilteredObjectDetails()
    {
        $objects = array();
        if (!isset($this->urlFragments['display'])) {
            $this->fieldsToDisplay = 'full';
        }
        //get entity details
        $object = new $this->resourceConfiguration['retrieveData']['className']((int) $this->urlSegment[1]);
        if ($object->id) {
            $objects[] = $object;
            // Check if Object is accessible for this/those id_shop
            $assoc = Shop::getAssoTable($this->resourceConfiguration['retrieveData']['table']);
            if ($assoc !== false) {
                $check_shop_group = false;
                $sql = 'SELECT 1
	 						FROM `' . bqSQL(_DB_PREFIX_ . $this->resourceConfiguration['retrieveData']['table']);
                if ($assoc['type'] != 'fk_shop') {
                    $sql .= '_' . $assoc['type'];
                } else {
                    $def = ObjectModel::getDefinition($this->resourceConfiguration['retrieveData']['className']);
                    if (isset($def['fields']) && isset($def['fields']['id_shop_group'])) {
                        $check_shop_group = true;
                    }
                }
                $sql .= '`';
                foreach (self::$shopIDs as $id_shop) {
                    $OR[] = ' (id_shop = ' . (int) $id_shop . ($check_shop_group ? ' OR (id_shop = 0 AND id_shop_group=' . (int) Shop::getGroupFromShop((int) $id_shop) . ')' : '') . ') ';
                }
                $check = ' WHERE (' . implode('OR', $OR) . ') AND `' . bqSQL($this->resourceConfiguration['fields']['id']['sqlId']) . '` = ' . (int) $this->urlSegment[1];
                if (!Db::getInstance()->getValue($sql . $check)) {
                    $this->setError(404, 'This ' . $this->resourceConfiguration['retrieveData']['className'] . ' (' . (int) $this->urlSegment[1] . ') does not exists on this shop', 131);
                }
            }
            return $objects;
        }
        if (!count($this->errors)) {
            $this->objOutput->setStatus(404);
            $this->_outputEnabled = false;
            return false;
        }
    }
Exemplo n.º 5
0
 public function __construct()
 {
     $this->bootstrap = true;
     parent::__construct();
     $this->entities = array($this->l('Categories'), $this->l('Products'), $this->l('Combinations'), $this->l('Customers'), $this->l('Addresses'), $this->l('Brands'), $this->l('Suppliers'), $this->l('Alias'), $this->l('Store contacts'));
     // @since 1.5.0
     if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
         $this->entities = array_merge($this->entities, array($this->l('Supply Orders'), $this->l('Supply Order Details')));
     }
     $this->entities = array_flip($this->entities);
     switch ((int) Tools::getValue('entity')) {
         case $this->entities[$this->l('Combinations')]:
             $this->required_fields = array('group', 'attribute');
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id_product' => array('label' => $this->l('Product ID')), 'product_reference' => array('label' => $this->l('Product Reference')), 'group' => array('label' => $this->l('Attribute (Name:Type:Position)') . '*'), 'attribute' => array('label' => $this->l('Value (Value:Position)') . '*'), 'supplier_reference' => array('label' => $this->l('Supplier reference')), 'reference' => array('label' => $this->trans('Reference', array(), 'Admin.Global')), 'ean13' => array('label' => $this->l('EAN13')), 'upc' => array('label' => $this->l('UPC')), 'wholesale_price' => array('label' => $this->l('Wholesale price')), 'price' => array('label' => $this->l('Impact on price')), 'ecotax' => array('label' => $this->l('Ecotax')), 'quantity' => array('label' => $this->l('Quantity')), 'minimal_quantity' => array('label' => $this->l('Minimal quantity')), 'weight' => array('label' => $this->l('Impact on weight')), 'default_on' => array('label' => $this->l('Default (0 = No, 1 = Yes)')), 'available_date' => array('label' => $this->l('Combination availability date')), 'image_position' => array('label' => $this->l('Choose among product images by position (1,2,3...)')), 'image_url' => array('label' => $this->l('Image URLs (x,y,z...)')), 'image_alt' => array('label' => $this->l('Image alt texts (x,y,z...)')), 'shop' => array('label' => $this->l('ID / Name of shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')), 'advanced_stock_management' => array('label' => $this->l('Advanced Stock Management'), 'help' => $this->l('Enable Advanced Stock Management on product (0 = No, 1 = Yes)')), 'depends_on_stock' => array('label' => $this->l('Depends on stock'), 'help' => $this->l('0 = Use quantity set in product, 1 = Use quantity from warehouse.')), 'warehouse' => array('label' => $this->l('Warehouse'), 'help' => $this->l('ID of the warehouse to set as storage.')));
             self::$default_values = array('reference' => '', 'supplier_reference' => '', 'ean13' => '', 'upc' => '', 'wholesale_price' => 0, 'price' => 0, 'ecotax' => 0, 'quantity' => 0, 'minimal_quantity' => 1, 'weight' => 0, 'default_on' => 0, 'advanced_stock_management' => 0, 'depends_on_stock' => 0, 'available_date' => date('Y-m-d'));
             break;
         case $this->entities[$this->l('Categories')]:
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->trans('ID', array(), 'Admin.Global')), 'active' => array('label' => $this->l('Active (0/1)')), 'name' => array('label' => $this->trans('Name', array(), 'Admin.Global')), 'parent' => array('label' => $this->l('Parent category')), 'is_root_category' => array('label' => $this->l('Root category (0/1)'), 'help' => $this->l('A category root is where a category tree can begin. This is used with multistore.')), 'description' => array('label' => $this->trans('Description', array(), 'Admin.Global')), 'meta_title' => array('label' => $this->l('Meta title')), 'meta_keywords' => array('label' => $this->l('Meta keywords')), 'meta_description' => array('label' => $this->l('Meta description')), 'link_rewrite' => array('label' => $this->l('URL rewritten')), 'image' => array('label' => $this->l('Image URL')), 'shop' => array('label' => $this->l('ID / Name of shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')));
             self::$default_values = array('active' => '1', 'parent' => Configuration::get('PS_HOME_CATEGORY'), 'link_rewrite' => '');
             break;
         case $this->entities[$this->l('Products')]:
             self::$validators['image'] = array('AdminImportController', 'split');
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->trans('ID', array(), 'Admin.Global')), 'active' => array('label' => $this->l('Active (0/1)')), 'name' => array('label' => $this->trans('Name', array(), 'Admin.Global')), 'category' => array('label' => $this->l('Categories (x,y,z...)')), 'price_tex' => array('label' => $this->l('Price tax excluded')), 'price_tin' => array('label' => $this->l('Price tax included')), 'id_tax_rules_group' => array('label' => $this->l('Tax rules ID')), 'wholesale_price' => array('label' => $this->l('Wholesale price')), 'on_sale' => array('label' => $this->l('On sale (0/1)')), 'reduction_price' => array('label' => $this->l('Discount amount')), 'reduction_percent' => array('label' => $this->l('Discount percent')), 'reduction_from' => array('label' => $this->l('Discount from (yyyy-mm-dd)')), 'reduction_to' => array('label' => $this->l('Discount to (yyyy-mm-dd)')), 'reference' => array('label' => $this->l('Reference #')), 'supplier_reference' => array('label' => $this->l('Supplier reference #')), 'supplier' => array('label' => $this->l('Supplier')), 'manufacturer' => array('label' => $this->l('Brand')), 'ean13' => array('label' => $this->l('EAN13')), 'upc' => array('label' => $this->l('UPC')), 'ecotax' => array('label' => $this->l('Ecotax')), 'width' => array('label' => $this->l('Width')), 'height' => array('label' => $this->l('Height')), 'depth' => array('label' => $this->l('Depth')), 'weight' => array('label' => $this->l('Weight')), 'quantity' => array('label' => $this->l('Quantity')), 'minimal_quantity' => array('label' => $this->l('Minimal quantity')), 'visibility' => array('label' => $this->l('Visibility')), 'additional_shipping_cost' => array('label' => $this->l('Additional shipping cost')), 'unity' => array('label' => $this->l('Unit for the unit price')), 'unit_price' => array('label' => $this->l('Unit price')), 'description_short' => array('label' => $this->l('Short description')), 'description' => array('label' => $this->trans('Description', array(), 'Admin.Global')), 'tags' => array('label' => $this->l('Tags (x,y,z...)')), 'meta_title' => array('label' => $this->l('Meta title')), 'meta_keywords' => array('label' => $this->l('Meta keywords')), 'meta_description' => array('label' => $this->l('Meta description')), 'link_rewrite' => array('label' => $this->l('URL rewritten')), 'available_now' => array('label' => $this->l('Text when in stock')), 'available_later' => array('label' => $this->l('Text when backorder allowed')), 'available_for_order' => array('label' => $this->l('Available for order (0 = No, 1 = Yes)')), 'available_date' => array('label' => $this->l('Product availability date')), 'date_add' => array('label' => $this->l('Product creation date')), 'show_price' => array('label' => $this->l('Show price (0 = No, 1 = Yes)')), 'image' => array('label' => $this->l('Image URLs (x,y,z...)')), 'image_alt' => array('label' => $this->l('Image alt texts (x,y,z...)')), 'delete_existing_images' => array('label' => $this->l('Delete existing images (0 = No, 1 = Yes)')), 'features' => array('label' => $this->l('Feature (Name:Value:Position:Customized)')), 'online_only' => array('label' => $this->l('Available online only (0 = No, 1 = Yes)')), 'condition' => array('label' => $this->l('Condition')), 'customizable' => array('label' => $this->l('Customizable (0 = No, 1 = Yes)')), 'uploadable_files' => array('label' => $this->l('Uploadable files (0 = No, 1 = Yes)')), 'text_fields' => array('label' => $this->l('Text fields (0 = No, 1 = Yes)')), 'out_of_stock' => array('label' => $this->l('Action when out of stock')), 'is_virtual' => array('label' => $this->l('Virtual product (0 = No, 1 = Yes)')), 'file_url' => array('label' => $this->l('File URL')), 'nb_downloadable' => array('label' => $this->l('Number of allowed downloads'), 'help' => $this->l('Number of downloads allowed per customer. Set to 0 for unlimited downloads.')), 'date_expiration' => array('label' => $this->l('Expiration date (yyyy-mm-dd)')), 'nb_days_accessible' => array('label' => $this->l('Number of days'), 'help' => $this->l('Number of days this file can be accessed by customers. Set to zero for unlimited access.')), 'shop' => array('label' => $this->l('ID / Name of shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')), 'advanced_stock_management' => array('label' => $this->l('Advanced Stock Management'), 'help' => $this->l('Enable Advanced Stock Management on product (0 = No, 1 = Yes).')), 'depends_on_stock' => array('label' => $this->l('Depends on stock'), 'help' => $this->l('0 = Use quantity set in product, 1 = Use quantity from warehouse.')), 'warehouse' => array('label' => $this->l('Warehouse'), 'help' => $this->l('ID of the warehouse to set as storage.')), 'accessories' => array('label' => $this->l('Accessories (x,y,z...)')));
             self::$default_values = array('id_category' => array((int) Configuration::get('PS_HOME_CATEGORY')), 'id_category_default' => null, 'active' => '1', 'width' => 0.0, 'height' => 0.0, 'depth' => 0.0, 'weight' => 0.0, 'visibility' => 'both', 'additional_shipping_cost' => 0.0, 'unit_price' => 0, 'quantity' => 0, 'minimal_quantity' => 1, 'price' => 0, 'id_tax_rules_group' => 0, 'description_short' => array((int) Configuration::get('PS_LANG_DEFAULT') => ''), 'link_rewrite' => array((int) Configuration::get('PS_LANG_DEFAULT') => ''), 'online_only' => 0, 'condition' => 'new', 'available_date' => date('Y-m-d'), 'date_add' => date('Y-m-d H:i:s'), 'date_upd' => date('Y-m-d H:i:s'), 'customizable' => 0, 'uploadable_files' => 0, 'text_fields' => 0, 'advanced_stock_management' => 0, 'depends_on_stock' => 0, 'is_virtual' => 0);
             break;
         case $this->entities[$this->l('Customers')]:
             //Overwrite required_fields AS only email is required whereas other entities
             $this->required_fields = array('email', 'passwd', 'lastname', 'firstname');
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->trans('ID', array(), 'Admin.Global')), 'active' => array('label' => $this->l('Active  (0/1)')), 'id_gender' => array('label' => $this->l('Titles ID (Mr = 1, Ms = 2, else 0)')), 'email' => array('label' => $this->l('Email *')), 'passwd' => array('label' => $this->l('Password *')), 'birthday' => array('label' => $this->l('Birthday (yyyy-mm-dd)')), 'lastname' => array('label' => $this->l('Last Name *')), 'firstname' => array('label' => $this->l('First Name *')), 'newsletter' => array('label' => $this->l('Newsletter (0/1)')), 'optin' => array('label' => $this->l('Partner offers (0/1)')), 'date_add' => array('label' => $this->l('Registration date (yyyy-mm-dd)')), 'group' => array('label' => $this->l('Groups (x,y,z...)')), 'id_default_group' => array('label' => $this->l('Default group ID')), 'id_shop' => array('label' => $this->l('ID / Name of shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')));
             self::$default_values = array('active' => '1', 'id_shop' => Configuration::get('PS_SHOP_DEFAULT'));
             break;
         case $this->entities[$this->l('Addresses')]:
             //Overwrite required_fields
             $this->required_fields = array('alias', 'lastname', 'firstname', 'address1', 'postcode', 'country', 'customer_email', 'city');
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->trans('ID', array(), 'Admin.Global')), 'alias' => array('label' => $this->l('Alias *')), 'active' => array('label' => $this->l('Active  (0/1)')), 'customer_email' => array('label' => $this->l('Customer email *')), 'id_customer' => array('label' => $this->l('Customer ID')), 'manufacturer' => array('label' => $this->l('Brand')), 'supplier' => array('label' => $this->l('Supplier')), 'company' => array('label' => $this->trans('Company', array(), 'Admin.Global')), 'lastname' => array('label' => $this->l('Last Name *')), 'firstname' => array('label' => $this->l('First Name *')), 'address1' => array('label' => $this->l('Address 1 *')), 'address2' => array('label' => $this->l('Address 2')), 'postcode' => array('label' => $this->l('Zip/postal code *')), 'city' => array('label' => $this->l('City *')), 'country' => array('label' => $this->l('Country *')), 'state' => array('label' => $this->l('State')), 'other' => array('label' => $this->l('Other')), 'phone' => array('label' => $this->l('Phone')), 'phone_mobile' => array('label' => $this->l('Mobile Phone')), 'vat_number' => array('label' => $this->l('VAT number')), 'dni' => array('label' => $this->l('DNI/NIF/NIE')));
             self::$default_values = array('alias' => 'Alias', 'postcode' => 'X');
             break;
         case $this->entities[$this->l('Brands')]:
         case $this->entities[$this->l('Suppliers')]:
             //Overwrite validators AS name is not MultiLangField
             self::$validators = array('description' => array('AdminImportController', 'createMultiLangField'), 'short_description' => array('AdminImportController', 'createMultiLangField'), 'meta_title' => array('AdminImportController', 'createMultiLangField'), 'meta_keywords' => array('AdminImportController', 'createMultiLangField'), 'meta_description' => array('AdminImportController', 'createMultiLangField'));
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->trans('ID', array(), 'Admin.Global')), 'active' => array('label' => $this->l('Active (0/1)')), 'name' => array('label' => $this->trans('Name', array(), 'Admin.Global')), 'description' => array('label' => $this->trans('Description', array(), 'Admin.Global')), 'short_description' => array('label' => $this->l('Short description')), 'meta_title' => array('label' => $this->l('Meta title')), 'meta_keywords' => array('label' => $this->l('Meta keywords')), 'meta_description' => array('label' => $this->l('Meta description')), 'image' => array('label' => $this->l('Image URL')), 'shop' => array('label' => $this->l('ID / Name of group shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')));
             self::$default_values = array('shop' => Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT')));
             break;
         case $this->entities[$this->l('Alias')]:
             //Overwrite required_fields
             $this->required_fields = array('alias', 'search');
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->trans('ID', array(), 'Admin.Global')), 'alias' => array('label' => $this->l('Alias *')), 'search' => array('label' => $this->l('Search *')), 'active' => array('label' => $this->l('Active')));
             self::$default_values = array('active' => '1');
             break;
         case $this->entities[$this->l('Store contacts')]:
             unset(self::$validators['name']);
             self::$validators = array('hours' => array('AdminImportController', 'split'));
             $this->required_fields = array('address1', 'city', 'country', 'latitude', 'longitude');
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->trans('ID', array(), 'Admin.Global')), 'active' => array('label' => $this->l('Active (0/1)')), 'name' => array('label' => $this->trans('Name', array(), 'Admin.Global')), 'address1' => array('label' => $this->l('Address') . '*'), 'address2' => array('label' => $this->l('Address (2)')), 'postcode' => array('label' => $this->l('Zip/postal Code')), 'state' => array('label' => $this->l('State')), 'city' => array('label' => $this->trans('City', array(), 'Admin.Global') . '*'), 'country' => array('label' => $this->trans('Country', array(), 'Admin.Global') . '*'), 'latitude' => array('label' => $this->l('Latitude') . '*'), 'longitude' => array('label' => $this->l('Longitude') . '*'), 'phone' => array('label' => $this->l('Phone')), 'fax' => array('label' => $this->l('Fax')), 'email' => array('label' => $this->l('E-mail address')), 'note' => array('label' => $this->l('Note')), 'hours' => array('label' => $this->l('Hours (x,y,z...)')), 'image' => array('label' => $this->l('Picture URL')), 'shop' => array('label' => $this->l('ID / Name of shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')));
             self::$default_values = array('active' => '1');
             break;
     }
     // @since 1.5.0
     if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
         switch ((int) Tools::getValue('entity')) {
             case $this->entities[$this->l('Supply Orders')]:
                 // required fields
                 $this->required_fields = array('id_supplier', 'id_warehouse', 'reference', 'date_delivery_expected');
                 // available fields
                 $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->trans('ID', array(), 'Admin.Global')), 'id_supplier' => array('label' => $this->l('Supplier ID *')), 'id_lang' => array('label' => $this->l('Lang ID')), 'id_warehouse' => array('label' => $this->l('Warehouse ID *')), 'id_currency' => array('label' => $this->l('Currency ID *')), 'reference' => array('label' => $this->l('Supply Order Reference *')), 'date_delivery_expected' => array('label' => $this->l('Delivery Date (Y-M-D)*')), 'discount_rate' => array('label' => $this->l('Discount Rate')), 'is_template' => array('label' => $this->l('Template')));
                 // default values
                 self::$default_values = array('id_lang' => (int) Configuration::get('PS_LANG_DEFAULT'), 'id_currency' => Currency::getDefaultCurrency()->id, 'discount_rate' => '0', 'is_template' => '0');
                 break;
             case $this->entities[$this->l('Supply Order Details')]:
                 // required fields
                 $this->required_fields = array('supply_order_reference', 'id_product', 'unit_price_te', 'quantity_expected');
                 // available fields
                 $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'supply_order_reference' => array('label' => $this->l('Supply Order Reference *')), 'id_product' => array('label' => $this->l('Product ID *')), 'id_product_attribute' => array('label' => $this->l('Product Attribute ID')), 'unit_price_te' => array('label' => $this->l('Unit Price (tax excl.)*')), 'quantity_expected' => array('label' => $this->l('Quantity Expected *')), 'discount_rate' => array('label' => $this->l('Discount Rate')), 'tax_rate' => array('label' => $this->l('Tax Rate')));
                 // default values
                 self::$default_values = array('discount_rate' => '0', 'tax_rate' => '0');
                 break;
         }
     }
     $this->separator = ($separator = Tools::substr(strval(trim(Tools::getValue('separator'))), 0, 1)) ? $separator : ';';
     $this->convert = false;
     $this->multiple_value_separator = ($separator = Tools::substr(strval(trim(Tools::getValue('multiple_value_separator'))), 0, 1)) ? $separator : ',';
 }
Exemplo n.º 6
0
    /**
     * Returns webservice object list.
     *
     * @param string $sql_join
     * @param string $sql_filter
     * @param string $sql_sort
     * @param string $sql_limit
     *
     * @return array|null
     * @throws PrestaShopDatabaseException
     */
    public function getWebserviceObjectList($sql_join, $sql_filter, $sql_sort, $sql_limit)
    {
        $assoc = Shop::getAssoTable($this->def['table']);
        $class_name = WebserviceRequest::$ws_current_classname;
        $vars = get_class_vars($class_name);
        if ($assoc !== false) {
            if ($assoc['type'] !== 'fk_shop') {
                $multi_shop_join = ' LEFT JOIN `' . _DB_PREFIX_ . bqSQL($this->def['table']) . '_' . bqSQL($assoc['type']) . '`
										AS `multi_shop_' . bqSQL($this->def['table']) . '`
										ON (main.`' . bqSQL($this->def['primary']) . '` = `multi_shop_' . bqSQL($this->def['table']) . '`.`' . bqSQL($this->def['primary']) . '`)';
                $sql_filter = 'AND `multi_shop_' . bqSQL($this->def['table']) . '`.id_shop = ' . Context::getContext()->shop->id . ' ' . $sql_filter;
                $sql_join = $multi_shop_join . ' ' . $sql_join;
            } else {
                $vars = get_class_vars($class_name);
                foreach ($vars['shopIDs'] as $id_shop) {
                    $or[] = '(main.id_shop = ' . (int) $id_shop . (isset($this->def['fields']['id_shop_group']) ? ' OR (id_shop = 0 AND id_shop_group=' . (int) Shop::getGroupFromShop((int) $id_shop) . ')' : '') . ')';
                }
                $prepend = '';
                if (count($or)) {
                    $prepend = 'AND (' . implode('OR', $or) . ')';
                }
                $sql_filter = $prepend . ' ' . $sql_filter;
            }
        }
        $query = '
		SELECT DISTINCT main.`' . bqSQL($this->def['primary']) . '` FROM `' . _DB_PREFIX_ . bqSQL($this->def['table']) . '` AS main
		' . $sql_join . '
		WHERE 1 ' . $sql_filter . '
		' . ($sql_sort != '' ? $sql_sort : '') . '
		' . ($sql_limit != '' ? $sql_limit : '');
        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
    }
Exemplo n.º 7
0
 protected function _postProcess()
 {
     $errors = array();
     $shop_context = Shop::getContext();
     /* Processes Slider */
     if (Tools::isSubmit('submitSlider')) {
         $shop_groups_list = array();
         $shops = Shop::getContextListShopID();
         foreach ($shops as $shop_id) {
             $shop_group_id = (int) Shop::getGroupFromShop($shop_id, true);
             if (!in_array($shop_group_id, $shop_groups_list)) {
                 $shop_groups_list[] = $shop_group_id;
             }
             $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'), false, $shop_group_id, $shop_id);
             $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'), false, $shop_group_id, $shop_id);
             $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'), false, $shop_group_id, $shop_id);
             $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'), false, $shop_group_id, $shop_id);
         }
         /* Update global shop context if needed*/
         switch ($shop_context) {
             case Shop::CONTEXT_ALL:
                 $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'));
                 $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'));
                 $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'));
                 $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'));
                 if (count($shop_groups_list)) {
                     foreach ($shop_groups_list as $shop_group_id) {
                         $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'), false, $shop_group_id);
                     }
                 }
                 break;
             case Shop::CONTEXT_GROUP:
                 if (count($shop_groups_list)) {
                     foreach ($shop_groups_list as $shop_group_id) {
                         $res = Configuration::updateValue('HOMESLIDER_WIDTH', (int) Tools::getValue('HOMESLIDER_WIDTH'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_SPEED', (int) Tools::getValue('HOMESLIDER_SPEED'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_PAUSE', (int) Tools::getValue('HOMESLIDER_PAUSE'), false, $shop_group_id);
                         $res &= Configuration::updateValue('HOMESLIDER_LOOP', (int) Tools::getValue('HOMESLIDER_LOOP'), false, $shop_group_id);
                     }
                 }
                 break;
         }
         $this->clearCache();
         if (!$res) {
             $errors[] = $this->displayError($this->l('The configuration could not be updated.'));
         } else {
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=6&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
         }
     } elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_slide')) {
         $slide = new HomeSlide((int) Tools::getValue('id_slide'));
         if ($slide->active == 0) {
             $slide->active = 1;
         } else {
             $slide->active = 0;
         }
         $res = $slide->update();
         $this->clearCache();
         $this->_html .= $res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.'));
     } elseif (Tools::isSubmit('submitSlide')) {
         /* Sets ID if needed */
         if (Tools::getValue('id_slide')) {
             $slide = new HomeSlide((int) Tools::getValue('id_slide'));
             if (!Validate::isLoadedObject($slide)) {
                 $this->_html .= $this->displayError($this->l('Invalid slide ID'));
                 return false;
             }
         } else {
             $slide = new HomeSlide();
         }
         /* Sets position */
         $slide->position = (int) Tools::getValue('position');
         /* Sets active */
         $slide->active = (int) Tools::getValue('active_slide');
         /* Sets each langue fields */
         $languages = Language::getLanguages(false);
         foreach ($languages as $language) {
             $slide->title[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']);
             $slide->url[$language['id_lang']] = Tools::getValue('url_' . $language['id_lang']);
             $slide->legend[$language['id_lang']] = Tools::getValue('legend_' . $language['id_lang']);
             $slide->description[$language['id_lang']] = Tools::getValue('description_' . $language['id_lang']);
             /* Uploads image and sets slide */
             $type = Tools::strtolower(Tools::substr(strrchr($_FILES['image_' . $language['id_lang']]['name'], '.'), 1));
             $imagesize = @getimagesize($_FILES['image_' . $language['id_lang']]['tmp_name']);
             if (isset($_FILES['image_' . $language['id_lang']]) && isset($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($_FILES['image_' . $language['id_lang']]['tmp_name']) && !empty($imagesize) && in_array(Tools::strtolower(Tools::substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) {
                 $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
                 $salt = sha1(microtime());
                 if ($error = ImageManager::validateUpload($_FILES['image_' . $language['id_lang']])) {
                     $errors[] = $error;
                 } elseif (!$temp_name || !move_uploaded_file($_FILES['image_' . $language['id_lang']]['tmp_name'], $temp_name)) {
                     return false;
                 } elseif (!ImageManager::resize($temp_name, dirname(__FILE__) . '/images/' . $salt . '_' . $_FILES['image_' . $language['id_lang']]['name'], null, null, $type)) {
                     $errors[] = $this->displayError($this->l('An error occurred during the image upload process.'));
                 }
                 if (isset($temp_name)) {
                     @unlink($temp_name);
                 }
                 $slide->image[$language['id_lang']] = $salt . '_' . $_FILES['image_' . $language['id_lang']]['name'];
             } elseif (Tools::getValue('image_old_' . $language['id_lang']) != '') {
                 $slide->image[$language['id_lang']] = Tools::getValue('image_old_' . $language['id_lang']);
             }
         }
         /* Processes if no errors  */
         if (!$errors) {
             /* Adds */
             if (!Tools::getValue('id_slide')) {
                 if (!$slide->add()) {
                     $errors[] = $this->displayError($this->l('The slide could not be added.'));
                 }
             } elseif (!$slide->update()) {
                 $errors[] = $this->displayError($this->l('The slide could not be updated.'));
             }
             $this->clearCache();
         }
     } elseif (Tools::isSubmit('delete_id_slide')) {
         $slide = new HomeSlide((int) Tools::getValue('delete_id_slide'));
         $res = $slide->delete();
         $this->clearCache();
         if (!$res) {
             $this->_html .= $this->displayError('Could not delete.');
         } else {
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=1&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
         }
     }
     /* Display errors if needed */
     if (count($errors)) {
         $this->_html .= $this->displayError(implode('<br />', $errors));
     } elseif (Tools::isSubmit('submitSlide') && Tools::getValue('id_slide')) {
         Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
     } elseif (Tools::isSubmit('submitSlide')) {
         Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=3&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name);
     }
 }
Exemplo n.º 8
0
 public function getConfigFieldsValues($shop_id)
 {
     $shop_group_id = Shop::getGroupFromShop($shop_id);
     $product_type = array();
     $description = 'short';
     $shipping_price = 0;
     $shipping_country = 'UK';
     $img_type = 'large_default';
     $mpn_type = '';
     $gender = '';
     $age_group = '';
     $export_attributes = '';
     $color = array();
     $material = array();
     $pattern = array();
     $size = array();
     $export_min_price = 0;
     $no_gtin = true;
     $no_brand = true;
     $id_exists_tag = true;
     $export_nap = true;
     $quantity = true;
     $featured_products = true;
     $gen_file_in_root = true;
     foreach (Language::getLanguages(false) as $lang) {
         $product_type[$lang['id_lang']] = Configuration::get('GS_PRODUCT_TYPE', $lang['id_lang'], $shop_group_id, $shop_id);
     }
     $description = Configuration::get('GS_DESCRIPTION', 0, $shop_group_id, $shop_id);
     $shipping_price = (double) Configuration::get('GS_SHIPPING_PRICE', 0, $shop_group_id, $shop_id);
     $shipping_country = Configuration::get('GS_SHIPPING_COUNTRY', 0, $shop_group_id, $shop_id);
     $img_type = Configuration::get('GS_IMG_TYPE', 0, $shop_group_id, $shop_id);
     $mpn_type = Configuration::get('GS_MPN_TYPE', 0, $shop_group_id, $shop_id);
     $gender = Configuration::get('GS_GENDER', 0, $shop_group_id, $shop_id);
     $age_group = Configuration::get('GS_AGE_GROUP', 0, $shop_group_id, $shop_id);
     $export_attributes = Configuration::get('GS_ATTRIBUTES', 0, $shop_group_id, $shop_id);
     $color = explode(";", Configuration::get('GS_COLOR', 0, $shop_group_id, $shop_id));
     $material = explode(";", Configuration::get('GS_MATERIAL', 0, $shop_group_id, $shop_id));
     $pattern = explode(";", Configuration::get('GS_PATTERN', 0, $shop_group_id, $shop_id));
     $size = explode(";", Configuration::get('GS_SIZE', 0, $shop_group_id, $shop_id));
     $export_min_price = (double) Configuration::get('GS_EXPORT_MIN_PRICE', 0, $shop_group_id, $shop_id);
     $no_gtin &= (bool) Configuration::get('GS_NO_GTIN', 0, $shop_group_id, $shop_id);
     $no_brand &= (bool) Configuration::get('GS_NO_BRAND', 0, $shop_group_id, $shop_id);
     $id_exists_tag &= (bool) Configuration::get('GS_ID_EXISTS_TAG', 0, $shop_group_id, $shop_id);
     $export_nap &= (bool) Configuration::get('GS_EXPORT_NAP', 0, $shop_group_id, $shop_id);
     $quantity &= (bool) Configuration::get('GS_QUANTITY', 0, $shop_group_id, $shop_id);
     $featured_products &= (bool) Configuration::get('GS_FEATURED_PRODUCTS', 0, $shop_group_id, $shop_id);
     $gen_file_in_root &= (bool) Configuration::get('GS_GEN_FILE_IN_ROOT', 0, $shop_group_id, $shop_id);
     return array('product_type[]' => $product_type, 'description' => $description, 'shipping_price' => (double) $shipping_price, 'shipping_country' => $shipping_country, 'img_type' => $img_type, 'mpn_type' => $mpn_type, 'gender' => $gender, 'age_group' => $age_group, 'export_attributes' => (double) $export_attributes, 'color[]' => $color, 'material[]' => $material, 'pattern[]' => $pattern, 'size[]' => $size, 'export_min_price' => (double) $export_min_price, 'no_gtin' => (int) $no_gtin, 'no_brand' => (int) $no_brand, 'id_exists_tag' => (int) $id_exists_tag, 'export_nap' => (int) $export_nap, 'quantity' => (int) $quantity, 'featured_products' => (int) $featured_products, 'gen_file_in_root' => (int) $gen_file_in_root);
 }
Exemplo n.º 9
0
 public function getConfigFieldsValues()
 {
     $shops = Shop::getContextListShopID();
     $is_search_on = true;
     foreach ($shops as $shop_id) {
         $shop_group_id = Shop::getGroupFromShop($shop_id);
         $is_search_on &= (bool) Configuration::get('MOD_BLOCKTOPMENU_SEARCH', null, $shop_group_id, $shop_id);
     }
     return array('search' => (int) $is_search_on);
 }
Exemplo n.º 10
0
 public function __construct()
 {
     $this->entities = array($this->l('Categories'), $this->l('Products'), $this->l('Combinations'), $this->l('Customers'), $this->l('Addresses'), $this->l('Manufacturers'), $this->l('Suppliers'));
     // @since 1.5.0
     if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
         $this->entities = array_merge($this->entities, array($this->l('Supply Orders'), $this->l('Supply Order Details')));
     }
     $this->entities = array_flip($this->entities);
     switch ((int) Tools::getValue('entity')) {
         case $this->entities[$this->l('Combinations')]:
             $this->required_fields = array('id_product', 'group', 'attribute');
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id_product' => array('label' => $this->l('Product ID') . '*'), 'group' => array('label' => $this->l('Attribute (Name:Type:Position)') . '*'), 'attribute' => array('label' => $this->l('Value (Value:Position)') . '*'), 'supplier_reference' => array('label' => $this->l('Supplier reference')), 'reference' => array('label' => $this->l('Reference')), 'ean13' => array('label' => $this->l('EAN13')), 'upc' => array('label' => $this->l('UPC')), 'wholesale_price' => array('label' => $this->l('Wholesale price')), 'price' => array('label' => $this->l('Impact on price')), 'ecotax' => array('label' => $this->l('Ecotax')), 'quantity' => array('label' => $this->l('Quantity')), 'minimal_quantity' => array('label' => $this->l('Minimal quantity')), 'weight' => array('label' => $this->l('Impact on weight')), 'default_on' => array('label' => $this->l('Default (0 = No, 1 = Yes)')), 'image_position' => array('label' => $this->l('Image position')), 'image_url' => array('label' => $this->l('Image URL')), 'delete_existing_images' => array('label' => $this->l('Delete existing images (0 = No, 1 = Yes)')), 'shop' => array('label' => $this->l('ID / Name of shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')));
             self::$default_values = array('reference' => '', 'supplier_reference' => '', 'ean13' => '', 'upc' => '', 'wholesale_price' => 0, 'price' => 0, 'ecotax' => 0, 'quantity' => 0, 'minimal_quantity' => 1, 'weight' => 0, 'default_on' => 0);
             break;
         case $this->entities[$this->l('Categories')]:
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID')), 'active' => array('label' => $this->l('Active (0/1)')), 'name' => array('label' => $this->l('Name *')), 'parent' => array('label' => $this->l('Parent category')), 'is_root_category' => array('label' => $this->l('Root category (0/1)'), 'help' => $this->l('A category root is where a category tree can begin. This is used with multistore.')), 'description' => array('label' => $this->l('Description')), 'meta_title' => array('label' => $this->l('Meta title')), 'meta_keywords' => array('label' => $this->l('Meta keywords')), 'meta_description' => array('label' => $this->l('Meta description')), 'link_rewrite' => array('label' => $this->l('URL rewritten')), 'image' => array('label' => $this->l('Image URL')), 'shop' => array('label' => $this->l('ID / Name of shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')));
             self::$default_values = array('active' => '1', 'parent' => Configuration::get('PS_HOME_CATEGORY'), 'link_rewrite' => '');
             break;
         case $this->entities[$this->l('Products')]:
             self::$validators['image'] = array('AdminImportController', 'split');
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID')), 'active' => array('label' => $this->l('Active (0/1)')), 'name' => array('label' => $this->l('Name *')), 'category' => array('label' => $this->l('Categories (x,y,z...)')), 'price_tex' => array('label' => $this->l('Price tax excluded')), 'price_tin' => array('label' => $this->l('Price tax included')), 'id_tax_rules_group' => array('label' => $this->l('Tax rules ID')), 'wholesale_price' => array('label' => $this->l('Wholesale price')), 'on_sale' => array('label' => $this->l('On sale (0/1)')), 'reduction_price' => array('label' => $this->l('Discount amount')), 'reduction_percent' => array('label' => $this->l('Discount percent')), 'reduction_from' => array('label' => $this->l('Discount from (yyyy-mm-dd)')), 'reduction_to' => array('label' => $this->l('Discount to (yyyy-mm-dd)')), 'reference' => array('label' => $this->l('Reference #')), 'supplier_reference' => array('label' => $this->l('Supplier reference #')), 'supplier' => array('label' => $this->l('Supplier')), 'manufacturer' => array('label' => $this->l('Manufacturer')), 'ean13' => array('label' => $this->l('EAN13')), 'upc' => array('label' => $this->l('UPC')), 'ecotax' => array('label' => $this->l('Ecotax')), 'weight' => array('label' => $this->l('Weight')), 'quantity' => array('label' => $this->l('Quantity')), 'description_short' => array('label' => $this->l('Short description')), 'description' => array('label' => $this->l('Description')), 'tags' => array('label' => $this->l('Tags (x,y,z...)')), 'meta_title' => array('label' => $this->l('Meta title')), 'meta_keywords' => array('label' => $this->l('Meta keywords')), 'meta_description' => array('label' => $this->l('Meta description')), 'link_rewrite' => array('label' => $this->l('URL rewritten')), 'available_now' => array('label' => $this->l('Text when in stock')), 'available_later' => array('label' => $this->l('Text when backorder allowed')), 'available_for_order' => array('label' => $this->l('Available for order (0 = No, 1 = Yes)')), 'date_add' => array('label' => $this->l('Product creation date')), 'show_price' => array('label' => $this->l('Show price (0 = No, 1 = Yes)')), 'image' => array('label' => $this->l('Image URLs (x,y,z...)')), 'delete_existing_images' => array('label' => $this->l('Delete existing images (0 = No, 1 = Yes)')), 'features' => array('label' => $this->l('Feature(Name:Value:Position)')), 'online_only' => array('label' => $this->l('Available online only (0 = No, 1 = Yes)')), 'condition' => array('label' => $this->l('Condition')), 'shop' => array('label' => $this->l('ID / Name of shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')));
             self::$default_values = array('id_category' => array((int) Configuration::get('PS_HOME_CATEGORY')), 'id_category_default' => (int) Configuration::get('PS_HOME_CATEGORY'), 'active' => '1', 'quantity' => 0, 'price' => 0, 'id_tax_rules_group' => 0, 'description_short' => array((int) Configuration::get('PS_LANG_DEFAULT') => ''), 'link_rewrite' => array((int) Configuration::get('PS_LANG_DEFAULT') => ''), 'online_only' => 0, 'condition' => 'new', 'date_add' => date('Y-m-d H:i:s'), 'condition' => 'new');
             break;
         case $this->entities[$this->l('Customers')]:
             //Overwrite required_fields AS only email is required whereas other entities
             $this->required_fields = array('email', 'passwd', 'lastname', 'firstname');
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID')), 'active' => array('label' => $this->l('Active  (0/1)')), 'id_gender' => array('label' => $this->l('Titles ID (Mr = 1, Ms = 2, else 0)')), 'email' => array('label' => $this->l('Email *')), 'passwd' => array('label' => $this->l('Password *')), 'birthday' => array('label' => $this->l('Birthday (yyyy-mm-dd)')), 'lastname' => array('label' => $this->l('Last Name *')), 'firstname' => array('label' => $this->l('First Name *')), 'newsletter' => array('label' => $this->l('Newsletter (0/1)')), 'optin' => array('label' => $this->l('Opt-in (0/1)')), 'id_shop' => array('label' => $this->l('ID / Name of shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')));
             self::$default_values = array('active' => '1', 'id_shop' => Configuration::get('PS_SHOP_DEFAULT'));
             break;
         case $this->entities[$this->l('Addresses')]:
             //Overwrite required_fields
             $this->required_fields = array('lastname', 'firstname', 'address1', 'postcode', 'country', 'customer_email', 'city');
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID')), 'alias' => array('label' => $this->l('Alias *')), 'active' => array('label' => $this->l('Active  (0/1)')), 'customer_email' => array('label' => $this->l('Customer email')), 'id_customer' => array('label' => $this->l('Customer ID:')), 'manufacturer' => array('label' => $this->l('Manufacturer')), 'supplier' => array('label' => $this->l('Supplier')), 'company' => array('label' => $this->l('Company')), 'lastname' => array('label' => $this->l('Last Name *')), 'firstname' => array('label' => $this->l('First Name *')), 'address1' => array('label' => $this->l('Address 1 *')), 'address2' => array('label' => $this->l('Address 2')), 'postcode' => array('label' => $this->l('Postal code / Zipcode*')), 'city' => array('label' => $this->l('City *')), 'country' => array('label' => $this->l('Country *')), 'state' => array('label' => $this->l('State')), 'other' => array('label' => $this->l('Other')), 'phone' => array('label' => $this->l('Phone')), 'phone_mobile' => array('label' => $this->l('Mobile Phone')), 'vat_number' => array('label' => $this->l('VAT number')));
             self::$default_values = array('alias' => 'Alias', 'postcode' => 'X');
             break;
         case $this->entities[$this->l('Manufacturers')]:
         case $this->entities[$this->l('Suppliers')]:
             //Overwrite validators AS name is not MultiLangField
             self::$validators = array('description' => array('AdminImportController', 'createMultiLangField'), 'short_description' => array('AdminImportController', 'createMultiLangField'), 'meta_title' => array('AdminImportController', 'createMultiLangField'), 'meta_keywords' => array('AdminImportController', 'createMultiLangField'), 'meta_description' => array('AdminImportController', 'createMultiLangField'));
             $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID')), 'active' => array('label' => $this->l('Active (0/1)')), 'name' => array('label' => $this->l('Name *')), 'description' => array('label' => $this->l('Description')), 'short_description' => array('label' => $this->l('Short description')), 'meta_title' => array('label' => $this->l('Meta title')), 'meta_keywords' => array('label' => $this->l('Meta keywords')), 'meta_description' => array('label' => $this->l('Meta description')), 'shop' => array('label' => $this->l('ID / Name of group shop'), 'help' => $this->l('Ignore this field if you don\'t use the Multistore tool. If you leave this field empty, the default shop will be used.')));
             self::$default_values = array('shop' => Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT')));
             break;
             // @since 1.5.0
         // @since 1.5.0
         case $this->entities[$this->l('Supply Orders')]:
             if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                 // required fields
                 $this->required_fields = array('id_supplier', 'id_warehouse', 'reference', 'date_delivery_expected');
                 // available fields
                 $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'id' => array('label' => $this->l('ID')), 'id_supplier' => array('label' => $this->l('Supplier ID *')), 'id_lang' => array('label' => $this->l('Lang ID')), 'id_warehouse' => array('label' => $this->l('Warehouse ID *')), 'id_currency' => array('label' => $this->l('Currency ID *')), 'reference' => array('label' => $this->l('Supply Order Reference *')), 'date_delivery_expected' => array('label' => $this->l('Delivery Date (Y-M-D)*')), 'discount_rate' => array('label' => $this->l('Discount Rate')), 'is_template' => array('label' => $this->l('Template')));
                 // default values
                 self::$default_values = array('id_lang' => (int) Configuration::get('PS_LANG_DEFAULT'), 'id_currency' => Currency::getDefaultCurrency()->id, 'discount_rate' => '0', 'is_template' => '0');
             }
             break;
             // @since 1.5.0
         // @since 1.5.0
         case $this->entities[$this->l('Supply Order Details')]:
             if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                 // required fields
                 $this->required_fields = array('supply_order_reference', 'id_product', 'unit_price_te', 'quantity_expected');
                 // available fields
                 $this->available_fields = array('no' => array('label' => $this->l('Ignore this column')), 'supply_order_reference' => array('label' => $this->l('Supply Order Reference *')), 'id_product' => array('label' => $this->l('Product ID *')), 'id_product_attribute' => array('label' => $this->l('Product Attribute ID')), 'unit_price_te' => array('label' => $this->l('Unit Price (tax excl.)*')), 'quantity_expected' => array('label' => $this->l('Quantity Expected *')), 'discount_rate' => array('label' => $this->l('Discount Rate')), 'tax_rate' => array('label' => $this->l('Tax Rate')));
                 // default values
                 self::$default_values = array('discount_rate' => '0', 'tax_rate' => '0');
             }
     }
     $this->separator = strval(trim(Tools::getValue('separator', ';')));
     if (is_null(Tools::getValue('multiple_value_separator')) || trim(Tools::getValue('multiple_value_separator')) == '') {
         $this->multiple_value_separator = ',';
     } else {
         $this->multiple_value_separator = Tools::getValue('multiple_value_separator');
     }
     parent::__construct();
 }
Exemplo n.º 11
0
			</tr>
		</thead>
		<tbody>
			<?php 
    if ($outputTemplates) {
        $useSliders = $arrSlidersTemplates;
        $pagenum = isset($_GET['pagenumt']) ? absint($_GET['pagenumt']) : 1;
        $offset = ($pagenum - 1) * $limit;
    } else {
        $useSliders = $arrSliders;
        $pagenum = isset($_GET['pagenum']) ? absint($_GET['pagenum']) : 1;
        $offset = ($pagenum - 1) * $limit;
    }
    $cur_offset = 0;
    $current_id_shop_group = Context::getcontext()->shop->id_shop_group;
    $current_shop_id = Context::getcontext()->shop->id;
    $shop_context = Context::getcontext()->cookie->shopContext;
    if (!empty($shop_context) && isset($shop_context)) {
        $shop_contexttype = substr($shop_context, 0, 1);
    } else {
        $shop_contexttype = 'a';
    }
    foreach ($useSliders as $slider) {
        if ($outputTemplates) {
            $slider->arrParams['id_shop'] = $current_shop_id;
        }
        $id_shop = @$slider->arrParams['id_shop'];
        $id_shop_group = Shop::getGroupFromShop($id_shop);
        if ($current_shop_id == $id_shop && $shop_contexttype == 's' || $id_shop_group == $current_shop_id && $shop_contexttype == 'g' || $shop_contexttype == 'a') {
            $total++;
            $cur_offset++;
Exemplo n.º 12
0
 public static function setQuantity($id_product, $id_product_attribute, $quantity, $id_shop = null)
 {
     if (!Validate::isUnsignedId($id_product)) {
         return false;
     }
     $context = Context::getContext();
     if ($id_shop === null && Shop::getContext() != Shop::CONTEXT_GROUP) {
         $id_shop = (int) $context->shop->id;
     }
     $depends_on_stock = StockAvailable::dependsOnStock($id_product);
     if (!$depends_on_stock) {
         $id_stock_available = (int) StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);
         if ($id_stock_available) {
             $stock_available = new StockAvailable($id_stock_available);
             PP::setQty($stock_available, $quantity);
             $stock_available->update();
         } else {
             $out_of_stock = StockAvailable::outOfStock($id_product, $id_shop);
             $stock_available = new StockAvailable();
             $stock_available->out_of_stock = (int) $out_of_stock;
             $stock_available->id_product = (int) $id_product;
             $stock_available->id_product_attribute = (int) $id_product_attribute;
             PP::setQty($stock_available, $quantity);
             if ($id_shop === null) {
                 $shop_group = Shop::getContextShopGroup();
             } else {
                 $shop_group = new ShopGroup((int) Shop::getGroupFromShop((int) $id_shop));
             }
             if ($shop_group->share_stock) {
                 $stock_available->id_shop = 0;
                 $stock_available->id_shop_group = (int) $shop_group->id;
             } else {
                 $stock_available->id_shop = (int) $id_shop;
                 $stock_available->id_shop_group = 0;
             }
             $stock_available->add();
         }
         Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $stock_available->quantity + $stock_available->quantity_remainder));
     }
     Cache::clean('StockAvailable::getQuantityAvailableByProduct_' . (int) $id_product . '*');
 }
Exemplo n.º 13
0
    /**
     * Return cart products
     *
     * @result array Products
     */
    public function getProducts($refresh = false, $id_product = false, $id_country = null)
    {
        if (!$this->id) {
            return array();
        }
        // Product cache must be strictly compared to NULL, or else an empty cart will add dozens of queries
        if ($this->_products !== null && !$refresh) {
            // Return product row with specified ID if it exists
            if (is_int($id_product)) {
                foreach ($this->_products as $product) {
                    if ($product['id_product'] == $id_product) {
                        return array($product);
                    }
                }
                return array();
            }
            return $this->_products;
        }
        $shop_group = Shop::getGroupFromShop(Shop::getContextShopID(), false);
        if ($shop_group['share_order']) {
            $id_shop = 'cp.id_shop';
        } else {
            $id_shop = (int) Shop::getContextShopID();
        }
        if (!$id_country) {
            $id_country = Context::getContext()->country->id;
        }
        // Build query
        $sql = new DbQuery();
        // Build SELECT
        $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
						pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, product_shop.`id_category_default`, p.`id_supplier`,
						p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`, product_shop.`available_for_order`, product_shop.`price`, p.`weight`,
						stock.`quantity` quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, product_shop.`active`, p.`date_add`,
						p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
						CONCAT(cp.`id_product`, cp.`id_product_attribute`, cp.`id_address_delivery`) AS unique_id, cp.id_address_delivery,
						product_shop.`wholesale_price`, product_shop.advanced_stock_management');
        // Build FROM
        $sql->from('cart_product', 'cp');
        // Build JOIN
        $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
        $sql->innerJoin('product_shop', 'product_shop', '(product_shop.id_shop=' . $id_shop . ' AND product_shop.id_product = p.id_product)');
        $sql->leftJoin('product_lang', 'pl', '
			p.`id_product` = pl.`id_product`
			AND pl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('pl', $id_shop));
        $sql->leftJoin('category_lang', 'cl', '
			product_shop.`id_category_default` = cl.`id_category`
			AND cl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('cl', $id_shop));
        // @todo test if everything is ok, then refactorise call of this method
        $sql->join(Product::sqlStock('cp', 'cp'));
        // Build WHERE clauses
        $sql->where('cp.`id_cart` = ' . (int) $this->id);
        if ($id_product) {
            $sql->where('cp.`id_product` = ' . (int) $id_product);
        }
        $sql->where('p.`id_product` IS NOT NULL');
        // Build GROUP BY
        $sql->groupBy('unique_id');
        // Build ORDER BY
        $sql->orderBy('p.id_product, cp.id_product_attribute, cp.date_add ASC');
        if (Customization::isFeatureActive()) {
            $sql->select('cu.`id_customization`, cu.`quantity` AS customization_quantity');
            $sql->leftJoin('customization', 'cu', 'p.`id_product` = cu.`id_product` AND cp.`id_product_attribute` = cu.id_product_attribute AND cu.id_cart=' . (int) $this->id);
        } else {
            $sql->select('NULL AS customization_quantity, NULL AS id_customization');
        }
        if (Combination::isFeatureActive()) {
            $sql->select('
				product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr,
				IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference,
				IF (IFNULL(pa.`supplier_reference`, \'\') = \'\', p.`supplier_reference`, pa.`supplier_reference`) AS supplier_reference,
				(p.`weight`+ pa.`weight`) weight_attribute,
				IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13,
				IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc,
				pai.`id_image` as pai_id_image, il.`legend` as pai_legend,
				IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity
			');
            $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cp.`id_product_attribute`');
            $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.id_shop=' . $id_shop . ' AND product_attribute_shop.id_product_attribute = pa.id_product_attribute)');
            $sql->leftJoin('product_attribute_image', 'pai', 'pai.`id_product_attribute` = pa.`id_product_attribute`');
            $sql->leftJoin('image_lang', 'il', 'il.id_image = pai.id_image AND il.id_lang = ' . (int) $this->id_lang);
        } else {
            $sql->select('p.`reference` AS reference, p.`supplier_reference` AS supplier_reference, p.`ean13`,
				p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity');
        }
        $result = Db::getInstance()->executeS($sql);
        // Reset the cache before the following return, or else an empty cart will add dozens of queries
        $products_ids = array();
        $pa_ids = array();
        if ($result) {
            foreach ($result as $row) {
                $products_ids[] = $row['id_product'];
                $pa_ids[] = $row['id_product_attribute'];
            }
        }
        // Thus you can avoid one query per product, because there will be only one query for all the products of the cart
        Product::cacheProductsFeatures($products_ids);
        Cart::cacheSomeAttributesLists($pa_ids, $this->id_lang);
        $this->_products = array();
        if (empty($result)) {
            return array();
        }
        $cart_shop_context = Context::getContext()->cloneContext();
        foreach ($result as &$row) {
            if (isset($row['ecotax_attr']) && $row['ecotax_attr'] > 0) {
                $row['ecotax'] = (double) $row['ecotax_attr'];
            }
            $row['stock_quantity'] = (int) $row['quantity'];
            // for compatibility with 1.2 themes
            $row['quantity'] = (int) $row['cart_quantity'];
            if (isset($row['id_product_attribute']) && (int) $row['id_product_attribute'] && isset($row['weight_attribute'])) {
                $row['weight'] = (double) $row['weight_attribute'];
            }
            if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
                $address_id = (int) $this->id_address_invoice;
            } else {
                $address_id = (int) $row['id_address_delivery'];
            }
            if (!Address::addressExists($address_id)) {
                $address_id = null;
            }
            if ($cart_shop_context->shop->id != $row['id_shop']) {
                $cart_shop_context->shop = new Shop((int) $row['id_shop']);
            }
            if ($this->_taxCalculationMethod == PS_TAX_EXC) {
                $row['price'] = Product::getPriceStatic((int) $row['id_product'], false, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 2, null, false, true, (int) $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, (int) $address_id ? (int) $address_id : null, $specific_price_output, true, true, $cart_shop_context);
                // Here taxes are computed only once the quantity has been applied to the product price
                $row['price_wt'] = Product::getPriceStatic((int) $row['id_product'], true, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 2, null, false, true, (int) $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, (int) $address_id ? (int) $address_id : null, $null, true, true, $cart_shop_context);
                $tax_rate = Tax::getProductTaxRate((int) $row['id_product'], (int) $address_id);
                $row['total_wt'] = Tools::ps_round($row['price'] * (double) $row['cart_quantity'] * (1 + (double) $tax_rate / 100), 2);
                $row['total'] = $row['price'] * (int) $row['cart_quantity'];
            } else {
                $row['price'] = Product::getPriceStatic((int) $row['id_product'], false, (int) $row['id_product_attribute'], 2, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, (int) $address_id ? (int) $address_id : null, $specific_price_output, true, true, $cart_shop_context);
                $row['price_wt'] = Product::getPriceStatic((int) $row['id_product'], true, (int) $row['id_product_attribute'], 2, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, (int) $address_id ? (int) $address_id : null, $null, true, true, $cart_shop_context);
                // In case when you use QuantityDiscount, getPriceStatic() can be return more of 2 decimals
                $row['price_wt'] = Tools::ps_round($row['price_wt'], 2);
                $row['total_wt'] = $row['price_wt'] * (int) $row['cart_quantity'];
                $row['total'] = Tools::ps_round($row['price'] * (int) $row['cart_quantity'], 2);
            }
            if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0) {
                $row2 = Db::getInstance()->getRow('
					SELECT image_shop.`id_image` id_image, il.`legend`
					FROM `' . _DB_PREFIX_ . 'image` i' . Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1') . '
					LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang . ')
					WHERE i.`id_product` = ' . (int) $row['id_product'] . ' AND image_shop.`cover` = 1');
                if (!$row2) {
                    $row2 = array('id_image' => false, 'legend' => false);
                } else {
                    $row = array_merge($row, $row2);
                }
            } else {
                $row['id_image'] = $row['pai_id_image'];
                $row['legend'] = $row['pai_legend'];
            }
            $row['reduction_applies'] = $specific_price_output && (double) $specific_price_output['reduction'];
            $row['quantity_discount_applies'] = $specific_price_output && $row['cart_quantity'] >= (int) $specific_price_output['from_quantity'];
            $row['id_image'] = Product::defineProductImage($row, $this->id_lang);
            $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
            $row['features'] = Product::getFeaturesStatic((int) $row['id_product']);
            if (array_key_exists($row['id_product_attribute'] . '-' . $this->id_lang, self::$_attributesLists)) {
                $row = array_merge($row, self::$_attributesLists[$row['id_product_attribute'] . '-' . $this->id_lang]);
            }
            $row = Product::getTaxesInformations($row, $cart_shop_context);
            $this->_products[] = $row;
        }
        return $this->_products;
    }
Exemplo n.º 14
0
    public static function execImportAttribute($pdt, $idP)
    {
        $product = new Product($idP);
        foreach ($pdt as $attributes) {
            $idPA = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_product_attribute` FROM `' . _DB_PREFIX_ . 'ec_ecopresto_product_attribute` WHERE `id_shop` = ' . (int) $attributes->id_shop . ' AND `reference` = "' . pSQL($attributes->supplier_reference) . '"');
            if (!$idPA) {
                Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'product_attribute` (`id_product`,`reference`,`supplier_reference`,`ean13`,`wholesale_price`,`price`,`weight`,`default_on`)
										VALUES (' . (int) $idP . ',"' . pSQL($attributes->reference) . '","' . pSQL($attributes->supplier_reference) . '",' . (int) $attributes->ean13 . ',"' . pSQL($attributes->wholesale_price) . '","' . pSQL($attributes->price) . '","' . pSQL($attributes->weight) . '",' . (int) $attributes->default_on . ')');
                $idPA = Db::getInstance()->Insert_ID();
                if (version_compare(_PS_VERSION_, '1.5', '>=')) {
                    Db::getInstance()->insert('product_attribute_shop', array('id_product_attribute' => (int) $idPA, 'id_shop' => (int) $attributes->id_shop, 'wholesale_price' => pSQL($attributes->wholesale_price), 'price' => pSQL($attributes->price), 'weight' => pSQL($attributes->weight), 'default_on' => (int) $attributes->default_on));
                    Db::getInstance()->insert('stock_available', array('id_product' => (int) $idP, 'id_product_attribute' => (int) $idPA, 'id_shop' => (int) $attributes->id_shop, 'id_shop_group' => (int) Shop::getGroupFromShop($attributes->id_shop), 'quantity' => 0));
                }
                $attribute = '';
                foreach ($attributes->id_attribute as $attribute) {
                    Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'product_attribute_combination` (`id_attribute`,`id_product_attribute`) VALUES (' . (int) $attribute->id_attribute . ',' . (int) $idPA . ')');
                }
                if (version_compare(_PS_VERSION_, '1.5', '>=')) {
                    if (!isset($pdt->id_product)) {
                        self::insertSupplierRef($idP, $idPA, $attributes->id_supplier, $attributes->supplier_reference);
                    }
                }
                Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'ec_ecopresto_product_attribute` (`reference`,`id_product_attribute`,`id_shop`) VALUES ("' . pSQL($attributes->supplier_reference) . '",' . (int) $idPA . ',' . (int) $attributes->id_shop . ')');
            } else {
                if (version_compare(_PS_VERSION_, '1.5', '>=')) {
                    Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'product_attribute_shop`
						SET ' . (isset($attributes->wholesale_price) ? '`wholesale_price`= "' . pSQL($attributes->wholesale_price) . '",' : '') . ' ' . (isset($attributes->price) ? '`price`= "' . pSQL($attributes->price) . '",' : '') . ' `weight`= "' . pSQL($attributes->weight) . '"
						WHERE `id_product_attribute`=' . (int) $idPA . ' AND `id_shop` = ' . (int) $attributes->id_shop);
                }
                Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'product_attribute`
					SET ' . (isset($attributes->wholesale_price) ? '`wholesale_price`= "' . pSQL($attributes->wholesale_price) . '",' : '') . ' ' . (isset($attributes->price) ? '`price`= "' . pSQL($attributes->price) . '",' : '') . ' `weight`= "' . pSQL($attributes->weight) . '"
					WHERE `id_product_attribute`=' . (int) $idPA);
            }
        }
    }
Exemplo n.º 15
0
    public function customGetNestedCategories($shop_id, $root_category = null, $id_lang = false, $active = true, $groups = null, $use_shop_restriction = true, $sql_filter = '', $sql_sort = '', $sql_limit = '')
    {
        if (isset($root_category) && !Validate::isInt($root_category)) {
            die(Tools::displayError());
        }
        if (!Validate::isBool($active)) {
            die(Tools::displayError());
        }
        if (isset($groups) && Group::isFeatureActive() && !is_array($groups)) {
            $groups = (array) $groups;
        }
        $cache_id = 'Category::getNestedCategories_' . md5((int) $shop_id . (int) $root_category . (int) $id_lang . (int) $active . (int) $active . (isset($groups) && Group::isFeatureActive() ? implode('', $groups) : ''));
        if (!Cache::isStored($cache_id)) {
            $result = Db::getInstance()->executeS('
				SELECT c.*, cl.`name` as gcat_name, g.*, gl.*, s.name as shop_name
				FROM `' . _DB_PREFIX_ . 'category` c
				INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = "' . (int) $shop_id . '")
				LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON c.`id_category` = cl.`id_category` AND cl.`id_shop` = "' . (int) $shop_id . '"
				LEFT JOIN `' . _DB_PREFIX_ . 'gshoppingflux` g ON g.`id_gcategory` = c.`id_category` AND g.`id_shop` = "' . (int) $shop_id . '"
				LEFT JOIN `' . _DB_PREFIX_ . 'gshoppingflux_lang` gl ON gl.`id_gcategory` = c.`id_category` AND gl.`id_shop` = "' . (int) $shop_id . '"
				LEFT JOIN ' . _DB_PREFIX_ . 'shop s ON s.`id_shop` = "' . (int) $shop_id . '"
				WHERE 1 ' . $sql_filter . ' ' . ($id_lang ? 'AND cl.`id_lang` = ' . (int) $id_lang . ' AND gl.`id_lang` = ' . (int) $id_lang : '') . ($active ? ' AND c.`active` = 1' : '') . (isset($groups) && Group::isFeatureActive() ? ' AND cg.`id_group` IN (' . implode(',', $groups) . ')' : '') . (!$id_lang || isset($groups) && Group::isFeatureActive() ? ' GROUP BY c.`id_category`' : '') . ($sql_sort != '' ? $sql_sort : ' ORDER BY c.`level_depth` ASC') . ($sql_sort == '' && $use_shop_restriction ? ', cs.`position` ASC' : '') . ($sql_limit != '' ? $sql_limit : ' LIMIT 1;'));
            $attributes = $this->getShopAttributes($this->context->language->id, $this->context->shop->id);
            foreach ($result as $k => $cat) {
                $result[$k]['gcategory'] = html_entity_decode($result[$k]['gcategory']);
                $gid_colors = array();
                $gid_materials = array();
                $gid_patterns = array();
                $gid_sizes = array();
                if ($result[$k]['level_depth'] > 0) {
                    $tree = " > ";
                    $str = '';
                    for ($i = 0; $i < $result[$k]['level_depth'] - 1; $i++) {
                        $str .= $tree;
                    }
                    $result[$k]['gcat_name'] = $str . ' ' . $result[$k]['gcat_name'];
                    $shop_group_id = Shop::getGroupFromShop($shop_id);
                    $result[$k]['color'] = explode(";", $result[$k]['color']);
                    foreach ($result[$k]['color'] as $a => $v) {
                        if (isset($attributes[$v - 1])) {
                            $gid_colors[] = $attributes[$v - 1]['name'];
                        }
                    }
                    $result[$k]['material'] = explode(";", $result[$k]['material']);
                    foreach ($result[$k]['material'] as $a => $v) {
                        if (isset($attributes[$v - 1])) {
                            $gid_materials[] = $attributes[$v - 1]['name'];
                        }
                    }
                    $result[$k]['pattern'] = explode(";", $result[$k]['pattern']);
                    foreach ($result[$k]['pattern'] as $a => $v) {
                        if (isset($attributes[$v - 1])) {
                            $gid_patterns[] = $attributes[$v - 1]['name'];
                        }
                    }
                    $result[$k]['size'] = explode(";", $result[$k]['size']);
                    foreach ($result[$k]['size'] as $a => $v) {
                        if (isset($attributes[$v - 1])) {
                            $gid_sizes[] = $attributes[$v - 1]['name'];
                        }
                    }
                    $result[$k]['gid_colors'] = implode(" ; ", $gid_colors);
                    $result[$k]['gid_materials'] = implode(" ; ", $gid_materials);
                    $result[$k]['gid_patterns'] = implode(" ; ", $gid_patterns);
                    $result[$k]['gid_sizes'] = implode(" ; ", $gid_sizes);
                }
            }
            $categories = array();
            $buff = array();
            if (!isset($root_category)) {
                $root_category = 1;
            }
            foreach ($result as $row) {
                $current =& $buff[$row['id_category']];
                $current = $row;
                if ($row['id_category'] == $root_category) {
                    $categories[$row['id_category']] =& $current;
                } else {
                    $buff[$row['id_parent']]['children'][$row['id_category']] =& $current;
                }
            }
            Cache::store($cache_id, $categories);
        }
        return Cache::retrieve($cache_id);
    }
Exemplo n.º 16
0
 /**
  * For a given id_product and id_product_attribute sets the quantity available
  *
  * @param int $id_product
  * @param int $id_product_attribute Optional
  * @param int $delta_quantity The delta quantity to update
  * @param int $id_shop Optional
  */
 public static function setQuantity($id_product, $id_product_attribute, $quantity, $id_shop = null)
 {
     if (!Validate::isUnsignedId($id_product)) {
         return false;
     }
     $context = Context::getContext();
     // if there is no $id_shop, gets the context one
     if ($id_shop === null && Shop::getContext() != Shop::CONTEXT_GROUP) {
         $id_shop = (int) $context->shop->id;
     }
     $depends_on_stock = StockAvailable::dependsOnStock($id_product);
     //Try to set available quantity if product does not depend on physical stock
     if (!$depends_on_stock) {
         $id_stock_available = (int) StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);
         if ($id_stock_available) {
             $stock_available = new StockAvailable($id_stock_available);
             $stock_available->quantity = (int) $quantity;
             $stock_available->update();
         } else {
             $out_of_stock = StockAvailable::outOfStock($id_product, $id_shop);
             $stock_available = new StockAvailable();
             $stock_available->out_of_stock = (int) $out_of_stock;
             $stock_available->id_product = (int) $id_product;
             $stock_available->id_product_attribute = (int) $id_product_attribute;
             $stock_available->quantity = (int) $quantity;
             $shop_group = new ShopGroup((int) Shop::getContextShopGroupID());
             // if quantities are shared between shops of the group
             if ($shop_group->share_stock) {
                 $stock_available->id_shop = 0;
                 $stock_available->id_shop_group = (int) $shop_group->id;
             } else {
                 $stock_available->id_shop = $id_shop;
                 $stock_available->id_shop_group = Shop::getGroupFromShop($id_shop);
             }
             $stock_available->add();
         }
         Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $stock_available->quantity));
     }
 }
Exemplo n.º 17
0
 /**
  * Add an sql restriction for shops fields
  *
  * @param int $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value
  * @param string $alias
  */
 public static function addSqlRestriction($share = false, $alias = null)
 {
     if ($alias) {
         $alias .= '.';
     }
     $group = Shop::getGroupFromShop(Shop::getContextShopID(), false);
     if ($share == Shop::SHARE_CUSTOMER && Shop::getContext() == Shop::CONTEXT_SHOP && $group['share_customer']) {
         $restriction = ' AND ' . $alias . 'id_shop_group = ' . (int) Shop::getContextShopGroupID();
     } else {
         $restriction = ' AND ' . $alias . 'id_shop IN (' . implode(', ', Shop::getContextListShopID($share)) . ') ';
     }
     return $restriction;
 }
Exemplo n.º 18
0
 protected function getMenuItems()
 {
     $items = Tools::getValue('items');
     if (is_array($items) && count($items)) {
         return $items;
     } else {
         $shops = Shop::getContextListShopID();
         $conf = null;
         if (count($shops) > 1) {
             foreach ($shops as $key => $shop_id) {
                 $shop_group_id = Shop::getGroupFromShop($shop_id);
                 $conf .= (string) ($key > 1 ? ',' : '') . Configuration::get('MOD_BLOCKTOPMENU_ITEMS', null, $shop_group_id, $shop_id);
             }
         } else {
             $shop_id = (int) $shops[0];
             $shop_group_id = Shop::getGroupFromShop($shop_id);
             $conf = Configuration::get('MOD_BLOCKTOPMENU_ITEMS', null, $shop_group_id, $shop_id);
         }
         if (strlen($conf)) {
             return explode(',', $conf);
         } else {
             return array();
         }
     }
 }
Exemplo n.º 19
0
 /**
  * Check if the employee is associated to a specific shop group
  *
  * @since 1.5.0
  * @param int $id_shop_shop
  * @return bool
  */
 public function hasAuthOnShopGroup($id_shop_group)
 {
     if ($this->isSuperAdmin()) {
         return true;
     }
     foreach ($this->associated_shops as $id_shop) {
         if ($id_shop_group == Shop::getGroupFromShop($id_shop, true)) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 20
0
 private function getMenuItems()
 {
     $items = Tools::getValue('items');
     if (is_array($items) && count($items)) {
         return $items;
     } else {
         $shops = Shop::getContextListShopID();
         $conf = null;
         if (count($shops) > 1) {
             foreach ($shops as $key => $shop_id) {
                 $shop_group_id = Shop::getGroupFromShop($shop_id);
                 $conf .= (string) ($key > 1 ? ',' : '') . Configuration::get($this->config_name . '_mobile_menu', null, $shop_group_id, $shop_id);
             }
         } else {
             $shop_id = (int) $shops[0];
             $shop_group_id = Shop::getGroupFromShop($shop_id);
             $conf = Configuration::get($this->config_name . '_mobile_menu', null, $shop_group_id, $shop_id);
         }
         if (strlen($conf)) {
             return explode(',', $conf);
         } else {
             return array();
         }
     }
 }