2

How can I passed the tracking number to the Model \Magento\Sales\Api\ShipOrderInterface. The method is working with a empty array.

this is the code I've made for testing, but it's not working:

<?php
namespace Maru3l\SyncOrchestra\Cron;

use \Psr\Log\LoggerInterface;
use \Magento\Framework\App\Helper\Context;
use \Magento\Framework\App\Helper\AbstractHelper;
use \Magento\Sales\Api\OrderRepositoryInterface;
use \Magento\Framework\Api\SearchCriteriaBuilder;
use \Magento\Sales\Api\ShipOrderInterface;

class SyncOrder extends AbstractHelper
{
    protected $logger;
    protected $sourceItemInterface;
    protected $orderRepository;
    protected $searchCriteriaBuilder;
    protected $shipOrderInterface;

    public function __construct(
        Context $context,
        LoggerInterface $logger,
        OrderRepositoryInterface $orderRepository,
        SearchCriteriaBuilder $searchCriteriaBuilder,
        ShipOrderInterface $shipOrderInterface
    ) {
        $this->logger = $logger;
        $this->orderRepository = $orderRepository;
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
        $this->shipOrderInterface = $shipOrderInterface;

        parent::__construct($context);
    }

/**
   * Request quantity from Orchestra and update quantity in Source
   *
   * @return void
   */

    public function execute()
    {
        $searchCriteria = $this->searchCriteriaBuilder
            ->addFilter(
                'status',
                'processing',
                'eq'
            )
            ->create();

        $orders = $this->orderRepository->getList($searchCriteria);

        foreach ($orders->getItems() as $order) {
            try {
                $this->shipOrderInterface->execute(
                    $order->getEntityId(),
                    array(),
                    true,
                    false,
                    null,
                    array(
                        array(
                                "track_number" => "test-tracking",
                                "carrier_code" => "canadapost",
                                "title" => "Poste Canada"
                        )
                    ),
                    array(),
                    null
                );
            } catch (\Exception $e) {
                $this->logger->info($e->getMessage());
            }
        };
    }
}

I'm doing a little plugin who sync the database of a custom inventory system with magento.

0

I found that I can create a tracking element with Magento\Sales\Model\Order\Shipment\TrackFactory like this:

$track = $this->trackFactory->create();
$track->setCarrierCode("canadapost");
$track->setTitle("Poste Canada");
$track->setDescription("Poste Canada");
$track->setTrackNumber("test-tracking-number-1234");

and pass it to the array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.