I'm trying to do in Prestashop 1.7 math operation between two smarty variables inside product-discounts.tpl but result is wrong...
{$product.regular_price}
[output: 12,85 €]
{$quantity_discount.discount}
[output: 9.8%]
{$product.regular_price*$quantity_discount.discount}
[output: 117,6] Should be: 12.85*9.8= 125.93
Any idea?
I've tryed:
{$product.regular_price|floatval}
[output:12] Should be: 12.85
Thanks in advance
Prestashop 1.7
Actually, this is happening because of comma in price 12,85 €, so, if you replace the comma with dot then you will get a correct value 125.93
I think the easiest solution would be by assigning a new variable in tpl file and replace the comma from the regular_price 12,85 with a dot.
By the way, you could also replace comma with dots from the controller but if you want to perform mathematical operations within the template file you could do it like this:
Firstly, assign {$product.regular_price} to regularPrice variable along with replacing comma with dot, something like this:
{assign var=regularPrice value=$product.regular_price|replace:',':'.'}
I hope $quantity_discount.discount always contains dot but if there is also a comma instead of dot then,
{assign var=quantityDiscount value=$quantity_discount.discount|replace:',':'.'}
and, last thing you have to do is multiple both variables regularPrice and quantityDiscount with each other
{assign var=total_price value=$regularPrice * $quantityDiscount}
then display total_price in tpl file like this:
{$total_price}
You can use the following
{$product.regular_price_amount*$quantity_discount.discount}
regular_price is used for price display.
If you want to do some mathematical calculation then you can use the regular_price_amount value of the product.
Related
I am using product tags as a way to filter what users see depending on if they are commercial or consumer customers. I have managed to get the tags into the class of each product displayed in a collection using the following code. The {{itemTags}} is being used to pass the value over into the HTML.
itemHtml = itemHtml.replace(/{{itemTags}}/g, data.tags);
<div class="{{itemTags}}">
The only issue is that all of the tags are displayed in a string with no spaces and commas in between each one. Resulting in the following class being added as an example.
class="accessories,Consumer,DJI Air 2S,live,pre-order,preorder"
Is it possible to remove the commas and add spaces in between each tag?
use the replace tag in liquid
itemHtml = itemHtml.replace(/{{itemTags | replace: "," , " " }}/g, data.tags);
Hi i am trying to scrap e-commerce page, but cant get prices.
I have page with this lines:
<span class="price">255,<sup>99</sup>€</span>
<span class="price">255 €</span>
But i can't extracts all price to one line.
I tried:
response.xpath('//span[#class="price"]/text()').extract()
But it ignores text in <sup> tag...
What i am doing wrong? please help.
You need to add another slash before text. So it addresses ALL nodes.
response.xpath('//span[#class="price"]//text()').extract()
Text='255,'
Text='99'
Text='€'
You should put double splash instead of single one.
response.xpath('//span[#class="price"]//text()').extract()
This statement returns all text under the specified tag as list object.
Note that the returned list may have some useless elements just like empty or return carriage character.
So you can use regex if you want extract only price information.
response.xpath('//span[#class="price"]//text()').re(r'[\d.,]+')
The currency symbol was ignored.
['255,','99','255']
Finally if you want get 255.99 from the page
''.join(response.xpath('//span[#class="price"][1]//text()').re(r'[\d.,]+')).replace(",",".")
You get all products first.
Final code:
products = response.xpath('//*[#class="catalog-table"]//td')
for prod in products:
price = ''.join(prod.xpath('//span[#class="price"][1]//text()').re(r'[\d.,]+')).replace(",",".")
print price
Check source HTML. There is in the source:
I was searching for the same question for the whole day and find this answer perfect for this
response.xpath('//meta[#itemprop="price"]/#content').get()
my variants title is “pack/4 bottles:4/PK”
“4/PK” is needed for shipping company to catch specific item.
However, it looks ugly when "4/PK" is displayed on page
Is there a way to hide it? Which liquid template should i touch?
Should I use
{{variant.title|move:'4/PK'}}
where should i put this code?
While this sounds more like something that should be assigned as an option for your variants instead of in the title, you can hide the part of the variants title that you don't want via using split and first
https://help.shopify.com/themes/liquid/filters/string-filters#split
split can be used to split a string (in this case your variant.title) into an array based on a set delimiter to divide it.
So you could do something only the lines of
{{variant.title | split: ':' | first }}
In your case, the output of the above would be: pack/4 bottles.
As for which liquid templates you will need to edit this into ... it will depend on your store. However some common areas would be:
product.liquid
cart.liquid
I highly recommend you read the the shopify liquid documents Here
Also, make sure to make a backup theme before doing any liquid changes in your theme that you are unsure of.
Hope this helps!
So I am currently doing a custom WHMCS template that uses the smarty template system. One of the calls is as follows:
{$customfield.input|replace:'>':'placeholder="Placeholder' >'}
Now this works in that it sets the placeholder with the text Placeholder. What I am trying to achieve is to get the following variable inside where the Placeholder text is:
{$customfield.name}
So I need something like the following:
{$customfield.input|replace:'>':'placeholder="{$customfield.name}" >'}
but that doesn't work.
Is this possible?
Correct way to do it
{$customfield.input|replace:'>':"placeholder='`$customfield.name`' >"}
Drop the braces around the second variable:
{$customfield.input|replace:'>':'placeholder="{$customfield.name|escape:html}" >'}
How to validate a Single line of text column type of list in sharepoint 2010 to enter accept only numbers?
Please don't tell me to use calculated column , I tried it and it didn't work for me as i want.
Please advice, thanks in advance.
This should work:
=ISNUMBER([MyColumn]+0)
Here is what seems to work for me (building on #Rob_Windsor; newlines added for readability):
=AND(
ISNUMBER(Number+0),
ISERR(FIND(".",Number)),
ISERR(FIND(",",Number)),
ISERR(FIND("$",Number)),
ISERR(FIND("+",Number)),
ISERR(FIND("-",Number)),
ISERR(FIND(" ",Number))
)
I went through the available functions and I don't see one that will validate whether a text value is a number.
BTW, is there a reason you are not using a Number field instead of a Single line of text?