Optimizing Your Magento Workflow: Print Packing Slips Before Final Shipment Submission
In many warehouses, packing slips serve as critical pick lists for order fulfillment. However, Magento’s default workflow requires orders to be marked as shipped before a packing slip can be generated and printed. This backward process can lead to inefficiencies and errors. Let me guide you through an upgrade-friendly solution that allows printing of packing slips before submitting the shipment.
Understanding the Current Workflow
In the current setup, Magento’s logic is tied to order status changes. Only once an order status transitions from “processing” to “shipped”, can a packing slip be generated via the backend interface or programmatically using APIs like sales_order_shipment_save_after observer.
This sequential approach assumes that all items in an order are ready for immediate shipping, which isn’t always the caseâespecially in complex fulfillment scenarios involving multiple warehouses or special handling processes.
An Upgrade-Friendly Solution
To print packing slips before final shipment submission, we’ll need to modify Magento’s default behavior without affecting core files. This approach ensures compatibility with future updates and maintains a clean, upgrade-friendly environment.
Our solution involves creating a custom module that extends the existing sales_order_shipment_processor model. By adding an additional status for our custom “Packing Slip Printed” flag, we can generate packing slips without actually submitting the shipment.
Step-by-Step Implementation
- Create Your Custom Module
First, create a new module called
Laravel_PackingSlip. Follow Magento’s standard naming conventions and directory structure:
app/code/Laravel/PackingSlip
- Extend sales_order_shipment_processor
In your new module, extend the
sales_order_shipment_processormodel and add a new status called “Packing Slip Printed”:
// app/code/Laravel/PackingSlip/Processor.php
namespace Laravel\PackingSlip\Model;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\DataObject;
use Magento\Sales\Model\Order\ShipmentFactory;
use Magento\Shipping\Model\Rate\ResultFactory;
class Processor extends \Magento\Sales\Model\Order\Shipment\Processor
{
const STATUS_PACKING_SLIP_PRINTED = 'packing_slip_printed';
public function process($request)
{
$shipmentId = $request->getParam('shipment_id');
$orderId = $request->getParam('order_id');
// Fetch the order and shipment
$order = $this->registryManager->registry("sales_order_{$orderId}");
$shipment = $this->shipmentFactory->create()->load($shipmentId);
if ($shipment && $shipment->getOrderId() == $orderId) {
// Set the custom status
$shipment->setStatus(self::STATUS_PACKING_SLIP_PRINTED);
$shipment->save();
// Generate and print the packing slip (omitted for brevity)
}
}
}
- Re-route the API Request
To use this new processing logic, we need to re-route Magento’s default shipment save request. This is achieved by adding an observer that intercepts the
sales_order_shipment_save_afterevent and redirects it to our custom processor.
Follow the instructions here to create a custom observer in your module: https://laravelcompany.com/blog/magento-event-observers-tutorial
- Printing the Packing Slip
The actual packing slip generation and printing process can be handled within the
processmethod of your custom processor class. You can use Magento’s defaultsales_order_shipment_print_pdfcontroller or extend it to fit your specific requirements.
Conclusion
By following this upgrade-friendly solution, you can optimize your warehouse workflow by printing packing slips before submitting shipments in Magento. This approach minimizes core file modifications and ensures compatibility with future updates.
Remember to clear your cache after implementing these changes, as Magento often caches the list of available shipment statuses.
Don’t hesitate to explore more customization options on our blog at https://laravelcompany.com/blog for further insights into Magento development and optimization techniques.