Как сортировать продукты на основе цены в PrestashopPhp

Кемеровские программисты php общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Как сортировать продукты на основе цены в Prestashop

Сообщение Anonymous »

Мне нужно сортировать на основе цены на продукты низкую и высокую. />\modules \ProductScategory \ProductScategory.tpl

{if count($categoryProducts) > 0 && $categoryProducts !== false}

{$categoryProducts|@count} {l s='other products in the same category:' mod='productscategory'}

{if count($categoryProducts) > 5}[url=javascript:{ldelim}{rdelim}]{l s='Previous' mod='productscategory'}[/url]{/if}
{if count($categoryProducts) > 5}[url=javascript:{ldelim}{rdelim}]{l s='Next' mod='productscategory'}[/url]{/if}


$('#productscategory_list').trigger('goto', [{$middlePosition}-3]);


{/if}
< /code>

Функция в \ modules \ productscategory \ productscategory.php < /p>

public function hookProductFooter($params)
{

$idProduct = (int)(Tools::getValue('id_product'));
$product = new Product((int)($idProduct));

/* If the visitor has came to this product by a category, use this one */
if (isset($params['category']->id_category))
$category = $params['category'];
/* Else, use the default product category */
else
{
if (isset($product->id_category_default) AND $product->id_category_default > 1)
$category = New Category((int)($product->id_category_default));
}

if (!Validate::isLoadedObject($category) OR !$category->active)
return;

// Get infos
$categoryProducts = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
$sizeOfCategoryProducts = (int)sizeof($categoryProducts);
$middlePosition = 0;

// Remove current product from the list
if (is_array($categoryProducts) AND sizeof($categoryProducts))
{
foreach ($categoryProducts AS $key => $categoryProduct)
if ($categoryProduct['id_product'] == $idProduct)
{
unset($categoryProducts[$key]);
break;
}

$taxes = Product::getTaxCalculationMethod();
if (Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE'))
foreach ($categoryProducts AS $key => $categoryProduct)
if ($categoryProduct['id_product'] != $idProduct)
{
if ($taxes == 0 OR $taxes == 2)
$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], true, NULL, 2);
elseif ($taxes == 1)
$categoryProducts[$key]['displayed_price'] = Product::getPriceStatic((int)$categoryProduct['id_product'], false, NULL, 2);
}

// Get positions
$middlePosition = round($sizeOfCategoryProducts / 2, 0);
$productPosition = $this->getCurrentProduct($categoryProducts, (int)$idProduct);

// Flip middle product with current product
if ($productPosition)
{
$tmp = $categoryProducts[$middlePosition-1];
$categoryProducts[$middlePosition-1] = $categoryProducts[$productPosition];
$categoryProducts[$productPosition] = $tmp;
}

// If products tab higher than 30, slice it
if ($sizeOfCategoryProducts > 30)
{
$categoryProducts = array_slice($categoryProducts, $middlePosition - 15, 30, true);
$middlePosition = 15;
}
}

$best_sellers = $this->getBestSellers($params);
if ($best_sellers === false)
return;

$this->smarty->assign(array(
'best_sellers' => $best_sellers,
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'smallSize' => Image::getSize(ImageType::getFormatedName('small'))
));

$bundle_products = $this->bundleproduct($params);

$this->smarty->assign(array(
'bundle_products' => $bundle_products,
'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
'smallSize' => Image::getSize(ImageType::getFormatedName('small'))
));

$id_product = (int)Tools::getValue('id_product');
$productsViewed = (isset($params['cookie']->viewed) && !empty($params['cookie']->viewed)) ? array_slice(explode(',', $params['cookie']->viewed), 0, Configuration::get('PRODUCTS_VIEWED_NBR')) : array();

if (count($productsViewed))
{
$defaultCover = Language::getIsoById($params['cookie']->id_lang).'-default';

$productIds = implode(',', $productsViewed);
$productsImages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT image_shop.id_image, p.id_product, il.legend, product_shop.active, pl.name, pl.description_short, pl.link_rewrite, cl.link_rewrite AS category_rewrite
FROM '._DB_PREFIX_.'product p
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').')
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product)'.
Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
LEFT JOIN '._DB_PREFIX_.'image_lang il ON (il.id_image = i.id_image)
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
WHERE p.id_product IN ('.$productIds.')
AND pl.id_lang = '.(int)($params['cookie']->id_lang).'
AND cl.id_lang = '.(int)($params['cookie']->id_lang).'
GROUP BY product_shop.id_product'
);

$productsImagesArray = array();
foreach ($productsImages as $pi)
$productsImagesArray[$pi['id_product']] = $pi;

$productsViewedObj = array();
foreach ($productsViewed as $productViewed)
{
$obj = (object)'Product';
if (!isset($productsImagesArray[$productViewed]) || (!$obj->active = $productsImagesArray[$productViewed]['active']))
continue;
else
{
$obj->id = (int)($productsImagesArray[$productViewed]['id_product']);
$obj->id_image = (int)$productsImagesArray[$productViewed]['id_image'];
$obj->cover = (int)($productsImagesArray[$productViewed]['id_product']).'-'.(int)($productsImagesArray[$productViewed]['id_image']);
$obj->legend = $productsImagesArray[$productViewed]['legend'];
$obj->name = $productsImagesArray[$productViewed]['name'];
$obj->description_short = $productsImagesArray[$productViewed]['description_short'];
$obj->link_rewrite = $productsImagesArray[$productViewed]['link_rewrite'];
$obj->category_rewrite = $productsImagesArray[$productViewed]['category_rewrite'];
// $obj is not a real product so it cannot be used as argument for getProductLink()
$obj->product_link = $this->context->link->getProductLink($obj->id, $obj->link_rewrite, $obj->category_rewrite);

if (!isset($obj->cover) || !$productsImagesArray[$productViewed]['id_image'])
{
$obj->cover = $defaultCover;
$obj->legend = '';
}
$productsViewedObj[] = $obj;
}
}

if ($id_product && !in_array($id_product, $productsViewed))
{
// Check if the user to the right of access to this product
$product = new Product((int)$id_product);
if ($product->checkAccess((int)$this->context->customer->id))
array_unshift($productsViewed, $id_product);
}
$viewed = '';
foreach ($productsViewed as $id_product_viewed)
$viewed .= (int)($id_product_viewed).',';
$params['cookie']->viewed = rtrim($viewed, ',');

if (!count($productsViewedObj))
return;

$this->smarty->assign(array(
'productsViewedObj' => $productsViewedObj,
'mediumSize' => Image::getSize('medium')));
}

$this->smarty->assign(array(
'categoryProducts' => $categoryProducts,
'middlePosition' => (int)$middlePosition,
'ProdDisplayPrice' => Configuration::get('PRODUCTSCATEGORY_DISPLAY_PRICE')));

return $this->display(__FILE__, 'productscategory.tpl');
}
< /code>

Как сортировать продукты на основе цены?

Подробнее здесь: https://stackoverflow.com/questions/170 ... prestashop
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Php»