This system is designed to showcase a Tofex module. A guide to use this system is available using this link.
The documentation of the module is available using this link.

Dies ist eine Demo-Installation. Es werden keine Aufträge erfüllt.

Tofex Sales Jobs

Introduction

This extension is a base module to use when sales objects have to created with external data.

Concept

If orders in Magento are handled by an external system like an ERP and you still want to have a complete process in Magento, it is required to generate the necessary Magento objects using data from the external system without any generation triggered in the Magento backend. This means shipment, tracking, invoice and credit memo have to be prepared programmatically. This extension provides an easy handling of this.

The extension contains four processes in the form of abstract classes which you have to implement and provide the necessary date. There are also some entry points available during the process which can be used for further implementation or left alone.

The four processes are:

  • Customer notification when order state / status reached
  • Creating of shipment with tracking
  • Creating of invoice
  • Creating of credit memo

Development

Customer notification

This job sends a notification to the customer in case the order has reached a certain status without any Magento logic being involved.

  • getStateStatus: List of order state / status to check for
  • getOrdersLimit: Limit the number of orders processing
  • prepareCollection: In case you want to change the collection to identify the orders
  • canProcessOrder: In case you want to provide some more checking with the loaded order
  • getStatusHistoryComment: The comment to use in the order status history
  • getIsVisibleOnFront: If the added order status history is visible
  • prepareOrder: Update the order before saving
  • followUpOrder: For additional processes after the order was saved
  • canNotifyCustomer: If the customer can be notified about the change
<?php

namespace Company\Webshop\Job;

use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\Collection;

class Notification
    extends \Tofex\SalesJobs\Job\Notification
{
    /**
     * key: state
     * value: status
     *
     * @return string[]
     */
    protected function getStateStatus()
    {
        ...
    }

    /**
     * @return int
     */
    protected function getOrdersLimit()
    {
        ...
    }

    /**
     * @param Collection $collection
     */
    protected function prepareCollection(Collection $collection)
    {
        ...
    }

    /**
     * @param Order  $order
     * @param string $state
     * @param string $status
     *
     * @return bool
     */
    protected function canProcessOrder(Order $order, $state, $status)
    {
        ...
    }

    /**
     * @param Order  $order
     * @param string $state
     * @param string $status
     *
     * @return bool
     */
    protected function getStatusHistoryComment(Order $order, $state, $status)
    {
        ...
    }

    /**
     * @param Order  $order
     * @param string $state
     * @param string $status
     *
     * @return bool
     */
    protected function getIsVisibleOnFront(Order $order, $state, $status)
    {
        ...
    }

    /**
     * @param Order $order
     */
    protected function prepareOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     */
    protected function followUpOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order  $order
     * @param string $state
     * @param string $status
     *
     * @return bool
     */
    protected function canNotifyCustomer(Order $order, $state, $status)
    {
        ...
    }
}

Creating shipment / tracking

This job creates a shipment with tracking information. There can be multiple tracks. Customer can be notified about the shipment if required.

  • getOrdersLimit: Limit the number of orders processing
  • prepareCollection: In case you want to change the collection to identify the orders
  • canProcessOrder: In case you want to provide some more checking with the loaded order
  • getShipmentQtys: Which items in what amount where shipped
  • getTrackingIds: List of tracking ids, each creates a track
  • getTrackNumber: The number of the track
  • getTrackCarrierCode: The carrier code of the track
  • getTrackTitle: The title of the track
  • prepareOrder: Update the order before saving
  • followUpOrder: For additional processes after the order was saved
  • canSendShipment: If the customer can be notified
<?php

namespace Company\Webshop\Job;

use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\Collection;

class Shipment
    extends \Tofex\SalesJobs\Job\Shipment
{
    /**
     * @return int
     */
    protected function getOrdersLimit()
    {
        ...
    }

    /**
     * @param Collection $collection
     */
    protected function prepareCollection(Collection $collection)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return bool
     */
    protected function canProcessOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return array
     */
    protected function getShipmentQtys(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return array
     */
    protected function getTrackingIds(Order $order)
    {
        ...
    }

    /**
     * @param Order  $order
     * @param int    $index
     * @param string $trackingId
     *
     * @return string
     */
    protected function getTrackNumber(Order $order, $index, $trackingId)
    {
        ...
    }

    /**
     * @param Order  $order
     * @param int    $index
     * @param string $trackingId
     *
     * @return string
     */
    protected function getTrackCarrierCode(Order $order, $index, $trackingId)
    {
        ...
    }

    /**
     * @param Order  $order
     * @param int    $index
     * @param string $trackingId
     *
     * @return string
     */
    protected function getTrackTitle(Order $order, $index, $trackingId)
    {
        ...
    }

    /**
     * @param Order $order
     */
    protected function prepareOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     */
    protected function followUpOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return bool
     */
    protected function canSendShipment(Order $order)
    {
        ...
    }
}

Creating invoice

This job creates an invoice. Customer can be notified about the invoice if required.

  • getOrdersLimit: Limit the number of orders processing
  • prepareCollection: In case you want to change the collection to identify the orders
  • canProcessOrder: In case you want to provide some more checking with the loaded order
  • getInvoiceIncrementId: The number of the invoice to create
  • getInvoiceQtys: Which items in what amount have to be invoiced
  • prepareOrder: Update the order before saving
  • followUpOrder: For additional processes after the order was saved
  • canSendInvoice: If the customer can be notified
<?php

namespace Company\Webshop\Job;

use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\Collection;

class Invoice
    extends \Tofex\SalesJobs\Job\Invoice
{
    /**
     * @return int
     */
    protected function getOrdersLimit()
    {
        ...
    }

    /**
     * @param Collection $collection
     */
    protected function prepareCollection(Collection $collection)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return bool
     */
    protected function canProcessOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return string
     */
    protected function getInvoiceIncrementId(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return array
     */
    protected function getInvoiceQtys(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     */
    protected function prepareOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     */
    protected function followUpOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return bool
     */
    protected function canSendInvoice(Order $order)
    {
        ...
    }
}

Creating credit memo

This job creates a credit memo. Customer can be notified about the credit memo if required.

  • getOrdersLimit: Limit the number of orders processing
  • prepareCollection: In case you want to change the collection to identify the orders
  • canProcessOrder: In case you want to provide some more checking with the loaded order
  • getCreditMemoIncrementId: The number of the credit memo to create
  • getCreditMemoQtys: Which items in what amount have to be credited
  • getCreditMemoShippingAmount: In case an amount of the shipped amount should be credited
  • getCreditMemoAdjustmentPositive: In case a positive adjustment should be added
  • getCreditMemoAdjustmentNegative: In case a negative adjustment (fee) should be added
  • prepareOrder: Update the order before saving
  • followUpOrder: For additional processes after the order was saved
  • canSendCreditMemo: If the customer can be notified
<?php

namespace Company\Webshop\Job;

use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\Collection;

class Creditmemo
    extends \Tofex\SalesJobs\Job\Creditmemo
{
    /**
     * @return int
     */
    protected function getOrdersLimit()
    {
        ...
    }

    /**
     * @param Collection $collection
     */
    protected function prepareCollection(Collection $collection)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return bool
     */
    protected function canProcessOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return string
     */
    protected function getCreditMemoIncrementId(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return array
     */
    protected function getCreditMemoQtys(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return float|null
     */
    protected function getCreditMemoShippingAmount(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return float|null
     */
    protected function getCreditMemoAdjustmentPositive(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return float|null
     */
    protected function getCreditMemoAdjustmentNegative(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     */
    protected function prepareOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     */
    protected function followUpOrder(Order $order)
    {
        ...
    }

    /**
     * @param Order $order
     *
     * @return bool
     */
    protected function canSendCreditMemo(Order $order)
    {
        ...
    }
}

License

Tofex Sales Jobs is licensed under the MIT License - see the LICENSE file for details.

Copyright © 2013-gegenwärtig Magento, Inc. Alle Rechte vorbehalten.