protected function _regenerateNewImagesOfShops($dir, $type) { if (!is_dir($dir)) { return false; } $generate_hight_dpi_images = (bool) Configuration::get('PS_HIGHT_DPI'); include_once __DIR__ . '/../../../modules/aphrodinet/classes/AphStoreImage.php'; foreach (AphStoreImage::getAllImages() as $image) { $imageObj = new AphStoreImage($image['id_image']); $existing_img = $dir . $imageObj->getExistingImgPath() . '.jpg'; if (file_exists($existing_img) && filesize($existing_img)) { foreach ($type as $imageType) { unlink($dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg'); //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[] = sprintf(Tools::displayError('Original image is corrupt (%s) for product ID %2$d or bad permission on folder'), $existing_img, (int) $imageObj->id_product); } 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[] = sprintf(Tools::displayError('Original image is corrupt (%s) for product ID %2$d or bad permission on folder'), $existing_img, (int) $imageObj->id_product); } } //} } } else { $this->errors[] = sprintf(Tools::displayError('Original image is missing or empty (%1$s) for product ID %2$d'), $existing_img, (int) $imageObj->id_product); } 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); }
public function initContent() { parent::initContent(); $shop = NULL; $alias_shop = (int) Tools::getValue('ash'); if (!empty($alias_shop)) { $_s = AphStore::getByAlias($alias_shop, Context::getContext()->language->id); $id_shop = $_s['id_shop']; } else { $id_shop = (int) Tools::getValue('ids'); } $shop = new AphStore($id_shop, Context::getContext()->language->id); $cover = NULL; $images = AphStoreImage::getImages(Context::getContext()->language->id, $id_shop); foreach ($images as &$image) { if (!empty($image['cover'])) { $cover = $image; } } if (empty($cover) && !empty($images)) { $cover = $images[0]; } $this->context->smarty->tpl_vars['meta_title']->value = $shop->name; $this->context->smarty->tpl_vars['meta_description']->value = $shop->meta_description; $products_by_category = array(); $categories = Category::getAllCategoriesName(NULL, Context::getContext()->language->id, true); if (!empty($categories)) { foreach ($categories as &$category) { if (Configuration::get('PS_ROOT_CATEGORY') == $category['id_category'] || Configuration::get('PS_HOME_CATEGORY') == $category['id_category']) { continue; } $products = AphStore::getProductsByStore($id_shop, Context::getContext()->language->id, NULL, NULL, 'name', 'desc', $category['id_category'], true); foreach ($products as &$product) { if (empty($products_by_category[$category['id_category']])) { $products_by_category[$category['id_category']] = array('id_category' => $category['id_category'], 'name' => $category['name'], 'class' => Tools::link_rewrite($category['name']), 'products' => array()); } $products_by_category[$category['id_category']]['products'][$product['id_product']] = array('id_product' => $product['id_product'], 'name' => $product['name'], 'link' => Context::getContext()->link->getProductLink((int) $product['id_product'], $product['link_rewrite'], $category['id_category'], $product['ean13'])); } } } $this->context->smarty->assign(array('shop' => $shop, 'cover' => $cover, 'images' => $images, 'products_by_category' => $products_by_category)); $this->context->controller->addCSS('/themes/aphrodinet/css/shop.css', 'all'); $this->setTemplate('shop.tpl'); }
public function initContent() { parent::initContent(); $specific_price = NULL; $date = Tools::getValue('date'); if (empty($date) || empty($date)) { $date = date('Y-m-d', strtotime('+2 day')); } $id_product = Tools::getValue('id_product'); if (!empty($date)) { $product = new Product($id_product, true, Context::getContext()->language->id, Context::getContext()->shop->id); } if (empty($product)) { $this->setTemplate('availability_no_product.tpl'); error_log(__LINE__); return; } $id_shop = (int) Tools::getValue('ids'); $id_city = (int) Tools::getValue('id_city'); if (empty($id_shop) && empty($id_city)) { $this->setTemplate('availability_no_location.tpl'); error_log(__LINE__); return; } if (!empty($id_shop)) { $shop = NULL; $alias_shop = (int) Tools::getValue('ash'); if (!empty($alias_shop)) { $_s = AphStore::getByAlias($alias_shop, Context::getContext()->language->id); $id_shop = $_s['id_shop']; } else { $id_shop = (int) Tools::getValue('ids'); } $shop = new AphStore($id_shop, Context::getContext()->language->id); $cover = NULL; $images = AphStoreImage::getImages(Context::getContext()->language->id, $id_shop); foreach ($images as &$image) { if (!empty($image['cover'])) { $cover = $image; } } if (empty($cover) && !empty($images)) { $cover = $images[0]; } } if (empty($id_shop) && !empty($id_city)) { $city = AphCity::getCity($id_city); if (empty($city) && empty($id_shop)) { $this->setTemplate('availability_no_city.tpl'); return; } $shops = AphStore::getByCity($id_city, Context::getContext()->language->id); if (empty($shops)) { $shops = array(); $id_currency = Validate::isLoadedObject(Context::getContext()->currency) ? (int) Context::getContext()->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT'); $_shops = AphStore::getStoresByProduct($id_product, Context::getContext()->language->id, null, 100000); foreach ($_shops as &$shop) { if ($this->distance($shop['latitude'], $shop['longitude'], $city['latitude'], $city['longitude'], 'K') > Configuration::get('APH_MAX_KM_FAR_AWAY')) { continue; } $product = new Product($id_product, false, (int) Context::getContext()->language->id, (int) $shop['id_shop']); $price = Product::getPriceStatic($id_product, true, 0, 2, null, false, true, 1, false, null, null, null, $specific_price, true, true, Context::getContext(), true, $date); if (empty($price)) { $price = $product->price; } else { $price = $price; } $shop['price_from'] = Tools::displayPrice($price, $id_currency); //$url = !empty($ssl) ? 'https://'.$shop['domain_ssl'] : 'http://'.$shop['domain']; //$shop['url'] = $url.$shop['uri']; $shop['url'] = Context::getContext()->link->getModuleLink('blockmobilecart', 'availability', array('id_product' => $id_product, 'date' => $date, 'ids' => $shop['id_shop'])); $shop['img_link_rewrite'] = Tools::link_rewrite($shop['legend']); $shops[] = $shop; } if (empty($shops)) { $this->context->smarty->assign(array('availability_no_closure_shops' => true)); } else { $this->context->smarty->assign(array('shops' => $shops, 'availability_no_shops' => true, 'availability_no_shops_city' => $city['name'], 'availability_no_shops_km' => Configuration::get('APH_MAX_KM_FAR_AWAY'))); } $this->setTemplate('availability_shops.tpl'); return; } } else { $shop = new AphStore($id_shop, Context::getContext()->language->id); if (empty($shop) && empty($id_city)) { $this->setTemplate('availability_no_shop.tpl'); error_log(__LINE__); return; } // il negozio non offre il servizio $product = new Product($id_product, true, Context::getContext()->language->id, $id_shop); $employees = AphEmployeeProduct::getEmployeesByShopAndProduct($id_shop, $id_product); if (empty($employees)) { $products = AphStore::getProductsByStore($id_shop, Context::getContext()->language->id, 0, 20, 'name', 'asc', $product->id_category_default, true); foreach ($products as &$product) { $p = new Product($product['id_product'], false, (int) Context::getContext()->language->id, $id_shop); $price = Product::getPriceStatic($product['id_product'], true, 0, 2, null, false, true, 1, false, null, null, null, $specific_price, true, true, Context::getContext(), true, $date); if (empty($price)) { $price = $p->price; } else { $price = $price; } $product['price_from'] = Tools::displayPrice($price, $id_currency); } $this->context->smarty->assign(array('shop' => $shop, 'cover' => $cover, 'images' => $images, 'products' => $products, 'token' => Tools::getToken(false))); $this->setTemplate('availability_no_product_for_shop.tpl'); return; } } if (empty($product)) { $this->setTemplate('availability_no_product.tpl'); return; } $this->context->smarty->tpl_vars['meta_title']->value = 'Acquista ' . $product->name . ' presso ' . $shop->name; $this->context->smarty->tpl_vars['meta_description']->value = $shop->meta_description; // $products_by_category = array(); // $categories = Category::getAllCategoriesName(NULL, Context::getContext()->language->id, true); // if (!empty($categories)){ // foreach ($categories as &$category) { // $products = AphStore::getProductsByStore($id_shop, Context::getContext()->language->id, NULL, NULL, 'name', 'desc', $category['id_category'], true); // foreach ($products as &$product) { // if (empty($products_by_category[ $category['id_category'] ])){ // $products_by_category[ $category['id_category'] ] = array( // 'id_category' => $category['id_category'], // 'name' => $category['name'], // 'class' => Tools::link_rewrite($category['name']), // 'products' => array() // ); // } // $products_by_category[ $category['id_category'] ]['products'][ $product['id_product'] ] = array( // 'id_product' => $product['id_product'], // 'name' => $product['name'], // 'link' => Context::getContext()->link->getProductLink((int)$product['id_product'], $product['link_rewrite'], $category['id_category'], $product['ean13']) // ); // } // } // } $jsVars = array(); $jsVars['calendar_params'] = array('ajax' => 1, 'ajaxCall' => 'ajaxshowCalendar', 'id_product' => $id_product, 'ids' => $id_shop, 'date' => $date, 'id_city' => empty($id_city) ? $shop->id_city : $id_city); $this->context->smarty->assign(array('shop' => $shop, 'cover' => $cover, 'images' => $images, 'product' => $product, 'token' => Tools::getToken(false), 'jsVars' => $jsVars)); $this->setTemplate('availability_full.tpl'); }
/** * @param Store $obj * @throws Exception * @throws SmartyException */ public function initFormImages($obj) { if ((bool) $obj->id) { $count_images = Db::getInstance()->getValue(' SELECT COUNT(id_shop) FROM ' . _DB_PREFIX_ . 'store_image WHERE id_shop = ' . (int) $obj->id_shop); $images = AphStoreImage::getImages($this->context->language->id, $obj->id_shop); foreach ($images as $k => $image) { $images[$k] = new AphStoreImage($image['id_image']); } $language = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT')); $image_uploader = new HelperImageUploader('file'); $image_uploader->setTemplateDirectory($this->tpl_dir . 'helpers/uploader/')->setMultiple(!(Tools::getUserBrowser() == 'Apple Safari' && Tools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminAphStores') . '&ajax=1&id_store=' . (int) $obj->id . '&action=addStoreImage')->setTemplate('ajax.tpl'); $this->context->smarty->assign(array('iso_lang' => $language['iso_code'], 'token' => $this->token, 'table' => $this->table, 'countImages' => $count_images, 'images' => $images, 'max_image_size' => $this->max_image_size / 1024 / 1024, "image_uploader" => $image_uploader->render(), 'table' => $this->table, 'default_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'current_shop_id' => (int) $obj->id_shop, 'id_shop' => (int) $obj->id_shop, 'id_store' => (int) $obj->id)); $type = ImageType::getByNameNType('%', 'stores', 'height'); if (isset($type['name'])) { $this->context->smarty->assign('imageType', $type['name']); } else { $this->context->smarty->assign('imageType', ImageType::getFormatedName('medium')); } } }
/** * Returns the path to the folder containing the image in the new filesystem * * @return string path to folder */ public function getImgFolder() { if (!$this->id) { return false; } if (!$this->folder) { $this->folder = AphStoreImage::getImgFolderStatic($this->id); } return $this->folder; }