Exemplo n.º 1
0
    public function install()
    {
        if (!parent::install() || !$this->registerHook('displayHeader') || !$this->registerHook('displayAdditionalFooter')) {
            return false;
        }
        $res = Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'footercontent` (
			`id_content` int(10) unsigned NOT NULL auto_increment,
			`id_shop` int(10) unsigned NOT NULL,
			`width` int(10) unsigned NOT NULL,
			PRIMARY KEY (`id_content`))
			ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8');
        if ($res) {
            $res &= Db::getInstance()->execute('CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'footercontent_lang` (
				`id_content` int(10) unsigned NOT NULL,
				`id_lang` int(10) unsigned NOT NULL,
				`body_title` varchar(255) NOT NULL,
				`body_paragraph` text NOT NULL,
				PRIMARY KEY (`id_content`, `id_lang`))
				ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8');
        }
        if ($res) {
            foreach (Shop::getShops(false) as $shop) {
                $res &= $this->createExampleContent($shop['id_shop']);
            }
        }
        if (!$res) {
            $res &= $this->uninstall();
        }
        return (bool) $res;
    }
 /**
  * Get view 
  *
  * @return string
  */
 public function initContent()
 {
     $options_time = array();
     $time_slice = Configuration::get('APH_CALENDAR_TIME_SLICE');
     for ($hours = 0; $hours < 24; $hours++) {
         // the interval for hours is '1'
         for ($mins = 0; $mins < 60; $mins += $time_slice) {
             // the interval for mins is 'APH_CALENDAR_TIME_SLICE'
             $options_time[str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT)] = str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT);
         }
     }
     $this->context->smarty->assign('options_time', $options_time);
     if ($this->display == 'edit') {
         $obj = $this->loadObject(true);
         $obj->from_time = substr($obj->from, 11, 5);
         $obj->from = substr($obj->from, 0, 10);
         $obj->to_time = substr($obj->to, 11, 5);
         $obj->to = substr($obj->to, 0, 10);
         $this->context->smarty->assign(array('obj' => $obj));
     } elseif ($this->display == 'add') {
         $this->context->smarty->assign(array('obj' => NULL));
     }
     if ($this->display == 'add' || $this->display == 'edit') {
         $shops = Shop::getShops(true, null, false);
         $languages = Language::getLanguages(true);
         self::fetchEmployees();
         $this->context->smarty->assign(array("id_lang_default" => Configuration::get('PS_LANG_DEFAULT'), 'tpl_dir' => $this->tpl_dir, "languages" => $languages, "shops" => $shops));
         $this->content .= $this->context->smarty->fetch(_PS_MODULE_DIR_ . $this->module->name . "/views/templates/admin/controllers/availabilities/form.tpl");
     }
     parent::initContent();
 }
 public function renderForm()
 {
     if (!$this->object->id) {
         $this->object->price = -1;
     }
     $this->fields_form = array('legend' => array('title' => $this->trans('Catalog price rules', array(), 'Admin.Catalog.Feature'), 'icon' => 'icon-dollar'), 'input' => array(array('type' => 'text', 'label' => $this->trans('Name', array(), 'Admin.Global'), 'name' => 'name', 'maxlength' => 255, 'required' => true), array('type' => 'select', 'label' => $this->trans('Shop', array(), 'Admin.Global'), 'name' => 'shop_id', 'options' => array('query' => Shop::getShops(), 'id' => 'id_shop', 'name' => 'name'), 'condition' => Shop::isFeatureActive(), 'default_value' => Shop::getContextShopID()), array('type' => 'select', 'label' => $this->trans('Currency', array(), 'Admin.Global'), 'name' => 'id_currency', 'options' => array('query' => array_merge(array(0 => array('id_currency' => 0, 'name' => $this->trans('All currencies', array(), 'Admin.Global'))), Currency::getCurrencies(false, true, true)), 'id' => 'id_currency', 'name' => 'name')), array('type' => 'select', 'label' => $this->trans('Country', array(), 'Admin.Global'), 'name' => 'id_country', 'options' => array('query' => array_merge(array(0 => array('id_country' => 0, 'name' => $this->trans('All countries', array(), 'Admin.Global'))), Country::getCountries((int) $this->context->language->id)), 'id' => 'id_country', 'name' => 'name')), array('type' => 'select', 'label' => $this->trans('Group', array(), 'Admin.Global'), 'name' => 'id_group', 'options' => array('query' => array_merge(array(0 => array('id_group' => 0, 'name' => $this->trans('All groups', array(), 'Admin.Global'))), Group::getGroups((int) $this->context->language->id)), 'id' => 'id_group', 'name' => 'name')), array('type' => 'text', 'label' => $this->trans('From quantity', array(), 'Admin.Catalog.Feature'), 'name' => 'from_quantity', 'maxlength' => 10, 'required' => true), array('type' => 'text', 'label' => $this->trans('Price (tax excl.)', array(), 'Admin.Catalog.Feature'), 'name' => 'price', 'disabled' => $this->object->price == -1 ? 1 : 0, 'maxlength' => 10, 'suffix' => $this->context->currency->getSign('right')), array('type' => 'checkbox', 'name' => 'leave_bprice', 'values' => array('query' => array(array('id' => 'on', 'name' => $this->trans('Leave initial price', array(), 'Admin.Catalog.Feature'), 'val' => '1', 'checked' => '1')), 'id' => 'id', 'name' => 'name')), array('type' => 'datetime', 'label' => $this->trans('From', array(), 'Admin.Global'), 'name' => 'from'), array('type' => 'datetime', 'label' => $this->trans('To', array(), 'Admin.Global'), 'name' => 'to'), array('type' => 'select', 'label' => $this->trans('Reduction type', array(), 'Admin.Catalog.Feature'), 'name' => 'reduction_type', 'options' => array('query' => array(array('reduction_type' => 'amount', 'name' => $this->trans('Amount', array(), 'Admin.Global')), array('reduction_type' => 'percentage', 'name' => $this->trans('Percentage', array(), 'Admin.Global'))), 'id' => 'reduction_type', 'name' => 'name')), array('type' => 'select', 'label' => $this->trans('Reduction with or without taxes', array(), 'Admin.Catalog.Feature'), 'name' => 'reduction_tax', 'align' => 'center', 'options' => array('query' => array(array('lab' => $this->trans('Tax included', array(), 'Admin.Global'), 'val' => 1), array('lab' => $this->trans('Tax excluded', array(), 'Admin.Global'), 'val' => 0)), 'id' => 'val', 'name' => 'lab')), array('type' => 'text', 'label' => $this->trans('Reduction', array(), 'Admin.Catalog.Feature'), 'name' => 'reduction', 'required' => true)), 'submit' => array('title' => $this->trans('Save', array(), 'Admin.Actions')));
     if (($value = $this->getFieldValue($this->object, 'price')) != -1) {
         $price = number_format($value, 6);
     } else {
         $price = '';
     }
     $this->fields_value = array('price' => $price, 'from_quantity' => ($value = $this->getFieldValue($this->object, 'from_quantity')) ? $value : 1, 'reduction' => number_format(($value = $this->getFieldValue($this->object, 'reduction')) ? $value : 0, 6), 'leave_bprice_on' => $price ? 0 : 1, 'shop_id' => ($value = $this->getFieldValue($this->object, 'id_shop')) ? $value : 1);
     $attribute_groups = array();
     $attributes = Attribute::getAttributes((int) $this->context->language->id);
     foreach ($attributes as $attribute) {
         if (!isset($attribute_groups[$attribute['id_attribute_group']])) {
             $attribute_groups[$attribute['id_attribute_group']] = array('id_attribute_group' => $attribute['id_attribute_group'], 'name' => $attribute['attribute_group']);
         }
         $attribute_groups[$attribute['id_attribute_group']]['attributes'][] = array('id_attribute' => $attribute['id_attribute'], 'name' => $attribute['name']);
     }
     $features = Feature::getFeatures((int) $this->context->language->id);
     foreach ($features as &$feature) {
         $feature['values'] = FeatureValue::getFeatureValuesWithLang((int) $this->context->language->id, $feature['id_feature'], true);
     }
     $this->tpl_form_vars = array('manufacturers' => Manufacturer::getManufacturers(), 'suppliers' => Supplier::getSuppliers(), 'attributes_group' => $attribute_groups, 'features' => $features, 'categories' => Category::getSimpleCategories((int) $this->context->language->id), 'conditions' => $this->object->getConditions(), 'is_multishop' => Shop::isFeatureActive());
     return parent::renderForm();
 }
 public function renderForm()
 {
     if (!$this->object->id) {
         $this->object->price = -1;
     }
     $shops = Shop::getShops();
     if (count($this->context->employee->getAssociatedShops()) > 1) {
         $shops = array_merge(array(0 => array('id_shop' => 0, 'name' => $this->l('All shops'))), $shops);
     }
     $this->fields_form = array('legend' => array('title' => $this->l('Specific price rules')), 'input' => array(array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 33, 'maxlength' => 32, 'required' => true, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}'), array('type' => 'select', 'label' => $this->l('Shop:'), 'name' => 'id_shop', 'options' => array('query' => $shops, 'id' => 'id_shop', 'name' => 'name'), 'condition' => Shop::isFeatureActive(), 'default_value' => Shop::getContextShopID()), array('type' => 'select', 'label' => $this->l('Currency:'), 'name' => 'id_currency', 'options' => array('query' => array_merge(array(0 => array('id_currency' => 0, 'name' => $this->l('All currencies'))), Currency::getCurrencies()), 'id' => 'id_currency', 'name' => 'name')), array('type' => 'select', 'label' => $this->l('Country:'), 'name' => 'id_country', 'options' => array('query' => array_merge(array(0 => array('id_country' => 0, 'name' => $this->l('All countries'))), Country::getCountries((int) $this->context->language->id)), 'id' => 'id_country', 'name' => 'name')), array('type' => 'select', 'label' => $this->l('Group:'), 'name' => 'id_group', 'options' => array('query' => array_merge(array(0 => array('id_group' => 0, 'name' => $this->l('All groups'))), Group::getGroups((int) $this->context->language->id)), 'id' => 'id_group', 'name' => 'name')), array('type' => 'text', 'label' => $this->l('From quantity:'), 'name' => 'from_quantity', 'size' => 6, 'maxlength' => 10, 'required' => true), array('type' => 'text', 'label' => $this->l('Price (tax excl.):'), 'name' => 'price', 'size' => 6, 'disabled' => $this->object->price == -1 ? 1 : 0, 'maxlength' => 10, 'suffix' => $this->context->currency->getSign('right')), array('type' => 'checkbox', 'name' => 'leave_bprice', 'values' => array('query' => array(array('id' => 'on', 'name' => $this->l('Leave base price'), 'val' => '1', 'checked' => '1')), 'id' => 'id', 'name' => 'name')), array('type' => 'date', 'label' => $this->l('From:'), 'name' => 'from', 'size' => 12), array('type' => 'date', 'label' => $this->l('To:'), 'name' => 'to', 'size' => 12), array('type' => 'select', 'label' => $this->l('Reduction type:'), 'name' => 'reduction_type', 'options' => array('query' => array(array('reduction_type' => 'amount', 'name' => $this->l('Amount')), array('reduction_type' => 'percentage', 'name' => $this->l('Percentage'))), 'id' => 'reduction_type', 'name' => 'name')), array('type' => 'text', 'label' => $this->l('Reduction:'), 'name' => 'reduction', 'required' => true)), 'submit' => array('title' => $this->l('Save'), 'class' => 'button'));
     if (($value = $this->getFieldValue($this->object, 'price')) != -1) {
         $price = number_format($value, 2);
     } else {
         $price = '';
     }
     $this->fields_value = array('price' => $price, 'from_quantity' => ($value = $this->getFieldValue($this->object, 'from_quantity')) ? $value : 1, 'reduction' => number_format(($value = $this->getFieldValue($this->object, 'reduction')) ? $value : 0, 2), 'leave_bprice_on' => $price ? 0 : 1);
     $attribute_groups = array();
     $attributes = Attribute::getAttributes((int) $this->context->language->id);
     foreach ($attributes as $attribute) {
         if (!isset($attribute_groups[$attribute['id_attribute_group']])) {
             $attribute_groups[$attribute['id_attribute_group']] = array('id_attribute_group' => $attribute['id_attribute_group'], 'name' => $attribute['attribute_group']);
         }
         $attribute_groups[$attribute['id_attribute_group']]['attributes'][] = array('id_attribute' => $attribute['id_attribute'], 'name' => $attribute['name']);
     }
     $features = Feature::getFeatures((int) $this->context->language->id);
     foreach ($features as &$feature) {
         $feature['values'] = FeatureValue::getFeatureValuesWithLang((int) $this->context->language->id, $feature['id_feature'], true);
     }
     $this->tpl_form_vars = array('manufacturers' => Manufacturer::getManufacturers(), 'suppliers' => Supplier::getSuppliers(), 'attributes_group' => $attribute_groups, 'features' => $features, 'categories' => Category::getSimpleCategories((int) $this->context->language->id), 'conditions' => $this->object->getConditions(), 'is_multishop' => Shop::isFeatureActive());
     return parent::renderForm();
 }
Exemplo n.º 5
0
 public function install()
 {
     if (!parent::install() || !$this->registerHook('leftColumn') || !$this->registerHook('rightColumn') || !$this->registerHook('header') || !$this->registerHook('footer') || !$this->registerHook('actionObjectCmsUpdateAfter') || !$this->registerHook('actionObjectCmsDeleteAfter') || !$this->registerHook('actionShopDataDuplication') || !$this->registerHook('actionAdminStoresControllerUpdate_optionsAfter') || !BlockCMSModel::createTables() || !Configuration::updateValue('FOOTER_CMS', '') || !Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', 1) || !Configuration::updateValue('FOOTER_POWEREDBY', 1) || !Configuration::updateValue('FOOTER_PRICE-DROP', 1) || !Configuration::updateValue('FOOTER_NEW-PRODUCTS', 1) || !Configuration::updateValue('FOOTER_BEST-SALES', 1) || !Configuration::updateValue('FOOTER_CONTACT', 1) || !Configuration::updateValue('FOOTER_SITEMAP', 1)) {
         return false;
     }
     $this->_clearCache('blockcms.tpl');
     // Install fixtures for blockcms
     $default = Db::getInstance()->insert('cms_block', array('id_cms_category' => 1, 'location' => 0, 'position' => 0));
     if (!$default) {
         return false;
     }
     $result = true;
     $id_cms_block = Db::getInstance()->Insert_ID();
     $shops = Shop::getShops(true, null, true);
     foreach ($shops as $shop) {
         $result &= Db::getInstance()->insert('cms_block_shop', array('id_cms_block' => $id_cms_block, 'id_shop' => $shop));
     }
     $languages = Language::getLanguages(false);
     foreach ($languages as $lang) {
         $result &= Db::getInstance()->insert('cms_block_lang', array('id_cms_block' => $id_cms_block, 'id_lang' => $lang['id_lang'], 'name' => $this->l('Information')));
     }
     $pages = CMS::getCMSPages(null, 1);
     foreach ($pages as $cms) {
         $result &= Db::getInstance()->insert('cms_block_page', array('id_cms_block' => $id_cms_block, 'id_cms' => $cms['id_cms'], 'is_category' => 0));
     }
     return $result;
 }
Exemplo n.º 6
0
 public function install()
 {
     if (!parent::install() || !$this->registerHooks() || !BlockCMSModel::createTables() || !Configuration::updateValue('FOOTER_CMS', '') || !Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', 1) || !Configuration::updateValue('FOOTER_POWEREDBY', 1)) {
         return false;
     }
     // Install fixtures for blockcms
     $default = Db::getInstance()->insert('cms_block', array('id_cms_category' => 1, 'location' => 0, 'position' => 0));
     if (!$default) {
         return false;
     }
     $result = true;
     $id_cms_block = Db::getInstance()->Insert_ID();
     $shops = Shop::getShops(true, null, true);
     foreach ($shops as $shop) {
         $result &= Db::getInstance()->insert('cms_block_shop', array('id_cms_block' => $id_cms_block, 'id_shop' => $shop));
     }
     $languages = Language::getLanguages(false);
     foreach ($languages as $lang) {
         $result &= Db::getInstance()->insert('cms_block_lang', array('id_cms_block' => $id_cms_block, 'id_lang' => $lang['id_lang'], 'name' => $this->l('Information')));
     }
     $pages = CMS::getCMSPages(null, 1);
     foreach ($pages as $cms) {
         $result &= Db::getInstance()->insert('cms_block_page', array('id_cms_block' => $id_cms_block, 'id_cms' => $cms['id_cms'], 'is_category' => 0));
     }
     return $result;
 }
Exemplo n.º 7
0
    public function install()
    {
        if (!parent::install() || !$this->registerHook('displayNav') || !$this->registerHook('freeFblock') || !$this->registerHook('displayHeader')) {
            return false;
        }
        $res = Db::getInstance()->execute('
			CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'slidetopcontent` (
				`id_slidetopcontent` int(10) unsigned NOT NULL auto_increment,
				`id_shop` int(10) unsigned NOT NULL ,
				PRIMARY KEY (`id_slidetopcontent`))
		ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8');
        if ($res) {
            $res &= Db::getInstance()->execute('
				CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'slidetopcontent_lang` (
					`id_slidetopcontent` int(10) unsigned NOT NULL,
					`id_lang` int(10) unsigned NOT NULL,
					`main_title` varchar(255) NOT NULL,
					`main_paragraph` text NOT NULL,
					`main_link` varchar(255) NOT NULL,
					`second_title` varchar(255) NOT NULL,
					`second_paragraph` text NOT NULL,
					`second_link` varchar(255) NOT NULL,
					PRIMARY KEY (`id_slidetopcontent`, `id_lang`))
		ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8');
        }
        if ($res) {
            foreach (Shop::getShops(false) as $shop) {
                $res &= $this->createExample($shop['id_shop']);
            }
        }
        if (!$res) {
            $res &= $this->uninstall();
        }
        return $res;
    }
Exemplo n.º 8
0
 public static function list_shops()
 {
     $shops = Shop::getShops(false);
     $table = new Cli\Table();
     $table->setHeaders(array('id', 'group', 'name', 'theme', 'category', 'domain', 'domain_ssl', 'uri', 'active'));
     foreach ($shops as $shop) {
         $theme = new Theme($shop['id_theme']);
         if (Validate::isLoadedObject($theme)) {
             $themeName = $theme->name;
         } else {
             $themeName = $shop['id_theme'];
         }
         unset($theme);
         $group = new ShopGroup($shop['id_shop_group']);
         if (Validate::isLoadedObject($group)) {
             $groupName = $group->name;
         } else {
             $groupName = $shop['id_shop_group'];
         }
         unset($group);
         $category = new Category($shop['id_category']);
         if (Validate::isLoadedObject($category)) {
             $categoryName = array_pop($category->name);
         } else {
             $categoryName = $shop['id_category'];
         }
         unset($category);
         $table->addRow(array($shop['id_shop'], $groupName, $shop['name'], $themeName, $categoryName, $shop['domain'], $shop['domain_ssl'], $shop['uri'], $shop['active']));
     }
     $table->display();
 }
Exemplo n.º 9
0
 public function renderForm()
 {
     $update_htaccess = Tools::modRewriteActive() && (file_exists('.htaccess') && is_writable('.htaccess') || is_writable(dirname('.htaccess')));
     $this->multiple_fieldsets = true;
     if (!$update_htaccess) {
         $desc_virtual_uri = array('<span class="warning_mod_rewrite">' . $this->l('You need to activate URL Rewriting if you want to add a virtual URL.') . '</span>');
     } else {
         $desc_virtual_uri = array($this->l('You can use this option if you want to create a store with a URL that doesn\'t exist on your server (e.g. if you want your store to be available with the URL www.my-prestashop.com/my-store/shoes/, you have to set shoes/ in this field, assuming that my-store/ is your Physical URL).'), '<strong>' . $this->l('URL rewriting must be activated on your server to use this feature.') . '</strong>');
     }
     $this->fields_form = array(array('form' => array('legend' => array('title' => $this->l('URL options'), 'icon' => 'icon-cogs'), 'input' => array(array('type' => 'select', 'label' => $this->l('Shop'), 'name' => 'id_shop', 'onchange' => 'checkMainUrlInfo(this.value);', 'options' => array('optiongroup' => array('query' => Shop::getTree(), 'label' => 'name'), 'options' => array('query' => 'shops', 'id' => 'id_shop', 'name' => 'name'))), array('type' => 'switch', 'label' => $this->l('Main URL'), 'name' => 'main', 'class' => 't', 'values' => array(array('id' => 'main_on', 'value' => 1), array('id' => 'main_off', 'value' => 0)), 'desc' => array($this->l('If you set this URL as the Main URL for the selected shop, all URLs set to this shop will be redirected to this URL (you can only have one Main URL per shop).'), array('text' => $this->l('Since the selected shop has no main URL, you have to set this URL as the Main URL.'), 'id' => 'mainUrlInfo'), array('text' => $this->l('The selected shop already has a Main URL. Therefore, if you set this one as the Main URL, the older of the two will be set as the normal URL.'), 'id' => 'mainUrlInfoExplain'))), array('type' => 'switch', 'label' => $this->l('Enabled'), 'name' => 'active', 'required' => false, 'class' => 't', 'values' => array(array('id' => 'active_on', 'value' => 1), array('id' => 'active_off', 'value' => 0)))), 'submit' => array('title' => $this->l('Save')))), array('form' => array('legend' => array('title' => $this->l('Shop URL'), 'icon' => 'icon-shopping-cart'), 'input' => array(array('type' => 'text', 'label' => $this->l('Domain'), 'name' => 'domain', 'size' => 50), array('type' => 'text', 'label' => $this->l('Domain SSL'), 'name' => 'domain_ssl', 'size' => 50)), 'submit' => array('title' => $this->l('Save')))));
     if (!defined('_PS_HOST_MODE_')) {
         $this->fields_form[1]['form']['input'] = array_merge($this->fields_form[1]['form']['input'], array(array('type' => 'text', 'label' => $this->l('Physical URL'), 'name' => 'physical_uri', 'desc' => $this->l('This is the physical folder for your store on the server. Leave this field empty if your store is installed on the root path (e.g. if your store is available at www.my-prestashop.com/my-store/, you input my-store/ in this field).'), 'size' => 50)));
     }
     $this->fields_form[1]['form']['input'] = array_merge($this->fields_form[1]['form']['input'], array(array('type' => 'text', 'label' => $this->l('Virtual URL'), 'name' => 'virtual_uri', 'desc' => $desc_virtual_uri, 'size' => 50, 'hint' => !$update_htaccess ? $this->l('Warning: URL rewriting (e.g. mod_rewrite for Apache) seems to be disabled. If your URL doesn\'t work, please check with your host provider on how to activate URL rewriting.') : null), array('type' => 'text', 'label' => $this->l('Your final URL will be'), 'name' => 'final_url', 'size' => 76, 'readonly' => true)));
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     self::$currentIndex = self::$currentIndex . '&id_shop=' . $obj->id;
     $current_shop = Shop::initialize();
     $list_shop_with_url = array();
     foreach (Shop::getShops(false, null, true) as $id) {
         $list_shop_with_url[$id] = (bool) count(ShopUrl::getShopUrls($id));
     }
     $this->tpl_form_vars = array('js_shop_url' => Tools::jsonEncode($list_shop_with_url));
     $this->fields_value = array('domain' => Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'domain') : $current_shop->domain, 'domain_ssl' => Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'domain_ssl') : $current_shop->domain_ssl, 'physical_uri' => Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'physical_uri') : $current_shop->physical_uri, 'active' => true);
     return parent::renderForm();
 }
Exemplo n.º 10
0
 /**
  * Updates product image in Prestashop.
  * 
  * @param integer $id_product, integer $id_img, string $url, string $name_photo
  * @return integer 
  * @see $this->copyImg
  *
  */
 public function updateImageInPrestashop($id_product, $id_img, $url, $name_photo)
 {
     if (empty($id_img)) {
         return (int) $this->insertImageInPrestashop($id_product, $url, $name_photo);
     } else {
         $shops = Shop::getShops(true, null, true);
         $image = new ImageCore((int) $id_img);
         $image->id_product = $id_product;
         $tmp = explode(".", $name_photo);
         $name_photo_product = "";
         $name_for_legend = "";
         if (count($tmp) == 1) {
             $name_photo_product = trim($url) . $name_photo . ".jpg";
             $name_for_legend = $name_photo . ".jpg";
         } else {
             $name_photo_product = trim($url) . $name_photo;
             $name_for_legend = $name_photo;
         }
         $image->legend = array('1' => trim($name_for_legend));
         if ($image->validateFields(false, true) === true && $image->validateFieldsLang(false, true) === true && $image->update()) {
             $image->associateTo($shops);
             if (!$this->copyImg($id_product, $id_img, $name_photo_product, 'products')) {
                 $image->delete();
             }
         }
         return (int) $image->id;
     }
 }
Exemplo n.º 11
0
    public function install()
    {
        if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('displayHeader')) {
            return false;
        }
        $res = Db::getInstance()->execute('
			CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'editorial` (
			`id_editorial` int(10) unsigned NOT NULL auto_increment,
			`id_shop` int(10) unsigned NOT NULL ,
			`body_home_logo_link` varchar(255) NOT NULL,
			PRIMARY KEY (`id_editorial`))
			ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8');
        if ($res) {
            $res &= Db::getInstance()->execute('
				CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'editorial_lang` (
				`id_editorial` int(10) unsigned NOT NULL,
				`id_lang` int(10) unsigned NOT NULL,
				`body_title` varchar(255) NOT NULL,
				`body_subheading` varchar(255) NOT NULL,
				`body_paragraph` text NOT NULL,
				`body_logo_subheading` varchar(255) NOT NULL,
				PRIMARY KEY (`id_editorial`, `id_lang`))
				ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8');
        }
        if ($res) {
            foreach (Shop::getShops(false) as $shop) {
                $res &= $this->createExampleEditorial($shop['id_shop']);
            }
        }
        if (!$res) {
            $res &= $this->uninstall();
        }
        return $res;
    }
Exemplo n.º 12
0
 /**
  * Get all site information - both Jirafe specific and general
  * @return array $sites An array of site information as per Jirafe API spec
  */
 public function getSites()
 {
     $sites = array();
     // First, get the general site info from the Prestashop database
     Shop::cacheShops(true);
     // we must refresh cache to get last insertion
     $psShops = Shop::getShops();
     // Get the Jirafe specific information about Prestashop sites
     $jsites = unserialize(base64_decode($this->get('sites')));
     if (!empty($psShops)) {
         foreach ($psShops as $psShop) {
             if ($psShop['active']) {
                 $shopId = $psShop['id_shop'];
                 $site = array();
                 $site['external_id'] = $shopId;
                 $site['description'] = $psShop['name'];
                 $site['url'] = 'http://' . $psShop['domain'] . $psShop['uri'];
                 $site['timezone'] = Configuration::get('PS_TIMEZONE');
                 $site['currency'] = $this->_getCurrency($shopId);
                 if (!empty($jsites[$shopId])) {
                     $site += $jsites[$shopId];
                 }
                 // new sites in prestashop are created without url
                 // api require a valid unique url
                 if ($site['url'] === 'http://') {
                     $site['url'] = 'http://example.' . md5(time() + $site['external_id']) . '.com';
                 }
                 // Add the site to the list of sites to return
                 $sites[] = $site;
             }
         }
     }
     return $sites;
 }
Exemplo n.º 13
0
 public function uninstall()
 {
     $shops = Shop::getShops(false);
     foreach ($shops as $shop) {
         $file = dirname(__FILE__) . '/img/' . $shop['id_shop'] . scrolltop::USER_IMG;
         if (file_exists($file)) {
             unlink($file);
         }
     }
     return parent::uninstall() and $this->unregisterHook('footer');
 }
Exemplo n.º 14
0
 public function init()
 {
     parent::init();
     // context->shop is set in the init() function, so we move the _category instanciation after that
     if (($id_category = Tools::getvalue('id_category')) && $this->action != 'select_delete') {
         $this->_category = new Category($id_category);
     } else {
         if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) {
             $this->_category = new Category($this->context->shop->id_category);
         } elseif (count(Category::getCategoriesWithoutParent()) > 1 && Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) != 1) {
             $this->_category = Category::getTopCategory();
         } else {
             $this->_category = new Category(Configuration::get('PS_HOME_CATEGORY'));
         }
     }
     $count_categories_without_parent = count(Category::getCategoriesWithoutParent());
     $top_category = Category::getTopCategory();
     if (Tools::isSubmit('id_category')) {
         $id_parent = $this->_category->id;
     } elseif (!Shop::isFeatureActive() && $count_categories_without_parent > 1) {
         $id_parent = $top_category->id;
     } elseif (Shop::isFeatureActive() && $count_categories_without_parent == 1) {
         $id_parent = Configuration::get('PS_HOME_CATEGORY');
     } elseif (Shop::isFeatureActive() && $count_categories_without_parent > 1 && Shop::getContext() != Shop::CONTEXT_SHOP) {
         if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) == 1) {
             $id_parent = $this->context->shop->id_category;
         } else {
             $id_parent = $top_category->id;
         }
     } else {
         $id_parent = $this->context->shop->id_category;
     }
     $this->_select = 'sa.position position';
     $this->_filter .= ' AND `id_parent` = ' . (int) $id_parent . ' ';
     if (Shop::getContext() == Shop::CONTEXT_SHOP) {
         $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` sa ON (a.`id_category` = sa.`id_category` AND sa.id_shop = ' . (int) $this->context->shop->id . ') ';
     } else {
         $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` sa ON (a.`id_category` = sa.`id_category` AND sa.id_shop = a.id_shop_default) ';
     }
     // we add restriction for shop
     if (Shop::getContext() == Shop::CONTEXT_SHOP && Shop::isFeatureActive()) {
         $this->_where = ' AND sa.`id_shop` = ' . (int) Context::getContext()->shop->id;
     }
     // if we are not in a shop context, we remove the position column
     if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
         unset($this->fields_list['position']);
     }
     // shop restriction : if category is not available for current shop, we redirect to the list from default category
     if (!$this->_category->isAssociatedToShop() && Shop::getContext() == Shop::CONTEXT_SHOP) {
         $this->redirect_after = self::$currentIndex . '&id_category=' . (int) $this->context->shop->getCategory() . '&token=' . $this->token;
         $this->redirect();
     }
 }
Exemplo n.º 15
0
    /**
     * Add radio currency restrictions for a new module
     * @param array $shops
     *
     * @return bool
     */
    public function addRadioCurrencyRestrictionsForModule(array $shops = array())
    {
        if (!$shops) {
            $shops = Shop::getShops(true, null, true);
        }
        foreach ($shops as $s) {
            if (!Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'module_currency` (`id_module`, `id_shop`, `id_currency`)
				VALUES (' . (int) $this->id . ', "' . (int) $s . '", -2)')) {
                return false;
            }
        }
        return true;
    }
Exemplo n.º 16
0
 public static function print_shop_list()
 {
     //function getShops($active = true, $id_shop_group = null, $get_as_list_id = false)
     $shopList = Shop::getShops();
     print_r($shopList);
     $defaultShop = Configuration::get('PS_SHOP_DEFAULT');
     foreach ($shopList as $shop) {
         echo $shop['id_shop'] . ' ' . $shop['id_shop_group'] . ' ' . $shop['name'] . ' ' . $shop['id_theme'] . ' ' . $shop['id_category'] . ' ' . $shop['domain'] . ' ' . $shop['domain_ssl'] . ' ' . $shop['uri'] . ' ' . $shop['active'];
         if ($shop['id_shop'] == $defaultShop) {
             echo " [Default Shop]";
         }
         echo "\n";
     }
 }
Exemplo n.º 17
0
    /**
     * Get Each parent category of this category until the root category
     *
     * @param integer $id_lang Language ID
     * @return array Corresponding categories
     */
    public function _getParentsCategories($id_current = NULL)
    {
        $context = Context::getContext()->cloneContext();
        $context->shop = clone $context->shop;
        $id_lang = $context->language->id;
        $categories = null;
        if (count(Category::getCategoriesWithoutParent()) > 1 && Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) != 1) {
            $context->shop->id_category = Category::getTopCategory()->id;
        } elseif (!$context->shop->id) {
            $context->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
        }
        $id_shop = $context->shop->id;
        while (true) {
            $sql = '
			SELECT c.*, cl.*
			FROM `' . _DB_PREFIX_ . 'category` c
			LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl
				ON (c.`id_category` = cl.`id_category`
				AND `id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . ')';
            if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) {
                $sql .= '
			LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` cs
				ON (c.`id_category` = cs.`id_category` AND cs.`id_shop` = ' . (int) $id_shop . ')';
            }
            $sql .= '
			WHERE c.`id_category` = ' . (int) $id_current;
            if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) {
                $sql .= '
				AND cs.`id_shop` = ' . (int) $context->shop->id;
            }
            $root_category = Category::getRootCategory();
            if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP && (!Tools::isSubmit('id_category') || (int) Tools::getValue('id_category') == (int) $root_category->id || (int) $root_category->id == (int) $context->shop->id_category)) {
                $sql .= '
					AND c.`id_parent` != 0';
            }
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
            if (isset($result[0])) {
                $categories[] = $result[0];
            } else {
                if (!$categories) {
                    $categories = array();
                }
            }
            if (!$result || $result[0]['id_category'] == $context->shop->id_category) {
                return $categories;
            }
            $id_current = $result[0]['id_parent'];
        }
    }
Exemplo n.º 18
0
 /**
  * Deletes all Nosto accounts from the system and notifies nosto that accounts are deleted.
  *
  * @return bool
  */
 public function deleteAll()
 {
     foreach (Shop::getShops() as $shop) {
         $id_shop = isset($shop['id_shop']) ? $shop['id_shop'] : null;
         foreach (Language::getLanguages(true, $id_shop) as $language) {
             $id_shop_group = isset($shop['id_shop_group']) ? $shop['id_shop_group'] : null;
             $account = $this->find($language['id_lang'], $id_shop_group, $id_shop);
             if ($account === null) {
                 continue;
             }
             $this->delete($account, $language['id_lang'], $id_shop_group, $id_shop);
         }
     }
     return true;
 }
Exemplo n.º 19
0
 protected function getMultiShopValues($key)
 {
     if (version_compare(_PS_VERSION_, '1.6.0.3', '>=') === true) {
         return Configuration::getMultiShopValues($key);
     } else {
         $shops = Shop::getShops(false, null, true);
         $id_lang = (int) $this->context->language->id;
         $results = array();
         array_push($results, Configuration::get($key));
         foreach ($shops as $id_shop) {
             array_push($results, Configuration::get($key, $id_lang, null, $id_shop));
         }
         return $results;
     }
 }
Exemplo n.º 20
0
 public function update($null_values = false)
 {
     if (Tools::isSubmit('submitAddcategoryAndBackToParent')) {
         $checked_artists_id = array();
         foreach ($_POST as $key => $val) {
             $hasString = strpos($key, 'related_artists');
             if ($hasString !== false) {
                 $checked_artists_id[] = $val;
             }
         }
         $serialize_artists = serialize($checked_artists_id);
         $this->related_artists[1] = $serialize_artists;
     }
     if ($this->id_parent == $this->id) {
         throw new PrestaShopException('a category cannot be its own parent');
     }
     if ($this->is_root_category && $this->id_parent != (int) Configuration::get('PS_ROOT_CATEGORY')) {
         $this->is_root_category = 0;
     }
     // Update group selection
     $this->updateGroup($this->groupBox);
     $this->level_depth = $this->calcLevelDepth();
     // If the parent category was changed, we don't want to have 2 categories with the same position
     $changed = $this->getDuplicatePosition();
     if ($changed) {
         if (Tools::isSubmit('checkBoxShopAsso_category')) {
             foreach (Tools::getValue('checkBoxShopAsso_category') as $id_asso_object => $row) {
                 foreach ($row as $id_shop => $value) {
                     $this->addPosition(Category::getLastPosition((int) $this->id_parent, (int) $id_shop), (int) $id_shop);
                 }
             }
         } else {
             foreach (Shop::getShops(true) as $shop) {
                 $this->addPosition(max(1, Category::getLastPosition((int) $this->id_parent, $shop['id_shop'])), $shop['id_shop']);
             }
         }
     }
     $ret = parent::update($null_values);
     if ($changed && (!isset($this->doNotRegenerateNTree) || !$this->doNotRegenerateNTree)) {
         $this->cleanPositions((int) $this->id_parent);
         Category::regenerateEntireNtree();
         $this->recalculateLevelDepth($this->id);
     }
     Hook::exec('actionCategoryUpdate', array('category' => $this));
     return $ret;
 }
Exemplo n.º 21
0
 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.º 22
0
    public static function clearCategory()
    {
        if (version_compare(_PS_VERSION_, '1.5', '<')) {
            return Db::getInstance()->execute('
				DELETE FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
				WHERE `id_shop`=' . (int) Context::getContext()->shop->id);
        }
        $shop_context = Shop::getContext();
        if ($shop_context == Shop::CONTEXT_SHOP) {
            return Db::getInstance()->execute('
				DELETE FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
				WHERE `id_shop`=' . (int) Context::getContext()->shop->id);
        } else {
            $id_shop_group = Shop::getContext() == Shop::CONTEXT_GROUP ? Shop::getContextShopGroupID() : null;
            $shop_ids = Shop::getShops(false, $id_shop_group, true);
            foreach ($shop_ids as $id_shop) {
                Db::getInstance()->execute('
					DELETE FROM `' . _DB_PREFIX_ . self::$definition['table'] . '`
					WHERE `id_shop`=' . (int) $id_shop);
            }
        }
    }
Exemplo n.º 23
0
    private function _initConfig()
    {
        //Avoid servers IPs
        Db::getInstance()->Execute('
			CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'customer_ip` (
			`id_customer_ip` int(10) unsigned NOT null AUTO_INCREMENT,
			`id_customer` int(10) unsigned NOT null,
			`ip` varchar(32) DEFAULT null,
			PRIMARY KEY (`id_customer_ip`),
			KEY `idx_id_customer` (`id_customer`)
			) ENGINE=' . _MYSQL_ENGINE_ . '  DEFAULT CHARSET=utf8;');
        if (version_compare(_PS_VERSION_, '1.5', '>') && Shop::isFeatureActive()) {
            foreach (Shop::getShops() as $shop) {
                if (!Configuration::updateValue('SHOPPING_FLUX_TOKEN', md5(rand()), false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_CANCELED', Configuration::get('PS_OS_CANCELED'), false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_SHIPPED', Configuration::get('PS_OS_SHIPPING'), false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_IMAGE', ImageType::getFormatedName('large'), false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_CARRIER', Configuration::get('PS_CARRIER_DEFAULT'), false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_TRACKING', 'checked', false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_BUYLINE', 'checked', false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_ORDERS', 'checked', false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_STATUS_SHIPPED', 'checked', false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_STATUS_CANCELED', '', false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_LOGIN', '', false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_INDEX', 'http://' . $shop['domain'] . $shop['uri'], false, null, $shop['id_shop']) || !Configuration::updateValue('SHOPPING_FLUX_STOCKS', '', false, null, $shop['id_shop'])) {
                    return false;
                }
            }
        } else {
            if (!Configuration::updateValue('SHOPPING_FLUX_TOKEN', md5(rand())) || !Configuration::updateValue('SHOPPING_FLUX_CANCELED', Configuration::get('PS_OS_CANCELED')) || !Configuration::updateValue('SHOPPING_FLUX_SHIPPED', Configuration::get('PS_OS_SHIPPING')) || !Configuration::updateValue('SHOPPING_FLUX_IMAGE', ImageType::getFormatedName('large')) || !Configuration::updateValue('SHOPPING_FLUX_CARRIER', Configuration::get('PS_CARRIER_DEFAULT')) || !Configuration::updateValue('SHOPPING_FLUX_TRACKING', 'checked') || !Configuration::updateValue('SHOPPING_FLUX_BUYLINE', 'checked') || !Configuration::updateValue('SHOPPING_FLUX_ORDERS', 'checked') || !Configuration::updateValue('SHOPPING_FLUX_STATUS_SHIPPED', 'checked') || !Configuration::updateValue('SHOPPING_FLUX_STATUS_CANCELED', '') || !Configuration::updateValue('SHOPPING_FLUX_LOGIN', '') || !Configuration::updateValue('SHOPPING_FLUX_INDEX', 'http://' . $shop['domain'] . $shop['uri']) || !Configuration::updateValue('SHOPPING_FLUX_STOCKS')) {
                return false;
            }
        }
        return true;
    }
Exemplo n.º 24
0
    protected static function getProductsToIndex($total_languages, $id_product = false, $limit = 50)
    {
        // Adjust the limit to get only "whole" products, in every languages (and at least one)
        $max_possibilities = $total_languages * count(Shop::getShops(true));
        $limit = max($max_possibilities, floor($limit / $max_possibilities) * $max_possibilities);
        return Db::getInstance()->executeS('
			SELECT p.id_product, pl.id_lang, pl.id_shop, pl.name pname, p.reference, p.ean13, p.upc,
				pl.description_short, pl.description, cl.name cname, m.name mname, l.iso_code
			FROM ' . _DB_PREFIX_ . 'product p
			LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl
				ON p.id_product = pl.id_product
			' . Shop::addSqlAssociation('product', 'p') . '
			LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl
				ON (cl.id_category = product_shop.id_category_default AND pl.id_lang = cl.id_lang AND cl.id_shop = product_shop.id_shop)
			LEFT JOIN ' . _DB_PREFIX_ . 'manufacturer m
				ON m.id_manufacturer = p.id_manufacturer
			LEFT JOIN ' . _DB_PREFIX_ . 'lang l
				ON l.id_lang = pl.id_lang
			WHERE product_shop.indexed = 0
			AND product_shop.visibility IN ("both", "search")
			' . ($id_product ? 'AND p.id_product = ' . (int) $id_product : '') . '
			LIMIT ' . (int) $limit);
    }
Exemplo n.º 25
0
 /**
  * Get a list of ID concerned by the shop context (E.g. if context is shop group, get list of children shop ID)
  *
  * @param string $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value
  * @return array
  */
 public static function getContextListShopID($share = false)
 {
     if (Shop::getContext() == Shop::CONTEXT_SHOP) {
         $list = $share ? Shop::getSharedShops(Shop::getContextShopID(), $share) : array(Shop::getContextShopID());
     } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
         $list = Shop::getShops(true, Shop::getContextShopGroupID(), true);
     } else {
         $list = Shop::getShops(true, null, true);
     }
     return $list;
 }
Exemplo n.º 26
0
    /**
     * Removes all product quantities from all a group of shops
     * If stocks are shared, remoe all old available quantities for all shops of the group
     * Else remove all available quantities for the current group
     *
     * @param ShopGroup $shop_group the ShopGroup object
     */
    public static function resetProductFromStockAvailableByShopGroup(ShopGroup $shop_group)
    {
        if ($shop_group->share_stock) {
            $shop_list = Shop::getShops(false, $shop_group->id, true);
            if (count($shop_list) > 0) {
                $id_shops_list = implode(', ', $shop_list);
                return Db::getInstance()->execute('
					DELETE FROM ' . _DB_PREFIX_ . 'stock_available
					WHERE id_shop IN (' . $id_shops_list . ')');
            }
        } else {
            return Db::getInstance()->execute('
				DELETE FROM ' . _DB_PREFIX_ . 'stock_available
				WHERE id_shop_group = ' . $shop_group->id);
        }
    }
Exemplo n.º 27
0
 /**
  * Set TaxRulesGroup
  *
  * @param  int $id_tax_rules_group    Set the TaxRulesGroup with the given ID
  *                                    as this Carrier's TaxRulesGroup
  * @param bool $all_shops             True if this should be done for all shops
  *
  * @return bool Whether the TaxRulesGroup has been succesfully set
  *              for this Carrier in this Shop or all given Shops
  */
 public function setTaxRulesGroup($id_tax_rules_group, $all_shops = false)
 {
     if (!Validate::isUnsignedId($id_tax_rules_group)) {
         die(Tools::displayError());
     }
     if (!$all_shops) {
         $shops = Shop::getContextListShopID();
     } else {
         $shops = Shop::getShops(true, null, true);
     }
     $this->deleteTaxRulesGroup($shops);
     $values = array();
     foreach ($shops as $id_shop) {
         $values[] = array('id_carrier' => (int) $this->id, 'id_tax_rules_group' => (int) $id_tax_rules_group, 'id_shop' => (int) $id_shop);
     }
     Cache::clean('carrier_id_tax_rules_group_' . (int) $this->id . '_' . (int) Context::getContext()->shop->id);
     return Db::getInstance()->insert('carrier_tax_rules_group_shop', $values);
 }
Exemplo n.º 28
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.º 29
0
 public function autoregisterhook($hook_name = 'moduleRoutes', $module_name = 'smartblog', $shop_list = null)
 {
     if (Module::isEnabled($module_name) == 1 && Module::isInstalled($module_name) == 1) {
         $return = true;
         $id_sql = 'SELECT `id_module` FROM `' . _DB_PREFIX_ . 'module` WHERE `name` = "' . $module_name . '"';
         $id_module = Db::getInstance()->getValue($id_sql);
         if (is_array($hook_name)) {
             $hook_names = $hook_name;
         } else {
             $hook_names = array($hook_name);
         }
         foreach ($hook_names as $hook_name) {
             if (!Validate::isHookName($hook_name)) {
                 throw new PrestaShopException('Invalid hook name');
             }
             if (!isset($id_module) || !is_numeric($id_module)) {
                 return false;
             }
             //$hook_name_bak = $hook_name;
             if ($alias = Hook::getRetroHookName($hook_name)) {
                 $hook_name = $alias;
             }
             $id_hook = Hook::getIdByName($hook_name);
             //$live_edit = Hook::getLiveEditById((int) Hook::getIdByName($hook_name_bak));
             if (!$id_hook) {
                 $new_hook = new Hook();
                 $new_hook->name = pSQL($hook_name);
                 $new_hook->title = pSQL($hook_name);
                 $new_hook->live_edit = (bool) preg_match('/^display/i', $new_hook->name);
                 $new_hook->position = (bool) $new_hook->live_edit;
                 $new_hook->add();
                 $id_hook = $new_hook->id;
                 if (!$id_hook) {
                     return false;
                 }
             }
             if (is_null($shop_list)) {
                 $shop_list = Shop::getShops(true, null, true);
             }
             foreach ($shop_list as $shop_id) {
                 $sql = 'SELECT hm.`id_module`
                     FROM `' . _DB_PREFIX_ . 'hook_module` hm, `' . _DB_PREFIX_ . 'hook` h
                     WHERE hm.`id_module` = ' . (int) $id_module . ' AND h.`id_hook` = ' . $id_hook . '
                     AND h.`id_hook` = hm.`id_hook` AND `id_shop` = ' . (int) $shop_id;
                 if (Db::getInstance()->getRow($sql)) {
                     continue;
                 }
                 $sql = 'SELECT MAX(`position`) AS position
                     FROM `' . _DB_PREFIX_ . 'hook_module`
                     WHERE `id_hook` = ' . (int) $id_hook . ' AND `id_shop` = ' . (int) $shop_id;
                 if (!($position = Db::getInstance()->getValue($sql))) {
                     $position = 0;
                 }
                 $return &= Db::getInstance()->insert('hook_module', array('id_module' => (int) $id_module, 'id_hook' => (int) $id_hook, 'id_shop' => (int) $shop_id, 'position' => (int) ($position + 1)));
             }
         }
         return $return;
     } else {
         return false;
     }
 }
Exemplo n.º 30
0
 /**
  * This method is used to fix shop addresses that cannot be fixed during upgrade process
  * (because uses the whole environnement of PS classes that is not available during upgrade).
  * This method should execute once on an upgraded PrestaShop to fix all OrderInvoices in one shot.
  * This method is triggered once during a (non bulk) creation of a PDF from an OrderInvoice that is not fixed yet.
  *
  * @since 1.6.1.1
  */
 public static function fixAllShopAddresses()
 {
     $shop_ids = Shop::getShops(false, null, true);
     $db = Db::getInstance();
     foreach ($shop_ids as $id_shop) {
         $address = self::getCurrentFormattedShopAddress($id_shop);
         $escaped_address = $db->escape($address, true, true);
         $db->execute('UPDATE `' . _DB_PREFIX_ . 'order_invoice` INNER JOIN `' . _DB_PREFIX_ . 'orders` USING (`id_order`)
             SET `shop_address` = \'' . $escaped_address . '\' WHERE `shop_address` IS NULL AND `id_shop` = ' . $id_shop);
     }
 }