Skip to content

Commit

Permalink
Merge pull request #15 from snowio/fix/update-version
Browse files Browse the repository at this point in the history
Update for Magento 2.4 and PHP 7.4
  • Loading branch information
Liam Toohey authored Dec 2, 2020
2 parents e4c53e2 + b805501 commit 298cf4f
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 169 deletions.
8 changes: 4 additions & 4 deletions Api/Data/OrderRelatedDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

interface OrderRelatedDataInterface
{
const ID = 'id';
const ORDER_INCREMENT_ID = 'order_increment_id';
const CODE = 'code';
const VALUE = 'value';
public const ID = 'id';
public const ORDER_INCREMENT_ID = 'order_increment_id';
public const CODE = 'code';
public const VALUE = 'value';

/**
* @return string
Expand Down
12 changes: 4 additions & 8 deletions Model/CreditmemoByOrderIncrementId.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@

class CreditmemoByOrderIncrementId implements CreditmemoByOrderIncrementIdInterface
{
/** @var CreditmemoManagementInterface */
private $creditmemoManagement;
private \Magento\Sales\Api\CreditmemoManagementInterface $creditmemoManagement;

/** @var CreditmemoRepositoryInterface */
private $creditmemoRepository;
private \Magento\Sales\Api\CreditmemoRepositoryInterface $creditmemoRepository;

/** @var OrderRepositoryInterface */
private $orderRepository;
private \Magento\Sales\Api\OrderRepositoryInterface $orderRepository;

/** @var CreditmemoFactory */
private $creditmemoFactory;
private \Magento\Sales\Model\Order\CreditmemoFactory $creditmemoFactory;

/**
* CreditmemoByOrderIncrementId constructor.
Expand Down
16 changes: 6 additions & 10 deletions Model/OrderRelatedDataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@

class OrderRelatedDataRepository implements OrderRelatedDataRepositoryInterface
{
/** @var ResourceModel\OrderRelatedData */
protected $resource;
protected \SnowIO\ExtendedSalesRepositories\Model\ResourceModel\OrderRelatedData $resource;

/** @var OrderRelatedDataFactory */
protected $factory;
protected \SnowIO\ExtendedSalesRepositories\Model\OrderRelatedDataFactory $factory;

/** @var SearchCriteriaBuilder */
private $searchCriteriaBuilder;
private \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder;

/** @var OrderRelatedDataSearchResultsInterfaceFactory */
private $searchResultsFactory;
private \SnowIO\ExtendedSalesRepositories\Api\Data\OrderRelatedDataSearchResultsInterfaceFactory $searchResultsFactory;

public function __construct(
OrderRelatedDataFactory $factory,
Expand Down Expand Up @@ -66,7 +62,7 @@ public function save(OrderRelatedDataInterface $orderRelatedData)
return $orderRelatedData;

} catch (\Exception $exception) {
throw new CouldNotSaveException(__($exception->getMessage()));
throw new CouldNotSaveException(__($exception->getMessage()), $exception);
}
}

Expand Down Expand Up @@ -155,7 +151,7 @@ public function delete(OrderRelatedDataInterface $orderRelatedData)
try {
$this->resource->delete($orderRelatedData);
} catch (\Exception $exception) {
throw new CouldNotDeleteException(__($exception->getMessage()));
throw new CouldNotDeleteException(__($exception->getMessage()), $exception);
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions Model/ShipOrderByIncrementId.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
class ShipOrderByIncrementId implements ShipOrderByIncrementIdInterface
{

private $shipOrder;
private $orderRepository;
private \Magento\Sales\Api\ShipOrderInterface $shipOrder;
private \Magento\Sales\Api\OrderRepositoryInterface $orderRepository;

public function __construct(OrderRepositoryInterface $orderRepository, ShipOrderInterface $shipOrder)
{
Expand Down
20 changes: 12 additions & 8 deletions Plugin/OrderRepositoryPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@

class OrderRepositoryPlugin
{
/** @var OrderRelatedDataRepositoryInterface */
private $orderRelatedDataRepository;

/** @var OrderExtensionFactory */
private $orderExtensionFactory;
public ExtensionAttributesFactory $extensionAttributesFactory;
private OrderRelatedDataRepositoryInterface $orderRelatedDataRepository;
private OrderExtensionFactory $orderExtensionFactory;

/**
* OrderRepositoryPlugin constructor.
* @param OrderExtensionFactory $orderExtensionFactory
* @param OrderRelatedDataRepositoryInterface $orderRelatedDataRepository
* @param ExtensionAttributesFactory $extensionAttributesFactory
*/
public function __construct(
OrderExtensionFactory $orderExtensionFactory,
OrderRelatedDataRepositoryInterface $orderRelatedDataRepository,
ExtensionAttributesFactory $extensionAttributesFactory
)
{
$this->orderExtensionFactory = $orderExtensionFactory;
$this->orderRelatedDataRepository = $orderRelatedDataRepository;
$this->extensionAttributesFactory = $extensionAttributesFactory;
}
Expand Down Expand Up @@ -54,9 +60,7 @@ private function getRelatedDataExtensionAttributes($order)

$relatedDataItems = $this->orderRelatedDataRepository->getAllByIncrementId($order->getIncrementId());
if ($relatedDataItems) {
$relatedData = array_map(function(OrderRelatedDataInterface $item){
return [$item->getCode() => $item->getValue()];
}, $relatedDataItems);
$relatedData = array_map(fn(OrderRelatedDataInterface $item) => [$item->getCode() => $item->getValue()], $relatedDataItems);
$orderExtensionAttributes->setSnowioRelateddata($relatedData);
}
return $orderExtensionAttributes;
Expand Down
2 changes: 1 addition & 1 deletion Plugin/ShipmentRepositoryExtensionPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class ShipmentRepositoryExtensionPlugin
{
private $orderRepository;
private \Magento\Sales\Api\OrderRepositoryInterface $orderRepository;

public function __construct(OrderRepositoryInterface $orderRepository)
{
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# snowio-extended-sales-repositories
Magento 2 module that exposes additional payment attributes as AdditionalInformationFields in ExtendedAttributes

### Magento Versions
- <= 2.3.x use 2.x tags
- >= 2.4.x use master
132 changes: 0 additions & 132 deletions Setup/UpgradeSchema.php

This file was deleted.

9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
}
],
"require": {
"php": ">=5.6",
"magento/module-sales": "^100.1.2|^101.0.2|^102.0.1",
"magento/framework": "^100.1.2|^101.0.2|^102.0.1"
"php": "^7.4",
"magento/module-sales": "^103",
"magento/framework": "^103"
},
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
"SnowIO\\ExtendedSalesRepositories\\": ""
}
},
"require-dev": {
"rector/rector": "^0.8.56"
}
}
22 changes: 22 additions & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="snowio_order_relateddata" resource="default" engine="innodb" comment="Persist Key/Value information to reference to an Order">
<column xsi:type="int" name="id" padding="10" unsigned="true" nullable="false" identity="true" comment="ID"/>
<column xsi:type="varchar" name="order_increment_id" nullable="false" length="50" comment="Order Increment Id"/>
<column xsi:type="varchar" name="code" nullable="false" length="255" comment="Key for the Data"/>
<column xsi:type="varchar" name="value" nullable="true" length="255" comment="Value for the Data"/>
<column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
<column xsi:type="timestamp" name="updated_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="id"/>
<column name="id"/>
</constraint>
<constraint xsi:type="unique" referenceId="SNOWIO_ORDER_RELATEDDATA_ORDER_INCREMENT_ID_CODE">
<column name="order_increment_id"/>
<column name="code"/>
</constraint>
<index referenceId="SNOWIO_ORDER_RELATEDDATA_ORDER_INCREMENT_ID" indexType="btree">
<column name="order_increment_id"/>
</index>
</table>
</schema>
19 changes: 19 additions & 0 deletions etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"snowio_order_relateddata": {
"column": {
"id": true,
"order_increment_id": true,
"code": true,
"value": true,
"created_at": true,
"updated_at": true
},
"index": {
"SNOWIO_ORDER_RELATEDDATA_ORDER_INCREMENT_ID": true
},
"constraint": {
"PRIMARY": true,
"SNOWIO_ORDER_RELATEDDATA_ORDER_INCREMENT_ID_CODE": true
}
}
}
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="SnowIO_ExtendedSalesRepositories" setup_version="1.1.1">
<module name="SnowIO_ExtendedSalesRepositories">
<sequence>
<module name="Magento_Sales"/>
</sequence>
Expand Down
27 changes: 27 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
__DIR__ . '/Api',
__DIR__ . '/Model',
__DIR__ . '/Plugin',
__DIR__ . '/Setup'
]);
$parameters->set(Option::SETS, [
SetList::PHPSTAN,
SetList::DEAD_CODE,
SetList::EARLY_RETURN,
SetList::CODE_QUALITY,
SetList::PHP_73,
SetList::PHP_74,
]);
$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class);
};

0 comments on commit 298cf4f

Please sign in to comment.