Update CRM from Prestashop - php

I'm building a website for a client, he wants to update his stock from his Presta website to his CRM. In order to achieve that it's very simple, I only have to call an URL like this :
http://crm.com/client1/bin/majstock.php?mode=stock&pdt=REF~-1;REF2~-1
Where REF is obviously the Ref of the product, and the number after ~ is the quantity to update, so in this example the customer bought 2 products, one is REF and the other one is REF2.
The problem is that I don't know where I should call this URL, and where I can get the parameters
Thanks for your help !

You can use the hook actionOrderStatusUpdates like that:
public function hookActionOrderStatusUpdate($params)
{
$OrderState = $params['newOrderStatus']; // an OrderState object
// $OrderState->id // order status ID
// $params['id_order'] // order ID
$Order = new Order((int)$params['id_order']);
$products = $Order->getProductsDetail();
// or
$products = $Order->getProducts();
}

You could create a new module with a hook on actionOrderStatusUpdate and call the CRM when the desired status is set on the order.

Related

Get order payment method name or ID in Prestashop

I'm modifying a cdc_googletagmanager module in prestashop and trying to add conditional function that will depend on choosed payment method in order.
I've tried something like this
foreach ($orders as $id_order) {
$order = new Order($params['id_order']);
$order_payment = OrderPayment::getByOrderId($id_order); }
But order_payment returns nothing. Is there any other method getting payment module name or ID?

Get websiteId from observer event

Given that I have multiple websites in my Magento instance, how do I identify the website where a particular event happened? For example, observing the checkout_cart_add_product_complete event lets me catch all Add to Cart events. Let's say I wanted to get the website Id of the website where this Add to Cart event happened, how do you I do that?
public function addToCart(Varien_Event_Observer $observer) {
$product = $observer->getEvent()->getProduct();
$websiteId = $observer->getEvent()->get ??? ();
}
I know that I can get the websiteIds of the product that was added to the cart, by doing the following
$websiteIds = $observer->getEvent()->getProduct()->getWebsiteIds();
But that is not what I want, because if the product belongs to more than one website, it will give me all the websites and not the one where the Add to Cart event happened.
Thanks
Have you tried:
Mage::app()->getStore()->getId()
within your observer? That should give you the current store id..
You can directly get the StoreId from Mage, not from the observer object.
StoreId:
Mage::app()->getStore()->getStoreId();
WebsiteId:
Mage::app()->getStore()->getWebsiteId();

Magento: Get product id by url

For example, here is url
http://www.tiffosi.com/mulher/camisas-e-tunicas/blusa-l-s-93368.html.
There are several simple products. How can I get the actual simple product ID, from this url?
Magento 1.8
First use the URL rewrite model to find the route which matches your product:
$vPath = 'http://www.tiffosi.com/mulher/camisas-e-tunicas/blusa-l-s-93368.html';
$oRewrite = Mage::getModel('core/url_rewrite')
->setStoreId(Mage::app()->getStore()->getId())
->loadByRequestPath($vPath);
Then you can call getProductId() on the route to locate the produc's id:
$iProductId = $oRewrite->getProductId();
Finally if you require the product model object itself it's then a simple matter to call:
$oProduct = Mage::getModel('catalog/product')->load($iProductId);

Correct way to handle my URL request

I have an application which I am trying to build using Slim PHP and at the moment I am struggling with one Route I am trying to sort out. Basically what happens is I go to GET /:slug and this provides me with a product view. However if there are variations on this product, it will be an intro page in which a visitor can target an exact product. The differences in these products will be :
Color
Dial
Strap
Material
Possibly a few others. The problem I am having is that I am not 100% sure which if any there will be. Do I write my routes for every possibility? Or is there a way I can get this to take a more relaxed approach to how this is formed?
I saw an example where someone did the following :
$app->get("/:slug(/:dial(/:strap(/:material)))", "Route\To\Controller:Action");
However I am assuming this will require this to be in that set order?
Also a note to add would be that some products have no additional filters and respond directly to /:slug whereas others may require all of the additional filters.
These results are all set in the database. I grab all products that have a similar slug as it equates to the product name, then each filter or collection of filters will be determined by certain parts in the database. For example: /this-product/this-dial/this-color/this-strap/this-material all of these values will be stored within the database table for the product - they either have a corresponding value for material - or it is NULL.
This allows me to on the root URL with the SLUG I can show variations - which will aid in the shopping experience in my opinion.
Does anybody have a solution?? Anyway I could achieve this? Am I going about it the wrong way?
One possible way is to render different templates based on the number of returned products. For example, if you are using Twig Template extension you can easily iterate over the set of results and render two templates one for Product Description and one for Product Group.. Alternatively, You can handle this while rendering a view in your SLIM Route
$app->get('/:slug', function ($slug) use ($app) {
$db = new dbConn();
$Products = $db->ProductQuery(); // DB querying for 'slug' & returned product (s)
if( // here check how many $Products and if = 1 ) {
$app->render('single_product_view.html',$Products);
} else if( /// > 1 ) {
$app->render('multiple_product_view.html',$Products);
} else {
$app->response->redirect($app->urlFor('notFoudnt'), 404); // or whatever other route..
}
})->name("product");
As for the querying why do you want to have a route for each product attribute ?
Can't you in this case have one route for the product view and add a query parameter ( attributes ) to URL
/this-product?dial=this-dial&color=this-color&strap=this-strap&material=this-material
$app->get('/:slug', function ($slug) use ($app) {
$Dial = $app->request()->get('dial');
$Color = $app->request()->get('color');
$Strap = $app->request()->get('strap');
$Mat = $app->request()->get('material');
// same as above, build your query string and render corresponding view
})->name("product");
You can also Group your routes ( for ajax request maybe.. )
$app->group('/api', function () use ($app) {
// Products attributes group route
$app->group('/products', function () use ($app) {
// Get Products with color = :color /api/products/color/:color
$app->get('/color/:color', function ($color ) {
});
// Get Products with Strap = :strap /api/products/strap/:strap
$app->get('/strap/:strap', function ($strap) {
});
// and so on..
});
});

Get customer details in backend admin panel order

What I have done:
I have few custom calculations to be done after placing an order for the customer in magento admin panel. I have hooked on to sales_order_save_after event inside tab inside my module's config.xml .
The Problem:
I need to get the customer_id of the actual customer for whom the order is been placed on the backend. How can this be done?
$_customer = Mage::getSingleton('customer/session')->getCustomer();
$customer_id=$_customer->getId();
The above will give me the customer_id in case of front end, I need a way to get the customer's id when ordering from backend.
In case, the event "adminhtml_sales_order_create_process_data", is what I need to hook on, do let me know. because I am also kind of confused about which event to hook on.
Help me out.
Please use this event sales_order_place_after.
And in your code, you might get the customer id like this:
public function hookSalesOrderPlaceAfter(Varien_Event_Observer $observer) {
$order = $observer->getEvent()->getOrder();
$customer_email = $order->getCustomerEmail();
$website_id = Mage::app()->getStore()->getWebsiteId();
$customer = Mage::getModel('customer/customer')->setWebsiteId($website_id)->loadByEmail($customer_email);
...
}
Hope it will help you.
This code below works for me (Thanks to Makwana Ketan shared this code)
$sessionquoteId = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getId();
$sessionCustomerId = Mage::getModel('sales/quote')->loadByIdWithoutStore($sessionquoteId)->getCustomerId();

Categories