classes/XLite/Model/Order/Status/Shipping.php line 38

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2001-present X-Cart Holdings LLC. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XLite\Model\Order\Status;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use XLite\API\Endpoint\OrderShippingStatus\DTO\OrderShippingStatusInput as Input;
  10. use XLite\API\Endpoint\OrderShippingStatus\DTO\OrderShippingStatusOutput as Output;
  11. /**
  12.  * Shipping status
  13.  *
  14.  * @ORM\Entity
  15.  * @ORM\Table  (name="order_shipping_statuses",
  16.  *      indexes={
  17.  *          @ORM\Index (name="code", columns={"code"})
  18.  *      }
  19.  * )
  20.  * @ApiPlatform\ApiResource(
  21.  *     shortName="OrderShippingStatus",
  22.  *     input=Input::class,
  23.  *     output=Output::class,
  24.  *     itemOperations={
  25.  *          "get"={
  26.  *              "method"="GET",
  27.  *              "path"="/orders/{id}/shipping_status.{_format}",
  28.  *              "identifiers"={"id"},
  29.  *              "requirements"={"id"="\d+"}
  30.  *          },
  31.  *          "put"={
  32.  *              "method"="PUT",
  33.  *              "path"="/orders/{id}/shipping_status.{_format}",
  34.  *              "identifiers"={"id"},
  35.  *              "requirements"={"id"="\d+"}
  36.  *          }
  37.  *     },
  38.  *     collectionOperations={}
  39.  * )
  40.  */
  41. class Shipping extends \XLite\Model\Order\Status\AStatus
  42. {
  43.     /**
  44.      * Statuses
  45.      */
  46.     public const STATUS_NEW                 'N';
  47.     public const STATUS_PROCESSING          'P';
  48.     public const STATUS_SHIPPED             'S';
  49.     public const STATUS_DELIVERED           'D';
  50.     public const STATUS_WILL_NOT_DELIVER    'WND';
  51.     public const STATUS_RETURNED            'R';
  52.     public const STATUS_WAITING_FOR_APPROVE 'WFA';
  53.     public const STATUS_NEW_BACKORDERED     'NBA';
  54.     /**
  55.      * @var \Doctrine\Common\Collections\Collection
  56.      *
  57.      * @ORM\OneToMany (targetEntity="XLite\Model\Order\Status\ShippingTranslation", mappedBy="owner", cascade={"all"})
  58.      */
  59.     protected $translations;
  60.     /**
  61.      * Disallowed to set manually statuses
  62.      *
  63.      * @return array
  64.      */
  65.     public static function getDisallowedToSetManuallyStatuses()
  66.     {
  67.         return [
  68.             static::STATUS_WAITING_FOR_APPROVE,
  69.             static::STATUS_NEW_BACKORDERED,
  70.         ];
  71.     }
  72.     /**
  73.      * Status is allowed to set manually
  74.      *
  75.      * @return boolean
  76.      */
  77.     public function isAllowedToSetManually()
  78.     {
  79.         return !in_array(
  80.             $this->getCode(),
  81.             static::getDisallowedToSetManuallyStatuses()
  82.         );
  83.     }
  84.     /**
  85.      * Get id
  86.      *
  87.      * @return integer
  88.      */
  89.     public function getId()
  90.     {
  91.         return $this->id;
  92.     }
  93.     /**
  94.      * Set code
  95.      *
  96.      * @param string $code
  97.      *
  98.      * @return Shipping
  99.      */
  100.     public function setCode($code)
  101.     {
  102.         $this->code $code;
  103.         return $this;
  104.     }
  105.     /**
  106.      * Get code
  107.      *
  108.      * @return string|null
  109.      */
  110.     public function getCode()
  111.     {
  112.         return $this->code;
  113.     }
  114.     /**
  115.      * Set position
  116.      *
  117.      * @param integer $position
  118.      *
  119.      * @return Shipping
  120.      */
  121.     public function setPosition($position)
  122.     {
  123.         $this->position $position;
  124.         return $this;
  125.     }
  126.     /**
  127.      * Get position
  128.      *
  129.      * @return integer
  130.      */
  131.     public function getPosition()
  132.     {
  133.         return $this->position;
  134.     }
  135.     /**
  136.      * List of change status handlers;
  137.      * top index - old status, second index - new one
  138.      * (<old_status> ----> <new_status>: $statusHandlers[$old][$new])
  139.      *
  140.      * @return array
  141.      */
  142.     public static function getStatusHandlers()
  143.     {
  144.         return [
  145.             static::STATUS_NEW => [
  146.                 static::STATUS_SHIPPED => ['ship'],
  147.                 static::STATUS_WAITING_FOR_APPROVE => ['waitingForApprove']
  148.             ],
  149.             static::STATUS_PROCESSING => [
  150.                 static::STATUS_SHIPPED => ['ship'],
  151.                 static::STATUS_WAITING_FOR_APPROVE => ['waitingForApprove']
  152.             ],
  153.             static::STATUS_DELIVERED => [
  154.                 static::STATUS_SHIPPED => ['ship'],
  155.             ],
  156.             static::STATUS_WILL_NOT_DELIVER => [
  157.                 static::STATUS_SHIPPED => ['ship'],
  158.             ],
  159.             static::STATUS_RETURNED => [
  160.                 static::STATUS_SHIPPED => ['ship'],
  161.             ],
  162.             static::STATUS_WAITING_FOR_APPROVE => [
  163.                 static::STATUS_SHIPPED => ['ship'],
  164.             ],
  165.             static::STATUS_NEW_BACKORDERED => [
  166.                 static::STATUS_NEW              => ['releaseBackorder'],
  167.                 static::STATUS_PROCESSING       => ['releaseBackorder'],
  168.                 static::STATUS_SHIPPED          => ['ship''releaseBackorder'],
  169.                 static::STATUS_DELIVERED        => ['releaseBackorder'],
  170.                 static::STATUS_WILL_NOT_DELIVER => ['releaseBackorder'],
  171.                 static::STATUS_RETURNED         => ['releaseBackorder'],
  172.             ],
  173.         ];
  174.     }
  175. }