I'd like get cart content on prestashop os-commerce. How can do it ?
You should take a look at the Cart class, located in classes/Cart.php. There's a method called getProducts().
/**
* Return cart products
*
* #result array Products
*/
public function getProducts($refresh = false, $id_product = false)
{
// code...
}
Hope this helps,
Br,
Simply use
Context::getContext()->cart
refer this link
https://www.prestashop.com/forums/topic/440516-how-to-get-all-product-ids-in-current-cart/
It's Working: Enjoy
in module hook you can use this:
$products = $params['cart']->getProducts(true);
If you are using a hook on Shopping Cart page you can use:
$products = $params['products'];
Related
I have customized my create order page and in that after selecting customer and store id I have information of the product(Ex product A), I want that after admin reaches the sales_order_create then there must be that product(Product A) in the 'Items Ordered' list by default.
Thanks in advance
One of the solutions is to add an observer for the event called "create_order_session_quote_initialized". In the observer you need to add something like this:
$session = $observer->getSession();
if ($session->getProductAdded()) {
return $this;
}
$product = Mage::getModel('catalog/product')->load($productId);
$session->getQuote()->addProduct($product);
$session->setProductAdded(true);
return $this;
It's not the exact code which already works. But I hope that this will help.
First we need to initialize the quote with product(Product A).
$quoteItem = Mage::getModel('sales/quote_item')
->setProduct($product)
->setQuote($this->getQuote())
->setQty($qty)
->setPrice($product->getPrice())
->save();
Convert this quote item to order item.
$orderItem = Mage::getModel('sales/convert_quote')
->itemToOrderItem($quoteItem)
->save($this->getOrder->getId());
I have a custom observer in Magento 1.8.1.0 that is called on Product view page when current product having any upsell products. I have verified (using Mage::log()) that the observer is working, however when I try the following:
public function updateUpsells(Varien_Event_Observer $oObserver)
{
$iCurrentCategory = Mage::registry('current_category')->getId();
$oUpsellCollection = $oObserver->getCollection();
foreach ($oUpsellCollection->getItems() as $key => $oUpsellProduct) {
$aCategoriesIds = $oUpsellProduct->getCategoryIds();
if (!in_array($iCurrentCategory, $aCategoriesIds)) {
$oUpsellCollection->removeItemByKey($key);
}
}
}
On echo $oUpsellCollection; i got nothing returned ?
Is anyone know how to get upsell products collection ? Is this a proper way to do it ?
$upsellCollection = $_product->getUpSellProductCollection();
I instanciate the following block by using the operator new but when I am going to use getProduct() it does not return anything because it doesn't have the ID of the product. How can I add it?
$block = new Mage_Catalog_Block_Product_View_Options();
Thanks in advance.
Try this:
$product_id = Mage::registry('current_product')->getId();
I'm on Magento 1.7.0.2. How can I print invoices from backend with the same manner that frontend uses? I want it to be on HTML format not PDF.
Assuming that you want to print one invoice at a time from the admin order detail page
Create a custom admin module
Add a controller with the method below
public function printInvoiceAction()
{
$invoiceId = (int) $this->getRequest()->getParam('invoice_id');
if ($invoiceId) {
$invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
$order = $invoice->getOrder();
} else {
$order = Mage::registry('current_order');
}
if (isset($invoice)) {
Mage::register('current_invoice', $invoice);
}
$this->loadLayout('print');
$this->renderLayout();
}
Reference printInvoiceAction() in app/code/core/Mage/Sales/controllers/GuestController.php
Then in your custom layout.xml use <sales_guest_printinvoice> in /app/design/frontend/base/default/layout/sales.xml as your template
Then add a button with link to the following url (need to get invoice id from order) /customModule/controller/printInvoice/invoice_id/xxx
(Not tested, so let me know if you run into any issues)
You should create your custom css file for printing print.css. And you should add "Print Button", that will call window.print()
I use this collecion to select the cms pages
$collection = Mage::getModel('cms/page')->getCollection()
->addFieldToFilter('is_active',1)
->addFieldToFilter('identifier',array(array('nin'=>array('no-route','enable-cookies'))));
How can I change it to select only the cms pages of the current store ?
Thanks a lot
Check the code below: ->addStoreFilter($store,$withAdmin)
$collection = Mage::getModel('cms/page')->getCollection()
->addStoreFilter($storeId)// You have to provide a store id or Mage_Core_Model_Store Object #see class Mage_Cms_Model_Mysql4_Page_Collection
->addFieldToFilter('is_active',1)
->addFieldToFilter('identifier',array(array('nin'=>array('no-route','enable-cookies'))));
If you do not need filters try this:
$cmsPage = Mage::getModel('cms/page')->setStore(Mage::app()->getStore()->getId())->load('faq-and-help', 'identifier');