Skip to content

Commit

Permalink
Merge pull request #16 from logeecom/release/v1.5.0
Browse files Browse the repository at this point in the history
Release v1.5.0
  • Loading branch information
yovendielmundo authored Nov 18, 2019
2 parents 8fe5dd3 + b481eee commit dab7741
Show file tree
Hide file tree
Showing 74 changed files with 2,011 additions and 295 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [Unreleased](https://github.com/packlink-dev/ecommerce_module_core/compare/master...dev)

### Added

- `isRegistered` method in `RepositoryRegistry`.
- `isShipmentLabelsAvailable` method in `OrderService`

### Removed

- `OrderService::updateShipmentLabel` method.
- `OrderRepository::isLabelSet` method.
- `OrderRepository::setLabelsByReference` method.

### Changed
**NON-BREAKING CHANGES**
- `SendDraftTask` is now idempotent.
- `ShippingMethodConfiguration` DTO and `ShippingMethod` model are modified to enable setting list of allowed
destination countries for a shipping method.
- `UpdateShipmentDataTask` checks for update with different frequencies for orders with different statuses.
*NOTICE* For existing users delete old scheduled `UpdateShipmentDataTasks` and schedule new ones in the same manner as
they are scheduled in core.
- `AbstractGenericStudentRepositoryTest` extended to cover every ORM operator.

**BREAKING CHANGES**

- The lowest boundary in fixed price can be higher than zero. *NOTICE* Each integration for from input field must
remove "disabled" directive in template file as disabling from input field is now handled by js library.
- Advanced serialization mechanism has been implemented.`NativeSerializer` and `JsonSerializer` have been introduced.
This is a *breaking* change and each integration should register preferred serializer in bootstrap.
- `OrderRepository` introduced new method `getOrderReferencesWithStatus`. This method must be implemented in each
integration.
- Removed `OrderRepository::setLabelsByReference` method.

## [v1.4.1](https://github.com/packlink-dev/ecommerce_module_core/compare/v1.4.1...1.4.0) - 2019-10-14
### Added
- `DraftController` is added to decrease the code in integrations related to creation of the draft
Expand Down
8 changes: 8 additions & 0 deletions src/BusinessLogic/BootstrapComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Packlink\BusinessLogic\Http\Proxy;
use Packlink\BusinessLogic\Location\LocationService;
use Packlink\BusinessLogic\Order\OrderService;
use Packlink\BusinessLogic\OrderShipmentDetails\OrderShipmentDetailsService;
use Packlink\BusinessLogic\Scheduler\ScheduleTickHandler;
use Packlink\BusinessLogic\ShippingMethod\PackageTransformer;
use Packlink\BusinessLogic\ShippingMethod\ShippingMethodService;
Expand Down Expand Up @@ -90,6 +91,13 @@ function () {
return PackageTransformer::getInstance();
}
);

ServiceRegister::registerService(
OrderShipmentDetailsService::CLASS_NAME,
function () {
return OrderShipmentDetailsService::getInstance();
}
);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/BusinessLogic/Controllers/DTO/ShippingMethodConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ class ShippingMethodConfiguration extends BaseDto
* @var mixed
*/
public $taxClass;
/**
* Flag that denotes whether is shipping to all countries allowed.
*
* @var boolean
*/
public $isShipToAllCountries = true;
/**
* If `isShipToAllCountries` set to FALSe than this array contains list of countries where shipping is allowed.
*
* @var array
*/
public $shippingCountries = array();

/**
* Transforms DTO to its array format suitable for http client.
Expand All @@ -76,6 +88,8 @@ public function toArray()
'pricePolicy' => $this->pricePolicy,
'showLogo' => $this->showLogo,
'taxClass' => $this->taxClass,
'isShipToAllCountries' => $this->isShipToAllCountries,
'shippingCountries' => $this->shippingCountries,
);

if ($this->pricePolicy === ShippingMethod::PRICING_POLICY_PERCENT && $this->percentPricePolicy) {
Expand Down Expand Up @@ -115,6 +129,18 @@ public static function fromArray(array $raw)

$result->taxClass = isset($raw['taxClass']) ? $raw['taxClass'] : null;

if (isset($raw['isShipToAllCountries']) && is_bool($raw['isShipToAllCountries'])) {
$result->isShipToAllCountries = $raw['isShipToAllCountries'];
} else {
$result->isShipToAllCountries = true;
}

if (isset($raw['shippingCountries']) && is_array($raw['shippingCountries'])) {
$result->shippingCountries = $raw['shippingCountries'];
} else {
$result->shippingCountries = array();
}

if ($result->pricePolicy === ShippingMethod::PRICING_POLICY_PERCENT) {
$value = $raw['percentPricePolicy'];
$result->percentPricePolicy = PercentPricePolicy::fromArray($value);
Expand Down
6 changes: 5 additions & 1 deletion src/BusinessLogic/Controllers/ShippingMethodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Class ShippingMethodController.
*
* @package Packlink\BusinessLogic\Controllers
* @package Packlink\PacklinkPro\IntegrationCore\BusinessLogic\Controllers
*/
class ShippingMethodController
{
Expand Down Expand Up @@ -176,6 +176,8 @@ private function transformShippingMethodModelToDto(ShippingMethod $item)
$shippingMethod->parcelDestination = $item->isDestinationDropOff() ? static::DROP_OFF : static::HOME;
$shippingMethod->parcelOrigin = $item->isDepartureDropOff() ? static::DROP_OFF : static::PICKUP;
$shippingMethod->taxClass = $item->getTaxClass();
$shippingMethod->shippingCountries = $item->getShippingCountries();
$shippingMethod->isShipToAllCountries = $item->isShipToAllCountries();

$shippingMethod->pricePolicy = $item->getPricingPolicy();
$shippingMethod->percentPricePolicy = $item->getPercentPricePolicy();
Expand Down Expand Up @@ -214,6 +216,8 @@ private function updateModelData(ShippingMethodConfiguration $configuration, Shi
$model->setTitle($configuration->name);
$model->setDisplayLogo($configuration->showLogo);
$model->setTaxClass($configuration->taxClass);
$model->setShipToAllCountries($configuration->isShipToAllCountries);
$model->setShippingCountries($configuration->shippingCountries);
switch ($configuration->pricePolicy) {
case ShippingMethod::PRICING_POLICY_PACKLINK:
$model->setPacklinkPricePolicy();
Expand Down
28 changes: 9 additions & 19 deletions src/BusinessLogic/Order/Interfaces/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ interface OrderRepository
*/
public function getIncompleteOrderReferences();

/**
* Retrieves list of order references where order is in one of the provided statuses.
*
* @param array $statuses List of order statuses.
*
* @return string[] Array of shipment references.
*/
public function getOrderReferencesWithStatus(array $statuses);

/**
* Fetches and returns system order by its unique identifier.
*
Expand All @@ -46,16 +55,6 @@ public function getOrderAndShippingData($orderId);
*/
public function setReference($orderId, $shipmentReference);

/**
* Sets order packlink shipping labels to an order by shipment reference.
*
* @param string $shipmentReference Packlink shipment reference.
* @param string[] $labels Packlink shipping labels.
*
* @throws \Packlink\BusinessLogic\Order\Exceptions\OrderNotFound When order with provided reference is not found.
*/
public function setLabelsByReference($shipmentReference, array $labels);

/**
* Sets order packlink shipment tracking history to an order for given shipment.
*
Expand Down Expand Up @@ -105,13 +104,4 @@ public function markShipmentDeleted($shipmentReference);
* @throws \Packlink\BusinessLogic\Order\Exceptions\OrderNotFound When order with provided reference is not found.
*/
public function isShipmentDeleted($shipmentReference);

/**
* Returns whether shipment identified by provided reference has Packlink shipment label set.
*
* @param string $shipmentReference Packlink shipment reference.
*
* @return bool Returns TRUE if label is set; otherwise, FALSE.
*/
public function isLabelSet($shipmentReference);
}
14 changes: 3 additions & 11 deletions src/BusinessLogic/Order/Models/OrderShipmentDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,11 @@ public function getShipmentLabels()
/**
* Sets order shipment labels from array of links to PDF.
*
* @param array $links Array of links to PDF.
* @param ShipmentLabel[] Array of links to PDF.
*/
public function setShipmentLabels(array $links)
public function setShipmentLabels(array $labels)
{
if (empty($this->shipmentLabels)) {
$shipmentLabels = array();

foreach ($links as $link) {
$shipmentLabels[] = new ShipmentLabel($link);
}

$this->shipmentLabels = $shipmentLabels;
}
$this->shipmentLabels = $labels;
}

/**
Expand Down
76 changes: 47 additions & 29 deletions src/BusinessLogic/Order/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Packlink\BusinessLogic\Http\DTO\Draft;
use Packlink\BusinessLogic\Http\DTO\Package;
use Packlink\BusinessLogic\Http\DTO\Shipment;
use Packlink\BusinessLogic\Http\DTO\ShipmentLabel;
use Packlink\BusinessLogic\Http\Proxy;
use Packlink\BusinessLogic\Order\Exceptions\OrderNotFound;
use Packlink\BusinessLogic\Order\Interfaces\OrderRepository;
Expand Down Expand Up @@ -87,35 +88,6 @@ public function setReference($orderId, $shipmentReference)
$this->orderRepository->setReference($orderId, $shipmentReference);
}

/**
* Updates shipment label from API for order with given shipment reference.
*
* @param Shipment $shipment Shipment DTO for given reference number.
*/
public function updateShipmentLabel(Shipment $shipment)
{
$referenceId = $shipment->reference;
if (!ShipmentStatus::shouldFetchLabels($shipment->status)
|| $this->orderRepository->isLabelSet($referenceId)
) {
return;
}

/** @var Proxy $proxy */
$proxy = ServiceRegister::getService(Proxy::CLASS_NAME);
$labels = array();
try {
$labels = $proxy->getLabels($referenceId);
if (count($labels) > 0) {
$this->orderRepository->setLabelsByReference($referenceId, $labels);
}
} catch (HttpBaseException $e) {
Logger::logError($e->getMessage(), 'Core', array('referenceId' => $referenceId));
} catch (OrderNotFound $e) {
Logger::logInfo($e->getMessage(), 'Core', array('referenceId' => $referenceId, 'labels' => $labels));
}
}

/**
* Updates shipping status from API for order with given shipment reference.
*
Expand Down Expand Up @@ -164,6 +136,52 @@ public function updateTrackingInfo(Shipment $shipment)
}
}

/**
* Retrieves list of order labels.
*
* @param string $reference Order reference.
*
* @return \Packlink\BusinessLogic\Http\DTO\ShipmentLabel[] List of shipment labels for an order defined by
* the provided reference.
*/
public function getShipmentLabels($reference)
{
/** @var Proxy $proxy */
$proxy = ServiceRegister::getService(Proxy::CLASS_NAME);
$labels = array();

try {
$links = $proxy->getLabels($reference);
foreach ($links as $link) {
$labels[] = new ShipmentLabel($link);
}
} catch (\Exception $e) {
Logger::logError("Failed to retrieve labels for order [$reference] because: {$e->getMessage()}");
}

return $labels;
}

/**
* Checks whether shipment labels are available.
*
* @param string $status
*
* @return bool TRUE if shipment labels are available; FALSE otherwise.
*/
public function isReadyToFetchShipmentLabels($status)
{
return in_array(
$status,
array(
ShipmentStatus::STATUS_READY,
ShipmentStatus::STATUS_IN_TRANSIT,
ShipmentStatus::STATUS_DELIVERED,
),
true
);
}

/**
* Converts order object to draft DTO suitable for sending to Packlink.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Packlink\BusinessLogic\OrderShipmentDetails;

use Logeecom\Infrastructure\ORM\Interfaces\RepositoryInterface;
use Logeecom\Infrastructure\ORM\QueryFilter\Operators;
use Logeecom\Infrastructure\ORM\QueryFilter\QueryFilter;
use Packlink\BusinessLogic\BaseService;
use Packlink\BusinessLogic\Order\Models\OrderShipmentDetails;

/**
* Class OrderShipmentDetailsService
*
* @package Packlink\BusinessLogic\OrderShipmentDetails
*/
class OrderShipmentDetailsService extends BaseService
{
/**
* Fully qualified name of this class.
*/
const CLASS_NAME = __CLASS__;
/**
* Singleton instance of this class.
*
* @var static
*/
protected static $instance;
/**
* Order shipment details repository.
*
* @var RepositoryInterface
*/
protected $orderShipmentDetailsRepository;

/**
* OrderShipmentDetailsService constructor.
*/
public function __construct()
{
parent::__construct();

$this->orderShipmentDetailsRepository = $this->getRepository(OrderShipmentDetails::getClassName());
}

/**
* Retrieves order shipment details.
*
* @param string | int $orderId Order id in an integration system.
*
* @return OrderShipmentDetails | null Instance that retrieved by the specifed id.
*
* @throws \Logeecom\Infrastructure\ORM\Exceptions\QueryFilterInvalidParamException
*/
public function getDetailsByOrderId($orderId)
{
$query = new QueryFilter();
$query->where('orderId', Operators::EQUALS, $orderId);

/** @var OrderShipmentDetails | null $entity */
$entity = $this->orderShipmentDetailsRepository->selectOne($query);

return $entity;
}
}
Loading

0 comments on commit dab7741

Please sign in to comment.