[PrestaShop] Display a price & ‘Add to Cart’ in your product view block


Σ Sigma Hosting is mainly a video tutorial website

Σ Sigma Hosting is mainly a video tutorial website that make it easier for you to search within the transcript of videos for solutions of problems you might face during your journey in dealing with different webhosting companies. So, we are very sorry if the text is not well organized and we may work on it in the future but for now we hope you get the benefit mainly from the video then you may need to have a look on the transcript. Thanks for your understanding 🙂

hey everyone this is Nemo n in today's quick tip we will see how to add the product price as well as an add to cart button to the viewed products block in prestashop so the first thing we want to do is to assign the price variable in the modules PHP files since right now it's not enough to simply modify the template because there is no price assigned to it at all and for this I will use an override just to avoid my modification being raised on the next update so i will create a new folder inside override modules and i will call it block bude just making sure i'm not misspell en la beauté ok and inside it through my editor I will create a new PHP file so in my route override and modules block viewed ocala file block bude that PHP ok and I will open HP tags and this is going to be my main override file so I will start by adding my code class block be viewed override stands luck dude ok good now what I'll do is reach back to my route modules block viewed is a bit out of screen but that's here love you ok and I'll open up the main PHP file for the module and I will look for hook right column which is the method that assigns the list in this case and I want to copy the whole method ok so we'll copy this one and make sure you grab the one present in your file of course since this might be different and will just paste it in my override you now I will look for object name this one it's line 47 here am i override and right after this I want to sign my price so obj arrow price equals product will call a static method of the product class which is called get price static and will pass in the object ID okay now i am getting this price with tax so in case you wanted with that make sure you pass in false as second parameter okay alright so time to deal with the template i am using the default one here so the path to my models view is themes the fault bootstrap modules block bude and this is the template five-block view dot TPL now at this point um where to add the prize is entirely up to you so i will drop it right after the pret description i think so p class price and i'll use a function a helper function smarty has so convert price price equals viewed product product ro price all right let's say and see if it pops up no good and case it doesn't for you make sure you reach the back office and clear your cache since i am leaving it disabled while testing now for the next part and which is actually last step adding the add to cart button so here we go after the price in the template i will add an anchor tag and it's going to have a class named button Ajax under a score add underscore to Andrew or card and the restore button make sure it really has this class if you're using the Ajax card BTN we can dash the default okay then the href is going to be a bit complicated so pay attention link get page link and we need to get the card and then true with I believe this is I so sale i'm not mistaken i just learned it by heart so i will escape this or I could actually no I will just keep it simple okay h raf the link to the cart page okay then every it needs a rail equals no follow then well the title i will just use the language tag LS so l s equals add to cart then it's going to need for the HX card data ID product which is going to be the viewed i think it needs to be viewed product um arrow again ID and I will cast an integer pepck a slender so and ball good and then we're also going to pass in the data ID product attribute which is going to be 0 in this case ID product attribute is going to be 0 alright then inside the anchor tag I'm going to use a span and it will copy this add to cart okay at to cart if when you test this doesn't work you can simply open up product list TPL and copy the add to cart button from there and then change the variables from I think its product to viewed product in this case okay so i will refresh and here's my button now let's see if everything works yep good it does nice so we're done ok this is everything for today's video and if you're looking for the best hosting for your shop I recommend checking out a 2 hosting com where you can find the best value packages to host your prestashop website thanks for watching I will see you next time .

Video Discription

In this quick video tutorial, we will add the price, as well as an add to cart button, to the viewed products block in PrestaShop



Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button