Jump to content

Advanced Stock Management: order submitted, which warehouse provided the stock ?


Recommended Posts

Hello,

 

I started using ASM in PrestaShop 1.5, and although there are many topics about this subject, there is one thing that I can't find.

 

I have 5 warehouses for my shop, they all provide stock for my products. Whenever an order is placed, let's say I order just 1 product, I assume that Prestashop takes this 1 product from stock from one of the available warehouses, correct?

 

And where can I find this information in the order screen? If I login to the backoffice I can see the order details, but it would be very useful if I could see on this same page from which warehouse the product was taken. Is this possible? For the customer this information is not relevant, so in frontend I won't have to see it.

 

Thanks !

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...

We have found a way to get it in the email sent by the MailAlerts module.

In the file /classes/order/Order.php , starting at line 1781:

    /**
     * Get warehouse associated to the order
     *
     * return array List of warehouse
     */
    public function getWarehouseList()
    {
        $results = Db::getInstance()->executeS('
            SELECT id_warehouse
            FROM `'._DB_PREFIX_.'order_detail`
            WHERE `id_order` =  '.(int)$this->id.'
            GROUP BY id_warehouse');
        if (!$results)
            return array();

            $warehouse_list = array();
        foreach ($results as $row)
            $warehouse_list[] = $row['id_warehouse'];

        return $warehouse_list;
    }

Based on this function, we have customized it to fit the need:

	/**
	 * Get warehouse associated to the order
	 *
	 * return name of the warehouse
	 */
	public static function getWarehouseName($id_order)
	{
		$results = Db::getInstance()->executeS('
			SELECT name
			FROM `'._DB_PREFIX_.'order_detail`,`'._DB_PREFIX_.'warehouse`
			WHERE `id_order` =  '.(int)$id_order.' AND '._DB_PREFIX_.'warehouse.id_warehouse = '._DB_PREFIX_.'order_detail.id_warehouse
			GROUP BY '._DB_PREFIX_.'order_detail.id_warehouse');
		if (!$results)
			return array();

		$warehouse_name = array();
		foreach ($results as $row)
			$warehouse_name[] = $row['name'];

		return $warehouse_name;
	} 

And put the customized function into /modules/mailalerts/MailAlert.php at the end.

 

Then, in /modules/mailalersts/mailalerts.php , inside the public function hookActionValidateOrder($params), at the end of the list under "// Getting differents vars" (line 266), added this :

        $order_warehouse = MailAlert::getWarehouseName($order->id);
        $order_warehouse = $order_warehouse[0];

Then finaly, in the same function into /modules/mailalersts/mailalerts.php , line 396, replaced :

sprintf(Mail::l('New order - #%06d', $id_lang), $order->id),

by:

sprintf(Mail::l('New order - #%06d '.$order_warehouse, $id_lang), $order->id),

So now in the subject of the merchant email, we get something like "[Prestashop] New order - #0000XX Warehouse-Name"

 

For the back-office side, latest version of PrestaShop shows the warehouse name into the order details, but we also are on version 1.5.4.1.  Else than this, when you change the state of the order to "Shipped", the quantities are updated and you can see in menu Stock->Stock Movements wich warehouse is related to this product and date.

 

We know this may be not the best/correct way to get it, but for now this works.

 

Let us know if it's working for you too and/or if you have a better way to achieve this.

 

Thanks!

Link to comment
Share on other sites

Another bug we found related to this, the customer gets one confirmation email by warehouse, but all the products are in each confirmation emails.

 

The only difference is inside the email, Order : XXXXXXXXX#1, XXXXXXXXX#2, etc.

 

This could confuse the customer and could think his order has been processed twice or more...

Link to comment
Share on other sites

Finally, emails are differents and costs of products and shipping are distinct and ok.

 

The products list was the same in both emails, after searching we found this fix and it's working:

 

https://github.com/PrestaShop/PrestaShop/commit/9bf6871e8dfe643e42e6fcf4c252597d06472efc

 

Now it sends one email per warehouse with only products in this warehouse included.

Link to comment
Share on other sites

×
×
  • Create New...