I'm new to Prestashop, I cant find examples anywhere of how to get the current cart contents. I can get a list of all carts, but how do I get the current users cart?
it is easy and simple. I am considering you are using PS 1.5.x
In controllers other than cart controller
$cart = new Cart($this->context->cookie->id_cart);
or in an class
$context = new Context();
$cart = new Cart($context->cookie->id_cart);
Now the $cart is an object, and it has all the current cart data.
You can also get the cart products by calling getProducts like below
$cartProducts = $cart->getProducts();
Hope this will help.
Please note that code is not tested and is just a sample code for your idea.
Thank you
For PS 1.4.X you can get using getProducts()
$product_array = $this->getProducts();
print_r($product_array);
Example :
public function getSubTotal() {
$product_array = $this->getProducts();
foreach($product_array as $product_item) {
$sub_total += $product_item['price'] * $product_item['cart_quantity'];
}
return $sub_total;
}
Related
I'm pretty new to business central so excuse me if this is a rather stupid question. I have been trying to make a button that sends the user to a page where he can see products that are new or old.
A product has a field named "Status" which can have the values "New", "Old", "SoldOut" or "BeingDelivered".
So my question is how do I set the filter to only show products that are either "New" or "Old". I got this so far which only shows products that are "New" but I can't figure out how to show "New" OR "Old" ones.
Group(group1)
{
Action(testAction)
{
ApplicationArea = All;
Caption = 'TestAction';
RunObject = page Products;
RunPageLink = Status = const("New");
}
}
I have been trying to find a solution and tried a bunch of different approaches but couldn't figure much out. Any help is really appreciated.
Little Edit:
Here is an example of what I would ideally want which obviously doesnt work though.
Group(group1)
{
Action(testAction)
{
ApplicationArea = All;
Caption = 'TestAction';
RunObject = page Products;
RunPageLink = Status = const("New|Old");
}
}
Thanks for your time and effort!
Use filter instead of const
Cheers
I have a task: create a custom admin page in Sitecore to show FULL order history. I found a way to get order history per visitor, but couldn't find anything to get a full list of orders.
To get an order list per visitor we can use method
public virtual GetVisitorOrdersResult GetVisitorOrders(GetVisitorOrdersRequest request);
from class Sitecore.Commerce.Services.Orders.OrderServiceProvider
and assembly: Sitecore.Commerce
I think we can get all users and after that get orders for each user. However, I don't think that it is a best way to solve the task. I will appreciate if you advice any other way to get all data.
Thank you in advance for the help.
P.S. I am using Sitecore 8.
I think I found the solution
var contextManager = new CommerceServerContextManager(); //using Sitecore.Commerce.Connect.CommerceServer;
OrderManagementContext orderManagementContext = contextManager.OrderManagementContext;
var orderManager = orderManagementContext.PurchaseOrderManager;
CultureInfo culture = new CultureInfo("en-US");
DataSet searchableProperties = orderManager.GetSearchableProperties(culture.ToString());
SearchClauseFactory searchClauseFactory = orderManager.GetSearchClauseFactory(searchableProperties, "PurchaseOrder"); //using CommerceServer.Core; Assembly CommerceServer.Core.CrossTier
SearchClause searchClause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.OnOrAfter, "Created", StartDate);
SearchOptions options = new SearchOptions();
options.SetPaging(10, 1);
var result = orderManager.SearchPurchaseOrders(searchClause, options);
Might be useful for somebody else.
hi i have installed opencart extension tell a friend everything is good but email is not sending rest all emails when customer register and purchased are sending tell me the reason
here is the extension link also
http://www.opencart.com/index.php?route=extension/extension/info&extension_id=4348&filter_search=tell%20a%20friend
If some one has used this one please tell me
some time Opencart not work with emails on models. you need to put your logic in controller to fix this issue.
here is the solution:
get all value in your Opencart controller function and put Email logic init something like this.
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender($this->request->post['name']);
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8')));
$mail->send();
I have millions of items in the database. And user can search those items based on the keyword. In the search function, I need to provide a feature that search for NOT that keyword.
For example Item A has a field called msg and the value is Sitecore is awesome and great.
In the search box, user can check the checkbox that indicates to show any item that doesn't contain the keyword. Maybe user key in is keyword, so Item A will not be displayed or retrieved by ADC.
Edit: Currently I'm using sitecore6.6, thus Search method has been deprecated. I have tried the Not keyword by using Occurrence.MustNot, but it doesn't return any result.
The Sitecore Advanced Database Crawler is an extension of the Sitecore.Search API and Sitecore.Search API is a wrapper around Lucene.
In Lucene you can user queries with NOT or - to exclude something like "Sitecore NOT awesome" or "Sitecore -awesome".
To exclude something you need at least one include term.
Not sure if it works, but give it a try.
This is untested, but you might have luck by using a MatchAllDocsQuery and supplying the keywords in the form of a Filter.
BooleanQuery booleanQuery = new BooleanQuery();
QueryParser queryParser = new QueryParser("msg", new StandardAnalyzer());
Query userQuery = queryParser.Parse("Sitecore is awesome and great");
booleanQuery.Add(userQuery, reverseQuery.Checked ? BooleanClause.Occur.MUST_NOT : BooleanClause.Occur.MUST);
MatchAllDocsQuery matchAllQuery = new MatchAllDocsQuery();
Filter filter = new QueryFilter(booleanQuery);
using (QueryRunner queryRunner = new QueryRunner("myIndex"))
{
var skinnyItems = queryRunner.RunQuery(matchAllQuery, filter, ...)
}
What I have done to NOT include the keywords associated with the result item set is this:
protected List<Item> getSearchResults(string queryToSearch, string selectedFilter, string notToSearch)
{
Database db = Sitecore.Context.Database;
var index = SearchManager.GetIndex("siteSearchIndexName");
using (SortableIndexSearchContext context = new SortableIndexSearchContext(index))
{
if (!String.IsNullOrWhiteSpace(query))
{
query.ToLower();
CombinedQuery cq = new CombinedQuery();
QueryBase qbKeyword = new FieldQuery("_orderkeywordpair", query);
QueryBase qbContent = new FieldQuery("_content", query);
QueryBase qbHtml = new FieldQuery("html", query);
if (!String.IsNullOrWhiteSpace(selectedFilter) && selectedFilter.ToLower() != "all")
{
QueryBase qbFilter = new FieldQuery("_pagetype", selectedFilter);
cq.Add(qbFilter, QueryOccurance.Must);
}
cq.Add(qbKeyword, QueryOccurance.Should);
cq.Add(qbContent, QueryOccurance.Must);
cq.Add(qbHtml, QueryOccurance.MustNot);
SearchHits hits = context.Search(cq);
I am trying to create an EventReceiver for a blog site (for the Posts list) and am having some trouble getting it working. I want to change the Created By column to Anonymous. Basically I have this whole thing working in a console application, however, that will only change the Created By column names when the console application is executed.
I need it to change the Created By whenever a new item is added to the list. My code is below....how do I modify this to use in an EventReceiver project??? Since I already tell the EventReceiver project the URL I want the EventReceiver attached to, I'm not sure what I can remove from this code, right now it just doesn't do anything, no error and no changing of the Created By column when I debug.
using (SPSite site = new SPSite("http://test-sharepoint/subsite/"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Posts"];
SPListItemCollection listItemCollection = list.Items;
foreach (SPListItem listItem in listItemCollection)
{
SPFieldUserValue userName = new SPFieldUserValue(web, 22, "Anonymous");
listItem["Author"] = userName;
listItem["Editor"] = userName;
listItem.Update();
}
web.Update();
}
}
EDIT: Code is in ItemAdded method
EDIT #2: This is trying the same code except without the loop and using properties.ListItem, this was my attempt in a Event Recevier project but no luck. It just doesn't change the Created By field, or any field for that matter (I tried the Title as well)
SPSite site = new SPSite("http://test-sharepoint/subsite/");
SPWeb web = site.OpenWeb();
SPFieldUserValue userName = new SPFieldUserValue(web, 22, "Anonymous");
properties.ListItem["Author"] = userName;
properties.ListItem["Editor"] = userName;
properties.ListItem.Update();
*Also from my understanding the SPFieldUserValue will grab either a User or a SharePoint User Group (Permissions) so in my code, the 22 grabs the SharePoint User Group that I want and "Anonymous" is the user from that group...
EDIT #3: More progress, this code works without issues for a list, however, not for the Posts or Comments lists, for those it does not change the Created By field. Could it be because of the approve/reject for all items??? Whether approved orpending it still does not show annonymous, BUT like I mentioned, it works fine in a different list.
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPSite site = new SPSite("http://test-sharepoint/hr/blog/"); //SPContext.Current.Site;
SPWeb web = site.OpenWeb();
SPFieldUserValue userName = new SPFieldUserValue(web,22,"Anonymous");
SPListItem currentItem = properties.ListItem;
//currentItem["Title"] = userName; //DateTime.Now.ToString();
currentItem["Author"] = userName;
currentItem["Editor"] = userName;
currentItem.SystemUpdate();
}
**EDIT #4: Alright I found my issue, when creating the project I chose Custom List as my list to attach to but I needed to choose Posts or Comments and now the above code works!!!
But now I have another problem, all posts on the blog are first submitted for approval...and due to this the event receiver doesn't seem to work for users other than the admin. It works fine for the admin account where I can just directly publish a post or comment but for a user with Contribute permissions whose posts are submitted for approval still shows their name on the Manage Posts page...what could I do about this? Any ideas?**
The code that works:
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPSite site = new SPSite("http://test-sharepoint/hr/blog/"); //SPContext.Current.Site;
SPWeb web = site.OpenWeb();
SPFieldUserValue userName = new SPFieldUserValue(web, 23, "Anonymous");
SPListItem currentItem = properties.ListItem;
currentItem["Author"] = userName;
currentItem["Editor"] = userName;
currentItem.SystemUpdate();
}
In response to edit #4, when working with SharePoint, if code works when executed by the administrator account, but does not work when executed by a "normal" account, permissions are likely to blame.
See the answer to the question SharePoint/WSS: Modify “created by” field? for an example of an SPItemEventReceiver that modifies the Author field.
Note: Many SharePoint developers recommend against the use of RunWithElevatedPrivileges and suggest using impersonation instead. See my answer to the question In which situation use SPSecurity.RunWithElevatedPrivileges with superusertoken? for more details.