<?php
use App\Application\Service\ElasticSearch\ElasticSearchService;
use App\Application\Service\Taxonomy\TaxonomyService;
use App\Application\Service\Taxonomy\TaxonomyTreeService;
use App\Client\Cdn\Factory\ImageUrlFactory;
use App\Entity\System\Tag;
use App\ViewManager\Landing\ViewService;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
class categoryController extends Controller
{
/** @var \Category */
protected $_object;
public const ORDER_BY_SCORE_DESC = -1;
public const LIMIT_PRODS_ES = 1000;
public const INIT_ES = 0;
/** @var TaxonomyTreeService */
private $taxonomyTreeService;
/** @var TaxonomyService */
private $taxonomyService;
/** @var TranslatorInterface */
private $translator;
/** @var ViewService */
private $viewService;
/** @var Environment */
private $twig;
public function __construct($id = null)
{
parent::__construct('Category', $id);
$this->taxonomyTreeService = Tools::getSfService(TaxonomyTreeService::class);
$this->taxonomyService = Tools::getSfService(TaxonomyService::class);
$this->translator = Tools::getSfService('translator');
$this->twig = Tools::getSfService('twig');
$this->viewService = Tools::getSfService(ViewService::class);
}
public function index()
{
}
public function landingpage()
{
if (!Tools::getSfParameter('is_staging')) {
\Sentry\captureException(new \Exception('Using legacy category controller'));
}
$home_category = App\Entity\System\Category::HOME_ID;
$sections = [];
$categTree = Category::getCategory($this->_object->id, '_layout0_Array', []);
$categChilds = $categTree['selcat_childs'];
$allTaxonomiesForLanguageID = $this->taxonomyService->getAllCachedTaxonomiesForLanguage(Session::get('id_lang'));
$categTree = $this->taxonomyTreeService->getLegacyTree($allTaxonomiesForLanguageID, Session::get('lang'), []);
$mainCategory = (intval($this->_object->id_parent) === intval($home_category));
// RECORREMOS EL LISTADO DE CATEGORIAS Y EXTRAEMOS LA PRIMERA PARA SELECCIONAR
$category_aux = [];
foreach ($categTree['_layout0_Array'] as $cat) {
if ($cat['id'] != $this->_object->id) {
array_push($category_aux, $cat);
} else {
array_unshift($category_aux, $cat);
}
}
$categTree['_layout0_Array'] = $category_aux;
$mainavLinks = Category_mainav_link::getIdLinks($this->_object->id);
if ($mainavLinks) {
$this->category_mainav = $this->_object->id;
$this->category_mainav_links = $mainavLinks;
} else {
if ($mainCategory) {
$this->category_mainav = $this->_object->id;
$this->category_mainav_links = []; // Mostramos siempre las categorías hijo
}
}
$this->addJs([
['value' => 'public/js/tools.js?t=201606071238'],
['value' => 'public/js/categorylandingpage.js?t=201606071238'],
['value' => 'var filterMobile=0;',
'code' => true],
]);
$vars = [];
$vars['categMenuList'] = [];
$vars['_partials0'] = [
['sections' => $sections],
];
$vars['_layout1'] = [];
$vars['_layout1']['desc_category_extra'] = Tools::replaceAutomatedLinks($this->_object->description_extra[Session::get('id_lang')]);
$vars['_layout1']['_layout0_Array'] = $categTree['_layout0_Array'];
$vars['_layout2'] = [];
$vars['_layout2']['name_category'] = str_replace('|', '', $this->_object->name[Session::get('id_lang')]);
$vars['_layout2']['desc_category'] = Tools::replaceAutomatedLinks($this->_object->description[Session::get('id_lang')]);
$vars['_layout2']['cat'] = $this->_object->id;
$vars['_layout2']['link_rewrite'] = $this->_object->link_rewrite[Session::get('id_lang')];
$vars['_layout2']['is_exception'] = (in_array($this->_object->id, Tools::jsonDecode(Configuration::get('CATEGORY_TEXT_EXCEPTION')))) ? true : false;
$vars['_layout2']['_partials0'] = $categChilds;
$vars['_layout2']['childs'] = $categChilds;
$vars['_layout2']['childs_num_row'] = 3;
$countCategChild = count($categChilds);
for ($nRow = 4; $nRow <= 5; $nRow++) {
if (($countCategChild % $nRow) === 0) {
$vars['_layout2']['childs_num_row'] = $nRow;
}
}
if (Tools::isMobile()) {
$categoryBread = array_slice($sections, -1, 1);
$vars['_partials0'][0]['name'] = $categoryBread[0]['name'];
$vars['_partials0'][0]['arrow'] = false;
$vars['_partials0'][0]['linkCategory'] = false;
$vars['_layout1'] = 'not_display';
$this->addJs([
['value' => 'var filterMobile=0;',
'code' => true],
]);
}
$this->_object->canonical = Link::getCategoryLink($this->_object->id);
$this->setView('categoryLandingPage', $vars);
}
public function downloadcsv($type = 'taxonomy', $supplier = null)
{
$categoryId = Tools::getValue('args');
$filters = Tools::getValue('filters', []);
$init = Tools::getValue('init', self::INIT_ES);
$limit = Tools::getValue('limit', self::LIMIT_PRODS_ES);
$ajax = Tools::getValue('ajax', false);
if ($supplier) {
$filters['featured'] = [0];
}
$resultProducts = [];
switch ($type) {
case 'taxonomy':
$filters['taxonomy'] = [$categoryId];
$results = Tools::getResultsElasticSearch(Session::get('lang'), $init, $limit, $this->ajax, $filters, Session::get('is_wholesaler'));
$resultProducts = $results['result'];
break;
case 'new_products':
$viewFilters = $this->viewService->getFiltersByElasticSearchResults(null, $this->model, ViewService::VIEW_TYPE_NEW_PRODUCTS);
$resultProducts = $viewFilters->getCategoryProducts();
break;
case 'best_sellers':
$filters['minRecentSales'] = 20;
$results = Tools::getResultsElasticSearch(Session::get('lang'), $init, $limit, $this->ajax, $filters, Session::get('is_wholesaler'));
$resultProducts = $results['result'];
break;
case 'new_stock':
$viewFilters = $this->viewService->getFiltersByElasticSearchResults(null, $this->model, ViewService::VIEW_TYPE_NEW_STOCK_PRODUCTS);
$resultProducts = $viewFilters->getCategoryProducts();
break;
case 'tag':
$filters['tags'] = [$categoryId];
$results = Tools::getResultsElasticSearch(Session::get('lang'), $init, $limit, $this->ajax, $filters, Session::get('is_wholesaler'));
$resultProducts = $results['result'];
break;
case 'manufacturer':
$filters['brands'] = [$categoryId];
$results = Tools::getResultsElasticSearch(Session::get('lang'), $init, $limit, $this->ajax, $filters, Session::get('is_wholesaler'));
$resultProducts = $results['result'];
break;
case 'bigstocks':
$filters['bigStocks'] = 1;
$sexAndSensualityTaxonomyId = 17088;
$eroticClothesTaxonomyId = 16630;
$filters['excludeTaxonomy'] = [$sexAndSensualityTaxonomyId, $eroticClothesTaxonomyId];
$results = Tools::getResultsElasticSearch(Session::get('lang'), $init, $limit, $this->ajax, $filters, Session::get('is_wholesaler'));
$resultProducts = $results['result'];
break;
case 'search':
$filters['order'] = [self::ORDER_BY_SCORE_DESC];
$searchText = str_replace('+', ' ', $categoryId);
$results = Tools::getResultsElasticSearch(Session::get('lang'), $init, $limit, $this->ajax, $filters, Session::get('is_wholesaler'), $searchText);
$resultProducts = $results['result'];
break;
}
$this->setDisplayFooter(false);
$this->setDisplayHeadAndHeader(false);
header('Content-disposition: attachment; filename=products.csv');
header('Content-type: application/octet-stream');
$csvArray = [];
$csvArray[0] = [
'sku' => 'sku',
'name' => 'name',
'images' => 'images',
'video' => 'video',
'stock1' => 'stock_a',
'stock1Days' => 'stock_a_days',
'stock2' => 'stock_b',
'stock2Days' => 'stock_b_days',
'stock3' => 'stock_c',
'stock3Days' => 'stock_c_days',
'pvd_old' => 'pvd_old',
'pvd' => 'pvd',
'pvd_dif' => 'pvd_dif',
'pvr_old' => 'pvr_old',
'pvr' => 'pvr',
'pvr_dif' => 'pvr_dif',
'category' => 'category',
];
echo implode(';', $csvArray[0])."\r\n";
if (!empty($resultProducts)) {
try {
$taxonomyManager = Tools::getSfService(\App\Manager\System\TaxonomyManager::class);
$sessionService = Tools::getSfService(\App\Application\Service\Session\SessionService::class);
foreach ($resultProducts as $key => $resultProduct) {
$sincronizedDays = ($resultProduct['sincronized'] == 1 && !empty($resultProduct['days']) && $resultProduct['days'] > 0) ? $resultProduct['days'] : 1;
$stockMessage = Tools::calculateDaysTransit($sincronizedDays, $resultProduct['id_product']);
$stockFutureMsg = Tools::calculateDaysTransit(
$resultProduct['days_future_stock'],
$resultProduct['id_product']
);
$stockExternMessage = Tools::calculateDaysTransit(
$sincronizedDays,
$resultProduct['id_product'],
true
);
$pvdDif = Tools::displayPrice(0, false).'%';
if ($resultProduct['price_after_old'] > 0) {
$pvdDif = Tools::displayPrice(
(($resultProduct['price_after_old'] - $resultProduct['price_after']) / $resultProduct['price_after_old']) * 100,
false
).'%';
}
$pvrDif = Tools::displayPrice(0, false).'%';
if ($resultProduct['price_before_old'] > 0) {
$pvrDif = Tools::displayPrice((($resultProduct['price_before_old'] - $resultProduct['price_before']) / $resultProduct['price_before_old']) * 100, false).'%';
}
$images = explode(';', $resultProduct['name_image']);
foreach ($images as &$image) {
$image = ImageUrlFactory::buildByImageName($image);
}
$images = implode(',', $images);
if (is_array($resultProduct['reference'])) {
$resultProduct['reference'] = end($resultProduct['reference']);
}
$stock1Days = $stockMessage['days'] ?? 1;
$stock2Days = $stockFutureMsg['days'] ?? 5;
$stock3Days = $stockExternMessage['days'] ?? 1;
$defaultTaxonomyId = $resultProduct['id_taxonomy_default'] ?? null;
$taxonomyName = $defaultTaxonomyId ?
$taxonomyManager->getTaxonomyInfo($defaultTaxonomyId, $sessionService->get('id_lang')) : null;
$csvArray[$resultProduct['id_product']] = [
'sku' => $resultProduct['reference'],
'name' => addslashes($resultProduct['name']),
'images' => $images,
'video' => !empty($resultProduct['video']) ? 'https://www.youtube.com/watch?v='.$resultProduct['video'] : '-',
'stock1' => $resultProduct['quantity_immediate'] > 0 ? $resultProduct['quantity_immediate'] : 0,
'stock1Days' => $stock1Days,
'stock2' => $resultProduct['quantity_future'] > 0 ? $resultProduct['quantity_future'] : 0,
'stock2Days' => $stock2Days,
'stock3' => ($resultProduct['quantity_supplier'] - $resultProduct['quantity_extern']) > 0 ? ($resultProduct['quantity_supplier'] - $resultProduct['quantity_extern']) : 0,
'stock3Days' => $stock3Days,
'pvd_old' => !empty($resultProduct['price_after_old']) && $resultProduct['price_after_old'] > 0 ? Tools::displayPrice($resultProduct['price_after_old'], false) : '-',
'pvd' => Tools::displayPrice($resultProduct['price_after'], false),
'pvd_dif' => $pvdDif,
'pvr_old' => !empty($resultProduct['price_before_old']) && $resultProduct['price_before_old'] > 0 ? Tools::displayPrice($resultProduct['price_before_old'], false) : '-',
'pvr' => Tools::displayPrice($resultProduct['price_before'], false),
'pvr_dif' => $pvrDif,
'category' => $taxonomyName['tl_name'],
];
echo implode(';', $csvArray[$resultProduct['id_product']])."\r\n";
}
} catch (Exception $e) {
echo $e->getCode().' - '.$e->getMessage();
}
}
exit;
}
/**
* @deprecated moved to new architecture
*
* @throws \Twig\Error\SyntaxError
* @throws \Psr\Cache\InvalidArgumentException
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\LoaderError
*/
public function bigStocks()
{
if (!Tools::getSfParameter('is_staging')) {
\Sentry\captureException(new \Exception('Using legacy category controller'));
}
$languageId = (int)Session::get('id_lang');
$language = \Session::get('lang');
$isoCode = \Language::getIsoById($languageId);
$this->_object->meta_title[Session::get('id_lang')] = $this->l('Comprar a Precio de Mayorista BigStocks', 'categoryController');
$this->_object->meta_description[Session::get('id_lang')] = str_replace('%s', '', $this->l('Comprar a precio de mayorista BigStocks. Venta al mayor B2B. Bigbuy es tu Proveedor Dropshipping de BigStocks.', 'categoryController'));
$this->_object->meta_keywords[Session::get('id_lang')] = $this->l('Mayorista BigStocks, dropshipping BigStocks', 'categoryController');
$description = $this->translator->trans('big-stocks.title', [], 'messages', $language).
$this->translator->trans('big-stocks.list-header', [], 'messages', $language).'<ul><li>'.
$this->translator->trans('big-stocks.list-item-1', [], 'messages', $language).'</li><li>'.
$this->translator->trans('big-stocks.list-item-2', [], 'messages', $language).'</li><li>'.
$this->translator->trans('big-stocks.list-item-3', [], 'messages', $language).'</li><li>'.
$this->translator->trans('big-stocks.list-item-4', [], 'messages', $language).'</li><li>'.
$this->translator->trans('big-stocks.list-item-5', [], 'messages', $language).'</li><ul>';
$this->_object->meta_title[Session::get('id_lang')] = $this->l('Comprar a Precio de Mayorista BigStocks', 'categoryController');
$this->_object->meta_description[Session::get('id_lang')] = $description;
$this->_object->meta_keywords[Session::get('id_lang')] = $this->l('Mayorista BigStocks, dropshipping BigStocks', 'categoryController');
$numReferences = 0;
$allTaxonomiesForLanguageId = $this->taxonomyService->getAllCachedTaxonomiesForLanguage($languageId);
$taxonomyTree = $this->taxonomyTreeService->getLegacyTree($allTaxonomiesForLanguageId, $language, []);
$breadCrumb = [];
$sections = $breadCrumb;
$taxonomyChildren = [];
$hasChildren = !empty($taxonomyChildren);
$parentTaxonomyName = null;
$homeCategory = App\Entity\System\Category::HOME_ID;
$viewFilters = $this->viewService->getFiltersByElasticSearchResults(null, $this->model, ViewService::VIEW_TYPE_BIG_STOCKS);
$hrefLink = Link::getCategoryLink($this->_object->id);
$method = 'category/ajax_show_bigstocks_products';
$paginatorData = $this->viewService->getPaginatorDataEncoded($hrefLink, $method, $viewFilters, $this->_object->id);
$jsParameters = $this->viewService->getParameters($homeCategory, 0, $viewFilters);
$codeJs = Tools::createCategoryFilters($jsParameters);
$this->addJs($this->viewService->addJs($paginatorData, $codeJs, 1, ViewService::VIEW_TYPE_BIG_STOCKS));
$entityName = $this->l('Big Stocks', 'categoryController');
$this->metaNoindex = false;
if ($viewFilters->getAjax()) {
$this->setDisplayFooter(false);
$this->setDisplayHeadAndHeader(false);
$this->setJsonArgs($this->viewService->setJsonArguments($viewFilters));
$this->setJsonResponse(true);
if (empty($viewFilters->getCategoryProducts())) {
$viewVars['_partials0'] = 'not_display';
} else {
$viewVars['_partials0'] = $viewFilters->getCategoryProducts();
}
$this->setView('ajax-product-list', $viewVars);
} else {
$sectionImage = 'public/img/category/stock_header';
$viewVars = $this->viewService->generateViewVars(
$sections,
$taxonomyTree,
$entityName,
$description,
$homeCategory,
$taxonomyChildren,
$hasChildren,
$numReferences,
false,
$viewFilters,
$sectionImage,
$parentTaxonomyName,
false,
false
);
$viewVars['redirect'] = BASE_URL.'category/filterMobile/bigStocks';
$viewVars['domain'] = 'messages';
$viewVars['languageIsoCode'] = $isoCode;
$viewVars['tag_data'] = [
'blackfriday_id' => Tag::BLACK_FRIDAY_TAG_ID,
'blackfriday_text' => Tag::TAG_BLACK_FRIDAY_TEXT,
'hotdeals_id' => Tag::HOTDEAL_TAG_ID,
'hotdeals_text' => Tag::TAG_HOTDEALS_TEXT,
];
$viewVars['rendered_twig_template'] = $this->twig->render($this->viewService->getTwigName(), $viewVars);
$this->setView('taxonomyList', $viewVars);
}
}
/**
* @deprecated moved to new architecture
*
* @throws \Psr\Cache\InvalidArgumentException
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function new_products(): void
{
if (!Tools::getSfParameter('is_staging')) {
\Sentry\captureException(new \Exception('Using legacy category controller'));
}
$languageId = (int)Session::get('id_lang');
$language = \Session::get('lang');
$isoCode = \Language::getIsoById($languageId);
$this->_object->meta_title[Session::get('id_lang')] = $this->l('Comprar a Precio de Mayorista Novedades', 'categoryController');
$this->_object->meta_description[Session::get('id_lang')] = $this->l('Comprar a precio de mayorista Novedades. Venta al mayor B2B. Bigbuy es tu Proveedor Dropshipping de novedades.', 'categoryController');
$this->_object->meta_keywords[Session::get('id_lang')] = $this->l('Mayorista Novedades, dropshipping Novedades', 'categoryController');
$numReferences = 0;
$allTaxonomiesForLanguageId = $this->taxonomyService->getAllCachedTaxonomiesForLanguage($languageId);
$taxonomyTree = $this->taxonomyTreeService->getLegacyTree($allTaxonomiesForLanguageId, $language, []);
$breadCrumb = [];
$sections = $breadCrumb;
$taxonomyChildren = $taxonomyTree['selcat_childs'];
$hasChildren = !empty($taxonomyChildren);
$parentTaxonomyName = null;
$homeCategory = App\Entity\System\Category::HOME_ID;
$viewFilters = $this->viewService->getFiltersByElasticSearchResults(null, $this->model, ViewService::VIEW_TYPE_NEW_PRODUCTS);
$hrefLink = Link::getCategoryLink($this->_object->id);
$method = 'category/ajax_show_new_products';
$paginatorData = $this->viewService->getPaginatorDataEncoded($hrefLink, $method, $viewFilters, $this->_object->id);
$jsParameters = $this->viewService->getParameters($homeCategory, 0, $viewFilters);
$codeJs = Tools::createCategoryFilters($jsParameters);
$this->addJs($this->viewService->addJs($paginatorData, $codeJs, 1, ViewService::VIEW_TYPE_NEW_PRODUCTS));
$this->metaNoindex = false;
if ($viewFilters->getAjax()) {
$this->setDisplayFooter(false);
$this->setDisplayHeadAndHeader(false);
$this->setJsonArgs($this->viewService->setJsonArguments($viewFilters));
$this->setJsonResponse(true);
if (empty($viewFilters->getCategoryProducts())) {
$viewVars['_partials0'] = 'not_display';
} else {
$viewVars['_partials0'] = $viewFilters->getCategoryProducts();
}
$this->setView('ajax-product-list', $viewVars);
} else {
$entityName = $this->l('Novedades', 'categoryController');
$descriptionEntity = Tools::replaceAutomatedLinks(
sprintf(
$this->l('Comprar a precio de mayorista Novedades. Venta al mayor B2B. Bigbuy es tu Proveedor Dropshipping de novedades.', 'categoryController'),
'<a href="##CMS_9##">',
'</a>'
)
);
$sectionImage = 'public/img/category/header_novedades';
$viewVars = $this->viewService->generateViewVars(
$sections,
$taxonomyTree,
$entityName,
$descriptionEntity,
$homeCategory,
$taxonomyChildren,
$hasChildren,
$numReferences,
false,
$viewFilters,
$sectionImage,
$parentTaxonomyName
);
$viewVars['redirect'] = BASE_URL.'category/filterMobile/news';
$viewVars['domain'] = 'messages';
$viewVars['languageIsoCode'] = $isoCode;
$viewVars['tag_data'] = [
'blackfriday_id' => Tag::BLACK_FRIDAY_TAG_ID,
'blackfriday_text' => Tag::TAG_BLACK_FRIDAY_TEXT,
'hotdeals_id' => Tag::HOTDEAL_TAG_ID,
'hotdeals_text' => Tag::TAG_HOTDEALS_TEXT,
];
$viewVars['rendered_twig_template'] = $this->twig->render($this->viewService->getTwigName(), $viewVars);
$this->setView('taxonomyList', $viewVars);
}
}
/**
* @deprecated moved to new architecture
*
* @throws \Psr\Cache\InvalidArgumentException
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function new_stock(): void
{
if (!Tools::getSfParameter('is_staging')) {
\Sentry\captureException(new \Exception('Using legacy category controller'));
}
$languageId = (int)Session::get('id_lang');
$language = \Session::get('lang');
$isoCode = \Language::getIsoById($languageId);
$this->_object->meta_title[Session::get('id_lang')] = $this->l('Comprar a Precio de Mayorista productos de nuevo en stock', 'categoryController');
$this->_object->meta_description[Session::get('id_lang')] = $this->l('Comprar a precio de mayorista productos de nuevo en stock. Venta al mayor B2B. Bigbuy es tu Proveedor Dropshipping de productos de nuevo en stock.', 'categoryController');
$this->_object->meta_keywords[Session::get('id_lang')] = $this->l('Mayorista de productos de nuevo en stock, dropshipping de productos de nuevo en stock', 'categoryController');
$numReferences = 0;
$allTaxonomiesForLanguageId = $this->taxonomyService->getAllCachedTaxonomiesForLanguage($languageId);
$taxonomyTree = $this->taxonomyTreeService->getLegacyTree($allTaxonomiesForLanguageId, $language, []);
$breadCrumb = [];
$sections = $breadCrumb;
$taxonomyChildren = $taxonomyTree['selcat_childs'];
$hasChildren = !empty($taxonomyChildren);
$parentTaxonomyName = null;
$homeCategory = App\Entity\System\Category::HOME_ID;
$viewFilters = $this->viewService->getFiltersByElasticSearchResults(null, $this->model, ViewService::VIEW_TYPE_NEW_STOCK_PRODUCTS);
$hrefLink = Link::getCategoryLink($this->_object->id);
$method = 'category/ajax_show_new_stock';
$paginatorData = $this->viewService->getPaginatorDataEncoded($hrefLink, $method, $viewFilters, $this->_object->id);
$jsParameters = $this->viewService->getParameters($homeCategory, 0, $viewFilters);
$codeJs = Tools::createCategoryFilters($jsParameters);
$this->addJs($this->viewService->addJs($paginatorData, $codeJs, 1, ViewService::VIEW_TYPE_NEW_STOCK_PRODUCTS));
$this->metaNoindex = false;
if ($viewFilters->getAjax()) {
$this->setDisplayFooter(false);
$this->setDisplayHeadAndHeader(false);
$this->setJsonArgs($this->viewService->setJsonArguments($viewFilters));
$this->setJsonResponse(true);
if (empty($viewFilters->getCategoryProducts())) {
$viewVars['_partials0'] = 'not_display';
} else {
$viewVars['_partials0'] = $viewFilters->getCategoryProducts();
}
$this->setView('ajax-product-list', $viewVars);
} else {
$entityName = $this->l('Nuevo en stock', 'categoryController');
$descriptionEntity = $this->_object->meta_description[Session::get('id_lang')];
$sectionImage = 'public/img/category/stock_header';
$viewVars = $this->viewService->generateViewVars(
$sections,
$taxonomyTree,
$entityName,
$descriptionEntity,
$homeCategory,
$taxonomyChildren,
$hasChildren,
$numReferences,
false,
$viewFilters,
$sectionImage,
$parentTaxonomyName
);
$viewVars['redirect'] = BASE_URL.'category/filterMobile/new_stock';
$viewVars['domain'] = 'messages';
$viewVars['languageIsoCode'] = $isoCode;
$viewVars['tag_data'] = [
'blackfriday_id' => Tag::BLACK_FRIDAY_TAG_ID,
'blackfriday_text' => Tag::TAG_BLACK_FRIDAY_TEXT,
'hotdeals_id' => Tag::HOTDEAL_TAG_ID,
'hotdeals_text' => Tag::TAG_HOTDEALS_TEXT,
];
$viewVars['rendered_twig_template'] = $this->twig->render($this->viewService->getTwigName(), $viewVars);
$this->setView('taxonomyList', $viewVars);
}
}
/**
* @deprecated moved to new architecture
*/
public function best_sellers(): void
{
if (!Tools::getSfParameter('is_staging')) {
\Sentry\captureException(new \Exception('Using legacy category controller'));
}
$languageId = (int)Session::get('id_lang');
$language = \Session::get('lang');
$isoCode = \Language::getIsoById($languageId);
$numReferences = 0;
$allTaxonomiesForLanguageId = $this->taxonomyService->getAllCachedTaxonomiesForLanguage($languageId);
$taxonomyTree = $this->taxonomyTreeService->getLegacyTree($allTaxonomiesForLanguageId, $language, []);
$breadCrumb = [];
$sections = $breadCrumb;
$taxonomyChildren = $taxonomyTree['selcat_childs'];
$hasChildren = !empty($taxonomyChildren);
$parentTaxonomyName = null;
$homeCategory = App\Entity\System\Category::HOME_ID;
$viewFilters = $this->viewService->getFiltersByElasticSearchResults(null, $this->model, ViewService::VIEW_TYPE_BEST_SELLERS);
$hrefLink = Link::getCategoryLink($this->_object->id);
$method = 'category/ajax_show_best_seller_products';
$paginatorData = $this->viewService->getPaginatorDataEncoded($hrefLink, $method, $viewFilters, $this->_object->id);
$jsParameters = $this->viewService->getParameters($homeCategory, 0, $viewFilters);
$codeJs = Tools::createCategoryFilters($jsParameters);
$this->addJs($this->viewService->addJs($paginatorData, $codeJs, 1, ViewService::VIEW_JS_TYPE_BEST_SELLERS));
$this->metaNoindex = false;
if ($viewFilters->getAjax()) {
$this->setDisplayFooter(false);
$this->setDisplayHeadAndHeader(false);
$this->setJsonArgs($this->viewService->setJsonArguments($viewFilters));
$this->setJsonResponse(true);
if (empty($viewFilters->getCategoryProducts())) {
$viewVars['_partials0'] = 'not_display';
} else {
$viewVars['_partials0'] = $viewFilters->getCategoryProducts();
}
$this->setView('ajax-product-list', $viewVars);
} else {
$entityName = $this->l('Top Ventas', 'categoryController');
$descriptionEntity = $this->l('¡Descubre los Top Ventas de BigBuy! Amplía el catálogo de tu comercio dropshipping con los artículos más vendidos de nuestra página web. Infórmate sobre nuestros packs mayoristas y vende al por mayor nuestros exclusivos productos.', 'categoryController');
$descriptionCategoryExtra = $this->l('En la sección Top Ventas de BigBuy encontrarás una amplia selección de los artículos más demandados por nuestros clientes. Si todavía no eres distribuidor de BigBuy, infórmate en nuestra web sobre los requisitos y ventajas que ofrecemos a nuestros clientes y consigue ya tu tienda dropshipping.¡Compra al por mayor nuestros artículos Top Ventas y tendrás el éxito de ventas asegurado! Ofrecemos los mejores precios mayoristas del mercado europeo. Además, podrás vender sin acumular stock gracias a nuestra modalidad de venta dropshipping. ¿Quieres formar parte de un negocio exitoso en continua expansión? BigBuy te lo pone fácil, no pierdas la oportunidad de adentrarte en el mundo del e-commerce de la mano de BigBuy, experimentado mayorista y dropshipper en el mercado europeo. ¡Descubre los mejores Top Ventas navegando por esta sección de BigBuy y haz ya tu pedido al por mayor con los productos de más éxito en el mercado!', 'categoryController');
$sectionImage = 'public/img/category/header_topventas';
$viewVars = $this->viewService->generateViewVars(
$sections,
$taxonomyTree,
$entityName,
$descriptionEntity,
$homeCategory,
$taxonomyChildren,
$hasChildren,
$numReferences,
false,
$viewFilters,
$sectionImage,
$parentTaxonomyName,
false,
true,
$descriptionCategoryExtra
);
$viewVars['redirect'] = BASE_URL.'category/filterMobile/best_sellers';
$viewVars['domain'] = 'messages';
$viewVars['languageIsoCode'] = $isoCode;
$viewVars['tag_data'] = [
'blackfriday_id' => Tag::BLACK_FRIDAY_TAG_ID,
'blackfriday_text' => Tag::TAG_BLACK_FRIDAY_TEXT,
'hotdeals_id' => Tag::HOTDEAL_TAG_ID,
'hotdeals_text' => Tag::TAG_HOTDEALS_TEXT,
];
$viewVars['rendered_twig_template'] = $this->twig->render($this->viewService->getTwigName(), $viewVars);
$this->setView('taxonomyList', $viewVars);
}
}
/**
* @deprecated moved to new architecture
*/
public function filterMobile($id): void
{
$languageId = (int)Session::get('id_lang');
$isoCode = \Language::getIsoById($languageId);
$viewFilters = $this->viewService->getFiltersByElasticSearchResults(null, $this->model, $id);
$pagesExceptions = [
'news' => [
'call' => '',
'method' => 'category/new_products',
'target_path' => 'category/ajax_show_new_products',
'limit' => 0,
'filter' => ['order' => [6]],
'excludes' => true,
],
'bigstocks' => [
'call' => '',
'method' => 'category/bigstocks',
'target_path' => 'category/ajax_show_bigstocks_products',
'limit' => 0,
'filter' => ['order' => [6]],
'excludes' => true,
],
'new_stock' => [
'call' => '',
'method' => 'category/new_stock',
'target_path' => 'category/ajax_show_new_stock',
'limit' => 'configuration',
'filter' => ['order' => [6]],
'excludes' => false,
],
'best_sellers' => [
'call' => 'get_best_sellers',
'method' => 'category/best_sellers',
'target_path' => 'category/ajax_show_best_seller_products',
'limit' => 'configuration',
'filter' => ['order' => [6]],
'excludes' => false,
],
'manufacturer' => [
'call' => 'show_products_manufacturer',
'method' => '',
'target_path' => 'manufacturer/ajax_show_products',
'limit' => 'configuration',
'filter' => ['order' => [6]],
'excludes' => false,
],
'tag' => [
'call' => 'show_products_tag',
'method' => '',
'target_path' => 'tag/ajax_show_tagProducts',
'limit' => 'configuration',
'filter' => ['order' => [6]],
'excludes' => false,
],
'search' => [
'call' => 'show_products_tag',
'method' => '',
'target_path' => 'search/result_new',
'limit' => 'configuration',
'filter' => [],
'excludes' => false,
],
];
if (!\array_key_exists($id, $pagesExceptions)) {
$this->setView('not-found');
return;
}
$page = $pagesExceptions[$id];
$coreUrl = Core_url_rewrite::getUrlRewriteByTargetPath($page['method'], Session::get('id_lang'));
$linkRewrite = $coreUrl[0]['request_path'];
$href = BASE_URL.$page['target_path'];
$jsParameters = $this->viewService->getParametersToFilterMobile($id, $viewFilters, $linkRewrite, $href);
$codeJs = Tools::createCategoryFilters($jsParameters);
$this->addJs($this->viewService->addFilterMobileJs($codeJs));
$viewVars = $this->viewService->generateVarsMobileFilter($viewFilters);
$this->headerClass = 'fullContent';
$viewVars['redirect'] = $linkRewrite;
$viewVars['domain'] = 'messages';
$viewVars['languageIsoCode'] = $isoCode;
$viewVars['rendered_twig_template'] = $this->twig->render('front/shop_b2b/mobile/filter_mobile.html.twig', $viewVars);
$this->setView('filterMobile', $viewVars);
}
/**
* @deprecated moved to new architecture
*/
public function ajax_show_bigstocks_products(): void
{
$init = Tools::getValue('init');
$limit = Tools::getValue('limit');
$filters = Tools::getValue('filters', []);
$type = Tools::getValue('type');
$isMobile = Tools::getValue('mobile');
Session::set('filters', $filters);
$filters['bigStocks'] = 1;
$filters['excludeCategory'] = [ViewService::EROTIC_SEX_CATEGORY_ID];
$results = Tools::getResultsElasticSearch(
Session::get('lang'),
$init,
$limit,
$this->ajax,
$filters,
Session::get('is_wholesaler')
);
$numberProducts = $results['total_results'];
$resultProds = $results['result'];
if ($numberProducts === false) {
$numberProducts = 0;
}
$nextInit = $init + $limit;
$nextCallNum = $limit;
if ($numberProducts - $nextInit < $limit) {
$nextCallNum = $numberProducts - $nextInit;
}
$show = true;
if ($numberProducts <= $nextInit) {
$show = false;
}
$this->setDisplayFooter(false);
$this->setDisplayHeadAndHeader(false);
$numProductsPaginator = ($numberProducts > tools::MAX_LIST_PRODUCTS) ? tools::MAX_LIST_PRODUCTS : $numberProducts;
if ($isMobile) {
$this->setJsonArgs(['num_products' => $numberProducts]);
$this->setJsonResponse(true);
} else {
$this->setJsonArgs([
'init' => $nextInit,
'show' => $show,
'next_call_num' => $nextCallNum,
'num_products' => $numberProducts,
'num_products_paginator' => $numProductsPaginator,
'ga_productlist' => [],
]);
$this->setJsonResponse(true);
if (empty($resultProds)) {
$resultProds = 'not_display';
}
if ($type === 0) {
$vars = [
'_partials0' => $resultProds,
];
$this->setView('ajax-product-list', $vars);
} else {
$vars = [
'_layout0' => [
'_partials0' => $resultProds,
],
];
$this->setView('ajax-product-list-sliders', $vars, 'ajax-product-list-full');
}
}
}
/**
* @deprecated moved to new architecture
*/
public function ajax_show_new_products(): void
{
$init = Tools::getValue('init');
$limit = Tools::getValue('limit');
$filters = Tools::getValue('filters', []);
$type = Tools::getValue('type');
$isMobile = Tools::getValue('mobile');
Session::set('filters', $filters);
$filters['dateAddFrom'] = \strtotime('-14 days');
$sexAndSensualityTaxonomyId = 17088;
$eroticClothesTaxonomyId = 16630;
$filters['excludeTaxonomy'] = [$sexAndSensualityTaxonomyId, $eroticClothesTaxonomyId];
$results = Tools::getResultsElasticSearch(
Session::get('lang'),
$init,
$limit,
$this->ajax,
$filters,
Session::get('is_wholesaler')
);
$numberProducts = $results['total_results'];
$resultProds = $results['result'];
if ($numberProducts === false) {
$numberProducts = 0;
}
$nextInit = $init + $limit;
$nextCallNum = $limit;
if ($numberProducts - $nextInit < $limit) {
$nextCallNum = $numberProducts - $nextInit;
}
$show = true;
if ($numberProducts <= $nextInit) {
$show = false;
}
$this->setDisplayFooter(false);
$this->setDisplayHeadAndHeader(false);
$numProductsPaginator = ($numberProducts > tools::MAX_LIST_PRODUCTS) ? tools::MAX_LIST_PRODUCTS : $numberProducts;
if ($isMobile) {
$this->setJsonArgs(['num_products' => $numberProducts]);
$this->setJsonResponse(true);
} else {
$this->setJsonArgs([
'init' => $nextInit,
'show' => $show,
'next_call_num' => $nextCallNum,
'num_products' => $numberProducts,
'num_products_paginator' => $numProductsPaginator,
'ga_productlist' => [],
]);
$this->setJsonResponse(true);
if (empty($resultProds)) {
$resultProds = 'not_display';
}
if ($type === 0) {
$vars = [
'_partials0' => $resultProds,
];
$this->setView('ajax-product-list', $vars);
} else {
$vars = [
'_layout0' => [
'_partials0' => $resultProds,
],
];
$this->setView('ajax-product-list-sliders', $vars, 'ajax-product-list-full');
}
}
}
/**
* @deprecated moved to new architecture
*/
public function ajax_show_new_stock(): void
{
$init = Tools::getValue('init');
$limit = Tools::getValue('limit');
$filters = Tools::getValue('filters', []);
$type = Tools::getValue('type');
$isMobile = Tools::getValue('mobile');
Session::set('filters', $filters);
$date = new \DateTime('-10 days');
$filters['dateBackInStock'] = $date->getTimestamp();
$results = Tools::getResultsElasticSearch(
Session::get('lang'),
$init,
$limit,
$this->ajax,
$filters,
Session::get('is_wholesaler')
);
$numberProducts = isset($results['total_results']) ? $results['total_results'] : 0;
$resultProds = isset($results['result']) ? $results['result'] : false;
if ($numberProducts === false) {
$numberProducts = 0;
}
$nextInit = $init + $limit;
$nextCallNum = $limit;
if ($numberProducts - $nextInit < $limit) {
$nextCallNum = $numberProducts - $nextInit;
}
$show = true;
if ($numberProducts <= $nextInit) {
$show = false;
}
$this->setDisplayFooter(false);
$this->setDisplayHeadAndHeader(false);
$numProductsPaginator = ($numberProducts > tools::MAX_LIST_PRODUCTS) ? tools::MAX_LIST_PRODUCTS : $numberProducts;
if ($isMobile) {
$this->setJsonArgs(['num_products' => $numberProducts]);
$this->setJsonResponse(true);
} else {
$this->setJsonArgs([
'init' => $nextInit,
'show' => $show,
'next_call_num' => $nextCallNum,
'num_products' => $numberProducts,
'num_products_paginator' => $numProductsPaginator,
'ga_productlist' => [],
]);
$this->setJsonResponse(true);
if (empty($resultProds)) {
$resultProds = 'not_display';
}
if ($type === 0) {
$vars = [
'_partials0' => $resultProds,
];
$this->setView('ajax-product-list', $vars);
} else {
$vars = [
'_layout0' => [
'_partials0' => $resultProds,
],
];
$this->setView('ajax-product-list-sliders', $vars, 'ajax-product-list-full');
}
}
}
/**
* @deprecated moved to new architecture
*/
public function ajax_show_best_seller_products(): void
{
$init = Tools::getValue('init');
$limit = Tools::getValue('limit');
$filters = Tools::getValue('filters', []);
$type = Tools::getValue('type');
$isMobile = Tools::getValue('mobile');
Session::set('filters', $filters);
$filters['minRecentSales'] = 20;
$results = Tools::getResultsElasticSearch(
Session::get('lang'),
$init,
$limit,
$this->ajax,
$filters,
Session::get('is_wholesaler')
);
$numberProducts = $results['total_results'];
$resultProds = $results['result'];
if ($numberProducts === false) {
$numberProducts = 0;
}
$nextInit = $init + $limit;
$nextCallNum = $limit;
if ($numberProducts - $nextInit < $limit) {
$nextCallNum = $numberProducts - $nextInit;
}
$show = true;
if ($numberProducts <= $nextInit) {
$show = false;
}
$this->setDisplayFooter(false);
$this->setDisplayHeadAndHeader(false);
$numProductsPaginator = ($numberProducts > tools::MAX_LIST_PRODUCTS) ? tools::MAX_LIST_PRODUCTS : $numberProducts;
if ($isMobile) {
$this->setJsonArgs(['num_products' => $numberProducts]);
$this->setJsonResponse(true);
} else {
$this->setJsonArgs([
'init' => $nextInit,
'show' => $show,
'next_call_num' => $nextCallNum,
'num_products' => $numberProducts,
'num_products_paginator' => $numProductsPaginator,
'ga_productlist' => [],
]);
$this->setJsonResponse(true);
if (empty($resultProds)) {
$resultProds = 'not_display';
}
if ($type === 0) {
$vars = [
'_partials0' => $resultProds,
];
$this->setView('ajax-product-list', $vars);
} else {
$vars = [
'_layout0' => [
'_partials0' => $resultProds,
],
];
$this->setView('ajax-product-list-sliders', $vars, 'ajax-product-list-full');
}
}
}
public function remove_filters()
{
Tools::remove_filters();
}
public function deleteSessionFilters()
{
Session::set('filters', false);
}
public function popupConfirmCsvListDownload()
{
$this->setDisplay_only_view(true);
$args = [
'title' => $this->l('Descarga de CSV de productos', 'categoryController'),
'msg' => $this->l('Para asegurar un buen rendimiento, el CSV que vas a descargar mostrará un máximo de 1.000 referencias. Te recomendamos ajustar el filtro para reducir el total de referencias.', 'categoryController'),
'icon' => 'draw_warning',
'actions' => [
[
'action' => 'submitAction',
'text' => $this->l('Descargar CSV', 'categoryController'),
'type' => 'button',
'icon' => '',
],
[
'action' => 'close',
'text' => $this->l('Volver', 'categoryController'),
'icon' => 'fa-chevron-left',
'type' => '',
],
],
];
$this->setView('popupOrderRepeat', $args);
}
}