How to Show/Display Product Cart Quantity in Product page using opencart 2.3 - opencart

I've searched and tried various approached using OC 2.3 .
I'm trying to display of individual product items already in cart on the Product page - any ideas?
Thanks

[![Current items Product in product page][2]][2]
Need to display how many items of individual product of current product page.
i entered code bellow but needs the value declared in controller i think.
<?php echo "CURRENT PRODUCT ITEMS IN CART: " . $products_quantity; ?>

i entered the bellow declaration in catalog/controller/product/product.php,
it works but only when there is a product in the cart.
foreach ($this->cart->getProducts() as $product) {
if ($product['quantity']) {
$products_quantity = $product['quantity'];
}
$data['products'] = array(
'products_quantity' => $product['quantity']
);
$data['products_quantity'] = $products_quantity;
}

Related

Is there an easy solution to export a filtered backendlist

I have a list with products and locations. I've created a filterdefinition and can filter products based on a location.
Now I want to export te filtered selection to print it to an pdf.
I've tried to acces the filtered items with the ajax framework, but can't find any information on how to retrieve the filtered id's.
My printhandler works fine, I only need to get the ID's of selected items in the filter.
scopes:
location:
label: Location
modelClass: XXX\xxxx\Models\Location
conditions: location_id in (:filtered)
nameFrom: location
As always, found a solution after asking for one;
Found a piece of code:
function getCurrentFilters() {
$filters = [];
foreach (\Session::get('widget', []) as $name => $item) {
if (str_contains($name, 'Filter')) {
$filter = #unserialize(#base64_decode($item));
if ($filter) {
//$filters[] = $filter;
array_push($filters, $filter);
}
}
}
return $filters;
}

Implementing SEO friendly URLs in Sitecore-uCommerce

I am implementing a default Sitecore-uCommerce SEO friendly URLs mechanics and I run into issues.
I looked into ItemResolver processor of uCommerce and I still do not understand how uCommerce sets the Sitecore Context Item. It seems like it uses an uCommerce Item's Guid for Sitecore.Context.Item. Somehow it is not the case, but I do not see the real Sitecore Item to be set as Context item. And uCommerce items do not have the layout details on them. Or am I wrong?
private ID FindSitecoreIdForProduct(int productId)
{
IRepository<Product> repository = ObjectFactory.Instance.Resolve<IRepository<Product>>();
Product product = repository.Get(productId);
if (product != null)
{
return new ID(product.Guid);
}
return ID.Null;
}
Then it makes
ID iD = this.FindSitecoreIdForProduct(productId);
if (iD == ID.Null)
{
return;
}
Context.Item = Context.Database.GetItem(iD);
I would like it to be a specific Sitecore Item with a rendering showing the product details. The URLs are of type
http://sitename.com/productdetailpage/productname/c-25/p-125
If you could just explain me how uCommerce gets to the real Sitecore Item and sets it as a Context.Item, I guess it will be enough for me.
You are on the right way.
They move the context item to other item. I didn't like how they deal with url, and I need other ProductResolver.
Ucommerce have products in his own db, and they created a dataProvider to bring products into Sitecore.
The Ucommerce products are located in Sitecore under /sitecore/uCommerce/Products .
The shops,category and subcategory are located under /sitecore/uCommerce/Store.
Please check this link to have a clean idea how ucommerce is dealing with url:
http://docs.ucommerce.net/ucommerce/v7.0/sitecore/working-with-nice-urls-in-sitecore.html
I also have the same issue like you and I created a custom ItemResolver.
I defined processor in this way on httpRequestBegin pipeline.
<processor type="NameSpace.ProductResolver, Assembly" patch:instead="processor[#type='UCommerce.Sitecore.Pipelines.ItemResolver, UCommerce.Sitecore']"/>
I created in Sitecore a new template name ProductPage, I create a new item named Product of type ProductPage
My requirements was to have url like : /Shoes/Running/NIKEAIRZOOMPEGASUS33
When you browse to /category/subcategory/productid my productResolver is triggered.
I check if category,subcategory and product exist.
If they exist I set the current category and current product.
SiteContext.Current.CatalogContext.CurrentProduct=current_product;
//you need to check if product is in current category
I set my Context Item to be the Product item
var pathList = args.LocalPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).ToList();
var currentProduct= GetCurrentProduct(pathList);
// in above function I am getting the current product, checking if is correct category and subcategory
if (currentProduct != null)
{
SiteContext.Current.CatalogContext.CurrentProduct = currentProduct;
Sitecore.Context.Item = productItem;
}

Show Sharepoint incomplete surveys

I have created Sharepoint survey with "Page Separator" type questions. But, even I am farm admin, I am unable to view responses of an incomplete survey. I need to show total number of participant and how many of them complate survey, how many of them incomplete.
I have run this PowerShell. It does not work me, because $unPublishedEntries.Count is always zero
$unPublishedEntries.Count=0
$survey.ItemCount=56
$survey.Items.Count=3
$web = Get-SPWeb "http://portal.tracy.com/sites/GD/"
$survey = $web.lists["Survey"]
$unPublishedEntries = $survey.Items | ? {-not $_.HasPublishedVersion}
Write-Host "Surveys in list: " $survey.ItemCount
Write-Host "Of which entries are incomplete: " $unPublishedEntries.Count
Foreach ($entry in $unPublishedEntries)
{
Write-Host $entry["Author"]
}
Why I can not see (56-3) 53 users?
Also, I have run this query to check database
[sql query][1]
But, "tp_level = 255" shows deleted surveys too. If I try "tp_level = 1" it shows complated surveys, but it include deleted surveys too.
Is there any solution?
Hi you need to run sql query
This Solution work for me :
http://yasingokhanyuksel.blogspot.com.tr/2015/11/incomplete-surveys-in-sharepoint.html
Thanks

Getting current cart ID in prestashop

I am busy with a site built on Code Igniter that needs integration with Prestashop. In the site, when creating a user account, I save a "shop_id" to the database, which is then retrieved as a session variable when logging in.
I am using the Prestashop API to retrieve the customer successfully (using above "shop_id")
$xml = $this->PSWebService->get(
array('resource' => 'customers', 'id' => (int)$this->user['shop_id'])
);
This successfully returns the user in question, but there is no Cart IDs in this result.
Logging in to the back-end of my shop, I see that there are multiple carts associated with the logged in user.
My question is: How to I retrieve the LATEST cart ID using the API?
$userId = (int) $this->user['shop_id'];
$opt['resource'] = 'carts';
$xml = $this->PSWebService->get($opt);
$carts = $xml->carts->children();
foreach ($carts as $cart) {
$cartIds[] = $cart['id'];
}
for ($i = count($cartIds) - 1; $i > -1; $i--) {
$opt['id'] = $cartIds[$i];
$xml = $this->PSWebService->get($opt);
//since cart ids are descending the first found will be the latest
if ($xml->cart->id_customer == $userId) {
$latestCartId = $cartIds[$i];
break;
}
}
Kind of late, but I struggled a bit with this same problem and found a way to do it just from query, based on yenshirak's tip (since cart ids are descending the first found will be the latest).
I query the API directly using postman like this:
get all carts:
GET webserver/api/carts
get cart for customer:
GET webserver/api/carts?filter[id_customer]=1
get the most recent:
GET webserver/api/carts?filter[id_customer]=1&sort=[id_DESC]&limit=1
for a pretty print, you can also add params:
display=full&output_format=JSON
You can do this in php, I have not tested if the syntax is correct, but based on documentation it looks something like this:
$opt = array(
'resource' => 'carts',
'filter[id_customer]' => '[1]',
'sort' => '[id_DESC]',
'limit' => '1'
);
$xml = $webService->get($opt);

Prestashop api - How to get the current cart contents

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;
}