I am creating a custom module in Prestashop. In that module I want to get
the order details when a new order has been made on the store. So I want
to know which hook should I use and how to get new order details along with
customer details when a new order has been made. Any help and suggestions will be really appreciable.
Use a hook actionValidateOrder. Hook gives you params array which includes Order, Cart, Customer, Currency and OrderState objects associated with it.
With them you can now get customer and order details.
public function hookActionValidateOrder($params) {
$order = $params['order'];
$customer = $params['customer'];
$order_details = $order->getOrderDetailList();
}
Hook needs to be registered in module install.
public function install() {
return parent::install && $this->registerHook('actionValidateOrder');
}
You can use displayOrderConfirmation hook in your main controller to get details of any order.
Following code can help you:
public function hookDisplayOrderConfirmation($params = null)
{
$id_customer = $params['objOrder']->id_customer;
//Get all other details using the $params['objOrder'] order object
}
Related
guys i want to make variable with order reference in my module with DisplayAdminOrder hook. And i try with this method , but nothing is happen are you have idea how to get variable with order reference
public function hookDisplayAdminOrder()
{
$orderid - Tools::getValue('id_order');
$order = new Order($orderid);
$ref = $order->reference;
echo $ref;
//$this->processChangePayment();
//return $this->display(__FILE__, 'display.tpl');
}
If the module placed in its hook, it should work. just use d() instead of echo to make sure it work correctly:
d($ref);
Does anyone know how to take advantage of any of the functions of the wishlist module to have a variable to use in tpl to know if a product is already added to a wishlist?
If I do not exist, I imagine that some function can be used because when you add a product, if you already have it in the default list, it adds a nity instead of adding it as a new product.
Ideally, for the function you would need, it would be to make a tour not only in the list by default but in all, it is necessary to know if it is already added to a list or not.
The function would be to show an icon or another according to whether a product is already on a list or not.
Has someone developed it or could you help me out?
Thanks!
Prestashop 1.6.1.16
Thank you very much for the contribution.
I gave the code that I put below and it always gives me a "1" (and if you notice, I invented the product id (which does not exist, since I only have 8 products at the moment).
I made an override of the php of the module:
class BlockWishListOverride extends BlockWishList
{
function checkProductIsInWishlist()
{
$customer_wishlists = getByIdCustomer($this->context->customer->id);
$id_product_to_check = 424554224; // Replace by the current product id
foreach ($customer_wishlists as $cw) {
$check_product_wl = WishList::getProductByIdCustomer((int)$cw['id_wishlist'], (int)$this->context->customer->id,
(int)$this->context->language->id, (int)$id_product_to_check);
if (count($check_product_wl)) {
$this->smarty->assign('is_in_wishlist', true);
}
}
}
}
And in my product.tpl:
<p>Is in whislist: {$is_in_wishlist|print_r}</p>
Result on Front:
Result $is_in_wishlist on front
Thanks
You can use the following methods:
public static function getByIdCustomer($id_customer)
public static function getProductByIdCustomer($id_wishlist, $id_customer, $id_lang, $id_product = null, $quantity = false)
which are available in /modules/blockwishlist/WishList.php
In your controller file (on the front-end), you could do something like this:
$customer_wishlists = WishList::getByIdCustomer($this->context->customer->id);
$id_product_to_check = 42; // Replace by the current product id
foreach ($customer_wishlists as $cw) {
$check_product_wl = WishList::getProductByIdCustomer((int)$cw['id_wishlist'], (int)$this->context->customer->id,
(int)$this->context->language->id, (int)$id_product_to_check);
if (count($check_product_wl)) {
$this->smarty->assign('is_in_wishlist', true);
}
}
And then check the {$is_in_wishlist} variable in your Smarty product.tpl template.
i'm developing carrier module for my project.i have to update a new column after checkout.
inside my module ,i want to call some hook immediately after order placed to get order id .
i have used below hooks.but no luck.
public function hookActionOrderStatusUpdate($params){
$order_id=$params['newOrderStatus']->id;
}
public function hookActionOrderStatusPostUpdate($params){
$order_id=$params['newOrderStatus']->id;
}
public function hookDisplayOrderConfirmation($params){
$order_id=$params['newOrderStatus']->id;
}
how to get order id into my module,when user on order confirmation page?
Did you register one of this hooks before ?
It must work as a charm inside module class with :
$this->registerHook('displayOrderConfirmation');
to get the order id it's simple :
public function hookDisplayOrderConfirmation($params){
$order_id = $params['order']->id;
}
I create a module. Which add new tab in product, back office. In this tab I want to display all customization text. Which is define in customization tab. The problem is I don't know how to do that. There is a product, customization or customizationField classes.
I my module I have:
public function getCustomizationFields(){
$getCustomizationFields = Product::getCustomizationFieldIds();
return $getCustomizationFields;
}
There is no error. Always I have output like this:
array(0) { }
Is there any class which I can use for my purpose ? Thanks for any help.
Kind regards
If you have an instance of the Product class, you can do this:
$instance = new Product($product_id);
$instance->getCustomizationFields();
How about
public function getCustomizationFields(){
$productId = (int)Tools::getValue('id_product');
$product = new Product($productId);
$getCustomizationFields = $product->getCustomizationFieldIds();
return $getCustomizationFields;
}
I have a site that runs on Prestashop 1.6. We were able to install and set up the default shop as well as a couple of multishops. The issue that we are having is that as we continue to create multishops for our locations and add products onto these shops, we want these products to display on our default "Master" shop. Is there a way to get this done?
I'm sure this kind of customization have to be done in code, but it is not very hard. You can built a module to query the products and display it in any of the display hooks, say displayLeftColumnProduct or displayHome.
The second way is to use override. Overriding Product class or the ProductController might also works, but here I show you how to do this with overriding.
Looking at the Product class, in the getProducts method (https://github.com/PrestaShop/PrestaShop/blob/1.6/classes/Product.php#L1069) there is a call to Shop::addSqlAssociation('product', 'p') to create the JOIN for shop. To by pass that, we need to override the Shop::addSqlAssociation method (https://github.com/PrestaShop/PrestaShop/blob/1.6/classes/shop/Shop.php#L954) and check if the current shop is the "Master", for example:
class Shop extends ShopCore {
public static function addSqlAssociation($table, $alias, $inner_join = true, $on = null, $force_not_default = false)
{
// It better to check using URL
if (self::$context_id_shop == 1) return '';
return parent::addSqlAssociation($table, $alias, $inner_join, $on, $force_not_default);
}
}