コード例 #1
0
ファイル: OrderDetail.php プロジェクト: M03G/PrestaShop
 public static function getCrossSells($id_product, $id_lang, $limit = 12)
 {
     if (!$id_product || !$id_lang) {
         return;
     }
     $front = true;
     if (!in_array(Context::getContext()->controller->controller_type, array('front', 'modulefront'))) {
         $front = false;
     }
     $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
     SELECT o.id_order
     FROM ' . _DB_PREFIX_ . 'orders o
     LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON (od.id_order = o.id_order)
     WHERE o.valid = 1 AND od.product_id = ' . (int) $id_product);
     if (count($orders)) {
         $list = '';
         foreach ($orders as $order) {
             $list .= (int) $order['id_order'] . ',';
         }
         $list = rtrim($list, ',');
         $order_products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
             SELECT DISTINCT od.product_id, p.id_product, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price,
             cl.link_rewrite category, p.ean13, p.isbn, p.out_of_stock, p.id_category_default ' . (Combination::isFeatureActive() ? ', IFNULL(product_attribute_shop.id_product_attribute,0) id_product_attribute' : '') . '
             FROM ' . _DB_PREFIX_ . 'order_detail od
             LEFT JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product = od.product_id)
             ' . Shop::addSqlAssociation('product', 'p') . (Combination::isFeatureActive() ? 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_shop` product_attribute_shop
             ON (p.`id_product` = product_attribute_shop.`id_product` AND product_attribute_shop.`default_on` = 1 AND product_attribute_shop.id_shop=' . (int) Context::getContext()->shop->id . ')' : '') . '
             LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (pl.id_product = od.product_id' . Shop::addSqlRestrictionOnLang('pl') . ')
             LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = product_shop.id_category_default' . Shop::addSqlRestrictionOnLang('cl') . ')
             LEFT JOIN ' . _DB_PREFIX_ . 'image i ON (i.id_product = od.product_id)
             ' . Shop::addSqlAssociation('image', 'i', true, 'image_shop.cover=1') . '
             WHERE od.id_order IN (' . $list . ')
                 AND pl.id_lang = ' . (int) $id_lang . '
                 AND cl.id_lang = ' . (int) $id_lang . '
                 AND od.product_id != ' . (int) $id_product . '
                 AND product_shop.active = 1' . ($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') . '
             ORDER BY RAND()
             LIMIT ' . (int) $limit . '
         ', true, false);
         $tax_calc = Product::getTaxCalculationMethod();
         if (is_array($order_products)) {
             foreach ($order_products as &$order_product) {
                 $order_product['image'] = Context::getContext()->link->getImageLink($order_product['link_rewrite'], (int) $order_product['product_id'] . '-' . (int) $order_product['id_image'], ImageType::getFormattedName('medium'));
                 $order_product['link'] = Context::getContext()->link->getProductLink((int) $order_product['product_id'], $order_product['link_rewrite'], $order_product['category'], $order_product['ean13']);
                 if ($tax_calc == 0 || $tax_calc == 2) {
                     $order_product['displayed_price'] = Product::getPriceStatic((int) $order_product['product_id'], true, null);
                 } elseif ($tax_calc == 1) {
                     $order_product['displayed_price'] = Product::getPriceStatic((int) $order_product['product_id'], false, null);
                 }
             }
             return Product::getProductsProperties($id_lang, $order_products);
         }
     }
 }
コード例 #2
0
ファイル: Language.php プロジェクト: M03G/PrestaShop
 public static function checkAndAddLanguage($iso_code, $lang_pack = false, $only_add = false, $params_lang = null)
 {
     if (Language::getIdByIso($iso_code)) {
         return true;
     }
     // Initialize the language
     $lang = new Language();
     $lang->iso_code = Tools::strtolower($iso_code);
     $lang->language_code = $iso_code;
     // Rewritten afterwards if the language code is available
     $lang->active = true;
     // If the language pack has not been provided, retrieve it from prestashop.com
     if (!$lang_pack) {
         $lang_pack = self::getLangDetails($iso_code);
     }
     // If a language pack has been found or provided, prefill the language object with the value
     if ($lang_pack) {
         foreach ($lang_pack as $key => $value) {
             if ($key != 'iso_code' && isset(Language::$definition['fields'][$key])) {
                 $lang->{$key} = $value;
             }
         }
     }
     // Use the values given in parameters to override the data retrieved automatically
     if ($params_lang !== null && is_array($params_lang)) {
         foreach ($params_lang as $key => $value) {
             if ($key != 'iso_code' && isset(Language::$definition['fields'][$key])) {
                 $lang->{$key} = $value;
             }
         }
     }
     if (!$lang->name && $lang->iso_code) {
         $lang->name = $lang->iso_code;
     }
     if (!$lang->validateFields() || !$lang->validateFieldsLang() || !$lang->add(true, false, $only_add)) {
         return false;
     }
     if (isset($params_lang['allow_accented_chars_url']) && in_array($params_lang['allow_accented_chars_url'], array('1', 'true'))) {
         Configuration::updateGlobalValue('PS_ALLOW_ACCENTED_CHARS_URL', 1);
     }
     $flag = Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/flags/jpeg/' . $iso_code . '.jpg');
     if ($flag != null && !preg_match('/<body>/', $flag)) {
         $file = fopen(_PS_ROOT_DIR_ . '/img/l/' . (int) $lang->id . '.jpg', 'w');
         if ($file) {
             fwrite($file, $flag);
             fclose($file);
         } else {
             Language::_copyNoneFlag((int) $lang->id);
         }
     } else {
         Language::_copyNoneFlag((int) $lang->id);
     }
     $files_copy = array('/en.jpg');
     foreach (ImageType::getAll() as $alias => $config) {
         $files_copy[] = '/en-default-' . ImageType::getFormattedName($alias) . '.jpg';
     }
     foreach (array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_) as $to) {
         foreach ($files_copy as $file) {
             @copy(_PS_ROOT_DIR_ . '/img/l' . $file, $to . str_replace('/en', '/' . $iso_code, $file));
         }
     }
     return true;
 }
コード例 #3
0
 /**
  * Regenerate images
  *
  * @param $dir
  * @param $type
  * @param bool $productsImages
  * @return bool|string
  */
 protected function _regenerateNewImages($dir, $type, $productsImages = false)
 {
     if (!is_dir($dir)) {
         return false;
     }
     $generate_hight_dpi_images = (bool) Configuration::get('PS_HIGHT_DPI');
     if (!$productsImages) {
         $formated_medium = ImageType::getFormattedName('medium');
         foreach (scandir($dir) as $image) {
             if (preg_match('/^[0-9]*\\.jpg$/', $image)) {
                 foreach ($type as $k => $imageType) {
                     // Customizable writing dir
                     $newDir = $dir;
                     if (!file_exists($newDir)) {
                         continue;
                     }
                     if ($dir == _PS_CAT_IMG_DIR_ && $imageType['name'] == $formated_medium && is_file(_PS_CAT_IMG_DIR_ . str_replace('.', '_thumb.', $image))) {
                         $image = str_replace('.', '_thumb.', $image);
                     }
                     if (!file_exists($newDir . substr($image, 0, -4) . '-' . stripslashes($imageType['name']) . '.jpg')) {
                         if (!file_exists($dir . $image) || !filesize($dir . $image)) {
                             $this->errors[] = $this->trans('Source file does not exist or is empty (%filepath%)', array('%filepath%' => $dir . $image), 'Admin.Design.Notification');
                         } elseif (!ImageManager::resize($dir . $image, $newDir . substr(str_replace('_thumb.', '.', $image), 0, -4) . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) {
                             $this->errors[] = $this->trans('Failed to resize image file (%filepath%)', array('%filepath%' => $dir . $image), 'Admin.Design.Notification');
                         }
                         if ($generate_hight_dpi_images) {
                             if (!ImageManager::resize($dir . $image, $newDir . substr($image, 0, -4) . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) {
                                 $this->errors[] = $this->trans('Failed to resize image file to high resolution (%filepath%)', array('%filepath%' => $dir . $image), 'Admin.Design.Notification');
                             }
                         }
                     }
                     // stop 4 seconds before the timeout, just enough time to process the end of the page on a slow server
                     if (time() - $this->start_time > $this->max_execution_time - 4) {
                         return 'timeout';
                     }
                 }
             }
         }
     } else {
         foreach (Image::getAllImages() as $image) {
             $imageObj = new Image($image['id_image']);
             $existing_img = $dir . $imageObj->getExistingImgPath() . '.jpg';
             if (file_exists($existing_img) && filesize($existing_img)) {
                 foreach ($type as $imageType) {
                     if (!file_exists($dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg')) {
                         if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) {
                             $this->errors[] = $this->trans('Original image is corrupt (%filename%) for product ID %id% or bad permission on folder.', array('%filename%' => $existing_img, '%id%' => (int) $imageObj->id_product), 'Admin.Design.Notification');
                         }
                         if ($generate_hight_dpi_images) {
                             if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) {
                                 $this->errors[] = $this->trans('Original image is corrupt (%filename%) for product ID %id% or bad permission on folder.', array('%filename%' => $existing_img, '%id%' => (int) $imageObj->id_product), 'Admin.Design.Notification');
                             }
                         }
                     }
                 }
             } else {
                 $this->errors[] = $this->trans('Original image is missing or empty (%filename%) for product ID %id%', array('%filename%' => $existing_img, '%id%' => (int) $imageObj->id_product), 'Admin.Design.Notification');
             }
             if (time() - $this->start_time > $this->max_execution_time - 4) {
                 // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
                 return 'timeout';
             }
         }
     }
     return (bool) count($this->errors);
 }
コード例 #4
0
 public function initFormAttributes($product)
 {
     $data = $this->createTemplate($this->tpl_form);
     if (!Combination::isFeatureActive()) {
         $this->displayWarning($this->l('This feature has been disabled. ') . ' <a href="index.php?tab=AdminPerformance&token=' . Tools::getAdminTokenLite('AdminPerformance') . '#featuresDetachables">' . $this->l('Performances') . '</a>');
     } elseif (Validate::isLoadedObject($product)) {
         if ($this->product_exists_in_shop) {
             if ($product->is_virtual) {
                 $data->assign('product', $product);
                 $this->displayWarning($this->l('A virtual product cannot have combinations.'));
             } else {
                 $attribute_js = array();
                 $attributes = Attribute::getAttributes($this->context->language->id, true);
                 foreach ($attributes as $k => $attribute) {
                     $attribute_js[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name'];
                     natsort($attribute_js[$attribute['id_attribute_group']]);
                 }
                 $currency = $this->context->currency;
                 $data->assign('attributeJs', $attribute_js);
                 $data->assign('attributes_groups', AttributeGroup::getAttributesGroups($this->context->language->id));
                 $data->assign('currency', $currency);
                 $images = Image::getImages($this->context->language->id, $product->id);
                 $data->assign('tax_exclude_option', Tax::excludeTaxeOption());
                 $data->assign('ps_weight_unit', Configuration::get('PS_WEIGHT_UNIT'));
                 $data->assign('ps_use_ecotax', Configuration::get('PS_USE_ECOTAX'));
                 $data->assign('field_value_unity', $this->getFieldValue($product, 'unity'));
                 $data->assign('reasons', $reasons = StockMvtReason::getStockMvtReasons($this->context->language->id));
                 $data->assign('ps_stock_mvt_reason_default', $ps_stock_mvt_reason_default = Configuration::get('PS_STOCK_MVT_REASON_DEFAULT'));
                 $data->assign('minimal_quantity', $this->getFieldValue($product, 'minimal_quantity') ? $this->getFieldValue($product, 'minimal_quantity') : 1);
                 $data->assign('available_date', $this->getFieldValue($product, 'available_date') != 0 ? stripslashes(htmlentities($this->getFieldValue($product, 'available_date'), $this->context->language->id)) : '0000-00-00');
                 $i = 0;
                 $type = ImageType::getByNameNType('%', 'products', 'height');
                 if (isset($type['name'])) {
                     $data->assign('imageType', $type['name']);
                 } else {
                     $data->assign('imageType', ImageType::getFormattedName('small'));
                 }
                 $data->assign('imageWidth', (isset($image_type['width']) ? (int) $image_type['width'] : 64) + 25);
                 foreach ($images as $k => $image) {
                     $images[$k]['obj'] = new Image($image['id_image']);
                     ++$i;
                 }
                 $data->assign('images', $images);
                 $data->assign($this->tpl_form_vars);
                 $data->assign(array('list' => $this->renderListAttributes($product, $currency), 'product' => $product, 'id_category' => $product->getDefaultCategory(), 'token_generator' => Tools::getAdminTokenLite('AdminAttributeGenerator'), 'combination_exists' => Shop::isFeatureActive() && Shop::getContextShopGroup()->share_stock && count(AttributeGroup::getAttributesGroups($this->context->language->id)) > 0 && $product->hasAttributes()));
             }
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before adding combinations.'));
         }
     } else {
         $data->assign('product', $product);
         $this->displayWarning($this->l('You must save this product before adding combinations.'));
     }
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
コード例 #5
0
ファイル: StoresController.php プロジェクト: M03G/PrestaShop
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     $distance_unit = Configuration::get('PS_DISTANCE_UNIT');
     if (!in_array($distance_unit, array('km', 'mi'))) {
         $distance_unit = 'km';
     }
     $this->context->smarty->assign(array('mediumSize' => Image::getSize(ImageType::getFormattedName('medium')), 'searchUrl' => $this->context->link->getPageLink('stores'), 'distance_unit' => $distance_unit, 'stores' => $this->getTemplateVarStores()));
     $this->setTemplate('cms/stores');
 }
コード例 #6
0
 protected function postImage($id)
 {
     $ret = parent::postImage($id);
     if (($id_category = (int) Tools::getValue('id_category')) && isset($_FILES) && count($_FILES)) {
         $name = 'image';
         if ($_FILES[$name]['name'] != null && file_exists(_PS_CAT_IMG_DIR_ . $id_category . '.' . $this->imageType)) {
             $images_types = ImageType::getImagesTypes('categories');
             foreach ($images_types as $k => $image_type) {
                 if (!ImageManager::resize(_PS_CAT_IMG_DIR_ . $id_category . '.' . $this->imageType, _PS_CAT_IMG_DIR_ . $id_category . '-' . stripslashes($image_type['name']) . '.' . $this->imageType, (int) $image_type['width'], (int) $image_type['height'])) {
                     $this->errors = $this->trans('An error occurred while uploading category image.', array(), 'Admin.Catalog.Notification');
                 }
             }
         }
         $name = 'thumb';
         if ($_FILES[$name]['name'] != null) {
             if (!isset($images_types)) {
                 $images_types = ImageType::getImagesTypes('categories');
             }
             $formatted_small = ImageType::getFormattedName('small');
             foreach ($images_types as $k => $image_type) {
                 if ($formatted_small == $image_type['name']) {
                     if ($error = ImageManager::validateUpload($_FILES[$name], Tools::getMaxUploadSize())) {
                         $this->errors[] = $error;
                     } elseif (!($tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES[$name]['tmp_name'], $tmpName)) {
                         $ret = false;
                     } else {
                         if (!ImageManager::resize($tmpName, _PS_CAT_IMG_DIR_ . $id_category . '-' . stripslashes($image_type['name']) . '.' . $this->imageType, (int) $image_type['width'], (int) $image_type['height'])) {
                             $this->errors = $this->trans('An error occurred while uploading thumbnail image.', array(), 'Admin.Catalog.Notification');
                         } elseif (($infos = getimagesize($tmpName)) && is_array($infos)) {
                             ImageManager::resize($tmpName, _PS_CAT_IMG_DIR_ . $id_category . '_' . $name . '.' . $this->imageType, (int) $infos[0], (int) $infos[1]);
                         }
                         if (count($this->errors)) {
                             $ret = false;
                         }
                         unlink($tmpName);
                         $ret = true;
                     }
                 }
             }
         }
     }
     return $ret;
 }