im trying to get the cart total from the checkout and once the users confirms the order, to add the total amount as reward points...
for an example lets say if someone purchases goods worth 245$ i want to add the 245 as reward points.. Can someone please let me know the best way to do this?
I noted that in opencart the reward points are saved in oc_customer_reward but i couldnt find the sql in the order model related to that.
Any help will be appreciated
There are lots of ways you could approach this - the easiest I can think of is in system/library/cart/cart.php (path depends on your version) change:
'reward' => $reward * $cart['quantity'],
to
'reward' => ($price + $option_price) * $cart['quantity'],
This way the rewards are passed to any other functions that rely on the cart data - including third party checkout extensions.
You can try the following edit for automatic insertion of points when adding products.
admin/view/template/common/header.tpl
find:
</head>
add before:
<script type="text/javascript">
$(document).ready(function(){
var product_reward = $("input[id=product_reward]");
$("input[name^='price'],input[name='name'],input[name^='information_description'],input[name^='category_description']").keyup(function(){
var autoPoints = $("input[name^='price'],input[name='name'],input[name^='information_description'],input[name^='category_description']").val();
autoPoints = autoPoints * 0.05;
product_reward.val(autoPoints);
});
});
</script>
Related
I am planning to implement a live autosearch complete function in django ! But, am belive that am over doing it, so need a suggestion:
Basically this search bar is located in a page, where all at first all the available data's are displayed as a list ! And then when user types something i filter it out using jquery autocomplete.
In the above, am making two queries one to get all data and another one on each user types
As this takes two query, i belive its inefficient
Here is my search function
def search_query(request):
if 'term' in request.GET:
qs = University.objects.filter(name__icontains=request.GET.get('term'))
names = list()
for data in qs:
names.append(data.name)
return JsonResponse(names, safe=False)
And the above is been called each time the user types in the search bar and this is my jquery autocomplete code:
<script>
$( function() {
$( "#tags" ).autocomplete({
source: "{% url 'students:search-query' %}" // this hits the above def
});
} );
</script>
Apart from this, am also making this to show full list as initial data,
def index(request):
univesity = University.objects.filter(published=True)
context = {'univesity': univesity}
return render(request, 'students/search/index.html', context)
is this right way or is there any effcient way ? Can both the queries be combined or please suggest a efficient solution ( approx 50,000 datas to be searched as of now, may increase )
First off, both queries are returning different data. The index returns only published universities while the search returns all.
There are two solutions to your problem. Either one should work. Go with whichever you're more comfortable with (i.e if you write only Python improve the query, if you prefer JS do it on the frontend)
Performing the search on the Frontend
Now since you're returning all the data to the frontend, you can simply give it all to Jquery's autocomplete as a source and let it all happen on the frontend itself.
This can simply be something like
<script>
var universities = [] // populated either via an API or HTML rendering
$( function() {
$( "#tags" ).autocomplete({
source: universities.map(uni => uni.name),
});
});
</script>
OR
<script>
var universities = [] // populated either via an API or HTML rendering
function filterUniversities(request, response) {
var filteredNames = universities.filter(uni => uni.name === request).map(uni => uni.name);
response(filteredNames);
}
$( function() {
$( "#tags" ).autocomplete({
source: filterUniversities,
});
});
</script>
In either case you first need to set the list of universities. Looking at your code I see that you're rendering the data so an API is out of the question. You can do something like
<script>
var universities = [{% for uni in universities %}{{ uni }}{% if not forloop.last %}, {% endif %}{% endfor %}]
</script>
You might need to replace the {{ uni }} part with appropriate code.
There is also something called json_script that I've never tried but might work better.
{{ universities|json_script:"university-data" }}
And then your script simply becomes
<script>
var universities = JSON.parse(document.getElementById('university-data').textContent);
$( function() {
$( "#tags" ).autocomplete({
source: universities.map(uni => uni.name),
});
});
</script>
The first one will slow down your initial render time since the frontend has to compute that list right at the start.
The second will make every search slow instead.
Of course both these delays are in ms and should be much lesser than making a call to the server.
Improving backend query
If you prefer to still keep the search async and call your search query method each time, you can increase the delay before auto complete makes the call. By default it waits 300ms after the user stops typing before making performing the search.
In terms of the actual query
def search_query(request):
term = request.GET.get('term')
if term:
names = list(
University.objects
.filter(name__icontains=request.GET.get('term'))
.values_list("name", flat=True)
)
return JsonResponse(names, safe=False)
The main changes here are:
We're fetching only the university names from the db. Each university might contain lots of data, fetching it all can be slow. If we fetch only what's needed it's much quicker.
We're casting the queryset to a list rather than building a new list with append. Doing append in a loop is the slowest way of creating a list. List comprehensions is much quicker, but in this case we don't even need that. Simply casting to a list is the quickest.
We've also taken the term into a variable and checked that. Not a huge speed gain but if the term is blank (i.e request.GET['term'] = '') we don't want to do the search. 50k rows shouldn't be a lot for any database.
If you still find that the db is too slow you will need to analyse your queries and see how it can be optimized. Some sort of index might be needed, but that is beyond the scope of this answer, and should mostly likely not be necessary.
I need to do a webpage to finish my uni, and im about 90% done with it, however, im struggling with getting custom Iterators and Charts to work.
Im trying to use Recharts, but i have no idea on how to make it gather the info i want (I need it to get the number of users registered and the number of vaccines they took), but all i see on the documentation is ready results, im not sure if ChartJS will make it any better, and even if it does, im confused on how custom iterators work since i took my "Analytics" one from another StackOverflow question, however that's the least of my worries, since this seems to be simplier than getting the ACTUAL charts to work.
Help would be appreciated since i have 2 weeks to deliver it and im stuck on that, and its CRUCIAL i get that to work.
Oh yes, im also very bad at Javascript so every info is welcome.
EDIT:Forgot to say i've looked around but lots of them are for simplier and static stuff instead of database counts or stuff like that.
Welcome to SO.
1) Recharts wants an array that it needs to iterate over and display. So what I usually do is make the Chart Component a child of a List component.
2) I use the Filter on the List page to select different chart components when the user selects different options from the dropdown (in case your analytics page needs to show different charts from the same page)
^^this is a bit tricky for peeps new to JS but is quite straightforward if you want to get into it.
3) For you i think the best bet will be that you make different List components and resources for each page and just display different charts on their own page.
export const AnalyticsList = (props) => {
return (
<List title="Analytics" {...props} perPage={20} sort={{ field: 'id', order: 'ASC' }}>
<Analytics />
</List>
)
}
here is how the Analytics Component is
import React from 'react';
import {BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend} from 'recharts';
export const Analytics = (props) => {
return (
<BarChart width={800} height={400} data={Object.values(props.data)} margin={{top: 5, right: 30, left: 20, bottom: 5}}>
<XAxis dataKey="name"/>
<YAxis dataKey="charLimit" />
<CartesianGrid strokeDasharray="3 3"/>
<Tooltip/>
<Legend />
<Bar dataKey="charLimit" fill="#82ca9d" />
</BarChart>
);
}
Hope this helps.
What I am trying to achieve is to find a way of displaying a wiki page content in a floating iFrame ( and of course keep the styling ) for a tool that I am developing for our employees. Right now the tool I made is using jQuery dialog box to display a specific document / pdf, For compatibility and usability purposes I would really like to upgrade that so it uses a wiki page instead of documents / PDFs.The problem that I am facing is that there is no really direct link to the content of a Sharepoint wiki page instead the only available direct link is the one to the page all together with all the navigation menus, option panel, user panel etc. I want to avoid using javascrip to strip away these elements. Instead I am simply trying to find out if sharepoint 2013 has some more elegant way of providing the content such as: Web service or javascript SP API.
My ideas so far:
REST Url to give the content back? I know for sure it works for lists and libraries but I couldn't find anything in the REST API About wiki page content
SP.js ? Couldn't find anything about that either
Anyways, it could be possible that I have overlooked things, or probably haven't searched hard enough. However, any help is very very welcome. If you don't know about a concrete solution I would be very happy with nice suggestions too :)
If there is nothing out of the box I will have to get to my backup plan of a jQuery solution to get the page and strip off all unnecessary content and keep the styling.
I believe you are on the right track with REST API, in Enterprise Wiki Page the content is stored in PublishingPageContent property.
The following example demonstrates how to retrieve Enterprise Wiki Page content:
var getWikiPageContent = function (webUrl,itemId,result) {
var listTitle = "Pages";
var url = webUrl + "/_api/web/lists/GetByTitle('" + listTitle + "')/items(" + itemId + ")/PublishingPageContent";
$.getJSON(url,function( data ) {
result(data.value);
});
}
Usage
getWikiPageContent('https://contoso.sharepoint.com/',1,function(pageContent){
console.log(pageContent);
});
And something for those of you who like to have more than one different examples:
var inner_content;
var page_title = "home";
$.ajax({
url: "https://mysharepoint.sharepoint.com/MyEnterpriseWikiSite/_api/web/Lists/getbytitle('Pages')/items?$filter=Title eq '" + page_title +"'",
type: "GET",
headers: {
"ACCEPT": "application/json;odata=verbose"
},
success: function (data) {
if (data.d.results[0]) {
inner_content = data.d.results[0].PublishingPageContent;
}
},
error: function(){ //Show Error here }
});
That's what did the job for me.
This example fetches the inner content of an Enterprise wiki page by Title( make sure you are not using the Name of the page, although Title and Name can be given the same string value, they are different fields in sharepoint 2013 )
Am I able to load a custom template based on a condition?
eg..
If I was making a booking for a mechanic then the editor form would show textboxes for carmodel, yearmake etc.
If I was making a booking for a carpet cleaner the editor form would show textboxes for howmanyrooms, room sizes etc..
Am I able to pass an ID of a service and show the particular editor form for the correct service?
we can currently display this functionality if we create different scheduler Views but that would then create a duplication of many pages.
I had the exact same problem and after searching a long time and combining what I found, I came to this :
1) above my scheduler I have a kendodropdownlist
<input id="reservationPicker" />
<script>
$("#reservationPicker").kendoDropDownList({
dataTextField: "name",
dataValueField: "reservationDefTypeId",
dataSource: reservationPickerDataSource
});
</script>
2) my event has an extra field reservationDef which will hold the information of the dropdownlist.
3) I can use this information in my template
<script id="editorScheduler" type="text/x-kendo-template">
<center>
<div id="main">
#if(reservationDef=="mechanic"){#
<h3>Mechanic stuff</h3>
#}else if(reservationDef=="carpetCleaner"){#
<h3>Carpet Cleaner stuff</h3>
#}else{#
<h3>unknown type of reservation !</h3>
#: reservationDef #
#}#
</div>
</center>
</script>
4) I use this template in my scheduler
editable: {
template: $("#editorScheduler").html()
},
5) but what with a new appointment ! I use the add event of the scheduler and I fill in this information in the event
add: function (e) {
var reservationTypes = $("#reservationPicker").data("kendoDropDownList");
var selectedReservationType = reservationTypes.dataItem();
e.event.reservationDef = selectedReservationType.appointmentTitle;
},
This does the trick for me. Good luck !
No I didn't but I did find a work around by dynamically adding textboxes on the following page. To b able to choose a view model at runtime for the scheduler didn't seem possible
if anyone knows how to load a particular viewmodel at runtime using mvc would be very intresting for future ideas and development.
I'm building a website where college students can order delivery food. One special attribute about our site is that customers have to choose a preset delivery time. For example we have a drop at 7pm, 10pm, and at midnight.
All the information about the food is static (ie price, description, name), except the quantity remaining for that specific drop time.
Obviously i didn't want to hardcode the HTML for all the food items on my menu page, so i wrote a forloop in the html template. So i need to store the quantity remaining for the specific time somewhere in my model. the only problem is that I'm scared that if i use the same variable to transport the quantity remaining number to my template, i'll give out wrong information if alot of people are accessing the menu page at the same time.
For example, lets say the 7pm drop has 10 burritos remaining. And the 10pm drop has 40 burritos. Is there a chance that if someone has faster internet than the other customer, the wrong quantity remaining will display?
how would you guys go around to solve this problem?
i basically need a way to tell my template the quantity remaining for that specific time. and using the solution i have now, doesn't make me feel at ease. Esp if many people are going to be accessing the site at the same time.
view.py
orders = OrderItem.objects.filter(date__range=[now - timedelta(hours=20), now]).filter(time=hour)
steak_and_egg = 0
queso = 0
for food in orders:
if food.product.name == "Steak and Egg Burrito":
steak_and_egg = steak_and_egg + food.quantity
elif food.product.name == "Queso Burrito":
queso = queso + food.quantity
#if burritos are sold out, then tell template not to display "buy" link
quantity_steak_and_egg = max_cotixan_steak_and_egg - steak_and_egg
quantity_queso = max_cotixan_queso - queso
#psuedocode
steakandegg.quantity_remaining = quantity_steak_and_egg
queso.quantity_remaining = quantity_queso
HTML:
{% for item in food %}
<div id="food_set">
<img src="{{item.photo_menu.url}}" alt="" id="thumbnail photo" />
<div style='overflow:hidden'>
<p id="food_name">{{item.name}}</p>
<p id="price">${{item.price}}</p>
</div>
<p id="food_restaurant">By {{item.restaurant}}</p>
<div id="food_footer">
<img src="{{MEDIA_URL}}/images/order_dots.png" alt="" id="order_dots" />
<a id ="order_button" href="{{item.slug}}"></a>
<p id="quantity_remaining">{{item.quantity_remaining}} left</p>
</div><!-- end food_footer-->
</div><!-- end food_set-->
I don't understand what "faster Internet" or "using the same variable" have to do with anything here (or, indeed, what it has to do with sqlite particularly).
This question is about a fundamental property of web apps: that they are request/response based. That is, the client makes a request, and the server replies with a response, which represents the status of the data at that time. There's simply no getting around that: you can make it more dynamic, by using Ajax to update the page after the initial load, which is what StackOverflow does to show update messages while you're on the page. But even then, there's still a delay.
(I should note that there are ways of doing real-time updates, but they're complicated, and almost certainly overkill for a college food-ordering website.)
Now the issue is, why does this matter? It shouldn't. The user sees a page saying there is 1 burrito left - perhaps with a red warning saying "order quickly! almost gone!" - and they press the order button. On submission of that order, your code presumably checks for the actual status at that time. And, guess what, in the meantime you've processed another order and the burrito has already gone. So what? You simply show a message to the user, "sorry, it's gone, try something else". Anyone with any experience ordering things on the web - say, concert tickets - will understand what's happened.