Select new products by hand on PrestaShop - prestashop

PrestaShop v. 1.7.6 shows new products on homepage which are added to shop in last X days. But usually, this doesn't work for my clients, because they want to select them by hand. There are a lot of new products and only a few have to be promoted.
How it is possible to let the client Select which products will be in section "New" on the homepage and these products also should have LABEL "NEW" in categories listing everywhere in the shop, as it is by default for new products in PrestaShop.

New products are selected automatically by PrestaShop.
By default, all products you add are considered to be New. You may change number of days during which your products is considered as New at
Shop Parameters -> Product Settings -> Number of days for which the product is considered 'new'
Then the only way to select the products considered as new is modifying the field date_add at table ps_product.

You can override module ps_newproducts to change the expected behavior.
I did that on one of my project. I have override the module for a manual selection of products to display, it's more simple

The simple way is to use the ps_featuredproducts module and change translations.
This module works by position and you can change position manually.

I created a new category "News" to select products by hand. So now I need to add label in listing and product page:
/catalog/_partials/miniatiures/product.tpl:
{block name='product_flags'}
<ul class="product-flags">
<!-- CUSTOM CODE -->
{foreach from=Product::getProductCategoriesFull($product.id_product) item=cat}
{if $cat.name== 'News' }
<li class="product-flag new">New</li>
{/if}
{/foreach}
<!-- / CUSTOM CODE -->
{foreach from=$product.flags item=flag}
<li class="product-flag {$flag.type}">{$flag.label}</li>
{/foreach}
</ul>
{/block}
/catalog/product.tpl:
{block name='product_flags'}
<ul class="product-flags">
<!-- CUSTOM CODE -->
{foreach from=Product::getProductCategoriesFull(Tools::getValue('id_product')) item=cat}
{if $cat.name== 'News' }
<li class="product-flag new">New</li>
{/if}
{/foreach}
<!-- / CUSTOM CODE -->
{foreach from=$product.flags item=flag}
<li class="product-flag {$flag.type}">{$flag.label}</li>
{/foreach}
</ul>
{/block}
To show these products in homepage I have used this FREE MODULE:
https://mypresta.eu/modules/front-office-features/featured-products.html

Related

How ps_linklist render footer link block?

I am having difficulty understanding how the module that deals with generating links in the prestashop footer was written. The module is the ps_linklist and inside it contains a view / template / hook / linkblock.tpl which should contain the code needed to generate the links. The problem is that the code is as follows:
{foreach $linkBlocks as $linkBlock}
<h3>{$linkBlock.title|escape:'html':'UTF-8'}</h3>
<ul>
{foreach $linkBlock.links as $link}
<li>
<a
id="{$link.id}-{$linkBlock.id}"
class="{$link.class}"
href="{$link.url|escape:'html':'UTF-8'}"
title="{$link.description|escape:'html':'UTF-8'}"
{if !empty($link.target)} target="{$link.target|escape:'html':'UTF-8'}" {/if}
>
{$link.title|escape:'html':'UTF-8'}
</a>
</li>
{/foreach}
</ul>
{/foreach}
But the generated html is different, it includes a lot of information that cannot be generated by this code, so it is impossible for me to understand how to change the column layout of this section ... how to make things easy complex ...
enter image description here

generate warning when button click odoo website

I want to generate a warning near ADDTOCART when the ADDTOCART button clicked on odoo website.
XML file:
<t t-if="website.get_promo_code_error(delete=False)">
<div class="card bg-danger text-white mt16">
<div class="card-header clearfix">
<span class="float-left"><t t-esc="website.get_promo_code_error()" /></span>
</div>
</div>
</t>
Controler:
request.session['error_promo_code'] = "Can not add"
return request.redirect("/shop/product/%s" % product.id)
model:
def get_promo_code_error(self, delete=True):
error = request.session.get('error_promo_code')
if error and delete:
request.session.pop('error_promo_code')
return error
In Odoo there is a default feature which provides on the website.
Goto Product -> Ecommerce tab -> there you find field Availability-> select this option
Show inventory below a threshold and prevent sales if not enough stock
It will allow you to add the Availability Threshold, Add your product stock value like 10.
When you go on the webshop and add more than 10 qty for the same product it will trigger the message near the add to cart button.

Right way of using asp-page and asp-route in asp.net core razor pages between _layout and index page

Below is the file structure
I have default Index page under Pages folder, which has layout as _LayoutHarman.cshmtl
Code : Pages/Shared/_LayoutHarman.chtml
header menu : pages are in subfolder.ie category folder in this case
<a asp-route-cat_slug="electronic" asp-page="./category/Index">Electronic</a>
<a asp-route-cat_slug="beauty-care" asp-page="./category/index" >Beauty Care</a>
<a asp-route-cat_slug="toy" asp-page="./category/index" >Toy</a>
footer menu : pages are on root folder
<a asp-page="./Contact" >Contact</a>
<a asp-page="./terms" >Terms</a>
<a asp-page="./privacy" >Privacy</a>
Code : Pages/category/Index.cshtml
#page "{cat_slug?}/{pageIndex:int?}"
#model bList.Pages.category.IndexModel
#{
}
<nav aria-label="Page navigation example">
<ul class="pagination text-center">
#if(Model.prev_no!=0){
<li><a asp-page="category" asp-route-cat_slug="#Model.cat_url" asp-route-pageIndex="#Model.prev_no"> Previous</a></li>
}
#if (Model.no_more_record != "YES")
{
<li><a asp-page="category" asp-route-cat_slug="#Model.cat_url" asp-route-pageIndex="#Model.next_no">Next</a></li>
}
</ul>
</nav>
Here Next/ previous button generate url as follow
https://localhost:8080/category/toy/1
https://localhost:8080/category/toy/2
https://localhost:8080/category/toy/3
respective on selected category
Issue : When i visit on category page and click on prev or next button and then try to click on link Contact,Terms,Privacy i.e (which is on _LayoutHarman.cshtml) or on header menu then href become blank.
Edited One:
Code: On _LayoutHarman.cshtml
HeaderMenu:
<a href="./category/toy" >toy</a>
Footer Menu
<a asp-page="./Contact" >Contact</a>
<a asp-page="./terms" >Terms</a>
Code: On Category/Index.html page
Prev</li>
Next
Now on Next/ Prev button click , header menu generates url as
https://localhost:44382/category/toy/category/toy hence error page occurs. but for footer menu contact/term/privacy works properly
I did reproduce your problem, you need to delete the point(.) in asp-page attribute in your _LayoutHarman.cshmtl.
Changed like this:
<a asp-route-cat_slug="electronic" asp-page="/category/Index">Electronic</a>
<a asp-route-cat_slug="beauty-care" asp-page="/category/index" >Beauty Care</a>
<a asp-route-cat_slug="toy" asp-page="/category/index" >Toy</a>
<a asp-page="/Contact" >Contact</a>
<a asp-page="/terms" >Terms</a>
<a asp-page="/privacy" >Privacy</a>
And you don't need to add asp-page="category" in Pages/category/Index.cshtml, just delete this attribute in this page.
Here is my test result:
Do you really need all this extra server side processing, asp-route-cat_slug asp-page?
Can't you just use plain old fashion HTML hyperlink? As for the dynamic parameters maybe you can set only them...
View category
Just an idea to think on...
Cheers

Display product thumbnails on category/section page?

I'm trying to display the thumbnail images of each product on category page in Stencil CLI - BigCommerce with the option to slide. The most logical thing to do was to take the snippet from product-view.html and just paste it in card.html, unfortunately, it was to easy to be true.
I've tried changing the handlebars multiple times and replacing the a href url, but still no luck.
<ul class="productView-thumbnails"{{#gt product.images.length 5}} data-slick='{
"infinite": false,
"mobileFirst": true,
"slidesToShow": 5,
"slidesToScroll": 1
}'{{/gt}}>
{{#each product.images}}
<li class="productView-thumbnail">
<a
class="productView-thumbnail-link"
href="{{getImage this 'product_size' (cdn ../theme_settings.default_image_product)}}"
data-image-gallery-item
data-image-gallery-new-image-url="{{getImage this 'product_size' (cdn ../theme_settings.default_image_product)}}"
data-image-gallery-zoom-image-url="{{getImage this 'zoom_size' (cdn ../theme_settings.default_image_product)}}">
<img class="lazyload" data-sizes="auto" src="{{cdn 'img/loading.svg'}}" data-src="{{getImage this 'productview_thumb_size' (cdn ../theme_settings.default_image_product)}}" alt="{{this.alt}}" title="{{this.alt}}">
</a>
</li>
{{/each}}
</ul>
Any ideas ? Thanks.
I believe it's not possible using handlebars helpers. according to documentation, product thumbnails is not assigned as global attributes. so it won't work if you copy the code to category template.

Prestashop subcategories menu inside a subcategory

I am trying to show the subcategories menu of prestashop categories inside all subcategories. By default you only can see the subcategories menu inside a category but you cant see the "brother" subcategories of a subcategory.
I think I only need to make this code to work inside a subcategory because this code works well inside a category:
{foreach from=$subcategories item=subcategory}
<li > <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}"
class="cat_name">{$subcategory.name|escape:'htmlall':'UTF-8'}</a>
</li> {/foreach}
Any ideas?
Thanks so much
as always i don't give you a full code, but i tell you how to do it.
in smarty you need to create a function that takes as param number of parent category,
and in this function you need to use Category::getChildren( $id_category );then in smarty you need only take a loop through the smarty function.
regards
and sorry for my English.
For to start i would have created a override file in /override/controllers/, named CategoryController.php
And add this:
<?php
class CategoryController extends CategoryControllerCore
{
public function displayContent()
{
// Get the global smarty object.
global $smarty;
// Get current category's parent.
$parent_category = new Category($this->category->id_parent, self::$cookie->id_lang);
// Get parent category's subcategories (which is current category's siblings, including it self).
$category_siblings = $parent_category->getSubCategories((int)self::$cookie->id_lang)
/* Assign your siblings array to smarty. */
$smarty->assign(
array(
"category_siblings" => $category_siblings
)
);
/* This we run the normal displayContent, but pass the siblings array to
category.tpl */
parent::displayContent();
}
}
?>
And in product-list.tpl file:
<ul>
{foreach from=$category_siblings item=elemento}
<li {if $category->id == $elemento.id_category}class="active"{/if}> {$elemento.name} </li>
{/foreach}
</ul>
via Get sibling categories in category.tpl for the current category in prestashop