Developer forum

Forum » Rapido » Rapido development - Good practice questions

Rapido development - Good practice questions

Gaëtan Di Caro
Reply

Hello,

 

I'm trying to port some feature I had developped for a wrap solution to a Rapido solution. It is simply a paragraph which allows the user to input some product numbers and quantity all together in a textarea, then add all that to the basket. Now obviously I could just copy-paste what I have with very little change and that would work, but I'm actually interested in doing things right. I have read the rapido documentation about the development of new features, and while it was very interesting, it is quite abstract and I have trouble seeing how to integrate new stuff in practice.

Do I put my custom javascript (data processing of the input, behaviour after adding to basket) in custom.js, even though I will only need it on one page ? Or do I put it in a separate file like I'm used to ? Or something else ?

Cart.js doesn't have a method for addmulti. Do I add this method myself to the prototype in this file ? In custom.js ? In another file ? Should I extend the prototype at all ?

 

As an aside, it would be really nice to have a tutorial or webinar that whould go step by step in implementing some new simple feature to Rapido, so we can follow the philosophy behind.

 

Thanks.


Replies

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply

Hi Gaëtan

Thank you for the questions. Regarding adding the javascript to custom.js that will only be used on some pages. I agree, if we really, really want to save kb, that is not the best solution. But the thought behind it, on Rapido, is that it is ok as we are only adding very little data. Currently i think all the javascript on Rapido is around 71kb.

The gain here is that we get globally available and easy to maintain code.

Actually Cart.js has support for "add multi" The third parameter in Cart.UpdateCart can hold Dynamicweb cart commands. You do it like this:

Cart.UpdateCart('miniCart', URL_FOR_CART_PAGE, "&cartcmd=addmulti", true);

I hope we will be able to hold courses and webinars someday, and I now that it has been planned that we should have it. Currently my best suggestion, as you already did, is read the documentation. And even though we have tried to make everything as simple as possible to work with, you should always expect that there will be some kind of learning curve.

Do not hesitate to ask of you need clarification on something, also regarding the philosophy.

 

Best regards
Karsten Thuen

 
Gaëtan Di Caro
Reply

Thanks Karsten, it's a bit clearer !

My concern about the custom.js is more about maintaintability than weight. Here I don't need much so it's ok enough, but on some solutions I have some pretty hefty javascript and it adds up quickly. If I have to cram it all in one file it will be impossible to manage. Of course in that case I can simply add a reference to the specific script file in the template like I do now, but it's a bit too bad to not be able to piggyback on the way Rapido handles the javascript.

 

I'm looking forward to the webinars !

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply

Hi again

Yes, the custom.js is best for adding small chunks of custom js.

But great point. If that is the case, what I would do, is create a spreadsheet to keep track of my Rapido solutions. Here I would mark each site a level of customization. Throwing in a lot of javascript, should have a high level of customization. Then, in the spreadsheet I would write a comment on what I have changed in the default Rapido template. In this case the change would be that in Master.cshtml, you have added references for some included javascript files. 

Then, if someday, you want to upgrade Rapido, you would know that you will have to add the links to the master file after upgrading.

But then again, now that Handlebars is included, I do not see many cases where hefty javascript code should be needed. But I could be wrong. You are welcome to present the cases where you depend on this.

 

Best regards
Karsten Thuen

 
Gaëtan Di Caro
Reply

On a couple of our solutions we have configurators, which allows the customer to fully customize a product. Since it is quite complex that alone takes around 1000 lines of code in javascript.

Another example on many of our solution is a dealers or shops page, where the user can see a map with multiple markers and apply some search/filtering, that takes a couple of hundreds of lines.

 

We do mostly B2B, and there's always a lot of custom behaviour on the checkout or product page. But I'll definitely try to modify as little as possible on the Rapido templates. I'm thinking of making quite some use of the Include function in razor, so that most of my custom code stands in separate files.

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply

Thank you Gaëtan. That makes sense. The next release of Rapido will include a template for the Maps app in Dynamicweb. I think that may solve most of the map cases you may have. 

But it helps a lot to know how you are working with this. Then we can be better at improving Rapido to be better suited for the needs. 

@include is fine to use. Alternatively you could create a copy of the template and name it like this "Product.custom.cshtml", if you are going to customize. Then if you have updated Rapido you could compare "Product.cshtml" and "Product.custom.cshtml" and merge the changes. There are some online tools for that.

 

Best regards
Karsten Thuen

 
Gaëtan Di Caro
Reply

When is the custom.js minified ? I've added some code there to try but I can't see them appear in custom.min.js. I have enabled custom js in the website settings but the master page references the minified file.

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply

Hi

You can use this for compiling js in Visual Studio: https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebCompiler 

There may be some settings in a bundleconfig.json file that needs to be done for it to work.

 

Best regards
Karsten Thuen

 
Gaëtan Di Caro
Reply

Thanks, following Nikolai's post on another thread I installed the VS extention Web Essentials.

I'm a bit disappointed though, at first I had thought that Rapido would take care of all the bundling and minifying by itself, considering how much of it there is (for example on saving the website settings, the same way some stuff is generated now). It would be a really, really great thing to have because now it requires opening the solution in VS for every small change in the javascript.

 
Gaëtan Di Caro
Reply

I don't understand, I can't get the addmulti to work. Here is the url that is generated when I call the cart method :

mysolution.com/Default.aspx?ID=530&ProductLoopCounter1=1&ProductNumber1=225105&Quantity1=2&ProductLoopCounter2=2&ProductNumber2=225114&Quantity2=5&ProductLoopCounter3=3&ProductNumber3=225901&Quantity3=1&cartcmd=addMulti&feedtype=Counter

It is perfectly well formed, but nothing happens. If I call with a simple add command it works.

I have another solution which generates identical urls (from which I lifted my code) and it works fine there (9.3.8)

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Gaetano,

It looks like you are using ProductNumber instead of ProductID.

Maybe that is the difference?

Adrian

 
Gaëtan Di Caro
Reply

Hi Adrian,

I thought about that too but :

  1. I tried with productID and it didn't change anything
  2. it works on my other solution

 

You must be logged in to post in the forum