-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alexsolonenko
committed
Feb 7, 2023
1 parent
3c33196
commit a64bf57
Showing
18 changed files
with
440 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
namespace Commerce365\MagentoApiExtensions\Api; | ||
|
||
/** | ||
* Category Management Interface. | ||
* | ||
* Additional admin methods to manage your Magento categories. | ||
* | ||
* @api | ||
* @since 0.0.1 | ||
*/ | ||
interface CategoryManagementInterface | ||
{ | ||
/** | ||
* Put category position (within tree) | ||
* | ||
* @api | ||
* @param int $categoryId | ||
* @param int $new | ||
* @return boolean | ||
*/ | ||
public function updatePosition($categoryId, $new); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
namespace Commerce365\MagentoApiExtensions\Api; | ||
|
||
/** | ||
* Magento Management Interface. | ||
* | ||
* Additional admin method to obtain the current Magento version. | ||
* | ||
* @api | ||
* @since 0.0.4 | ||
*/ | ||
interface MagentoManagementInterface | ||
{ | ||
/** | ||
* Get current Magento version | ||
* | ||
* @api | ||
* @return string | ||
*/ | ||
public function getMagentoVersion(); | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
namespace Commerce365\MagentoApiExtensions\Api; | ||
|
||
/** | ||
* Payment Method Management Interface. | ||
* | ||
* Additional admin method to retrieve a list of installed payment methods. | ||
* | ||
* @api | ||
* @since 0.0.3 | ||
*/ | ||
interface PaymentMethodManagementInterface | ||
{ | ||
/** | ||
* Get active payment methods | ||
* | ||
* @api | ||
* @return string[] | ||
*/ | ||
public function getActiveMethods(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
namespace Commerce365\MagentoApiExtensions\Api; | ||
|
||
/** | ||
* Sales Management Interface. | ||
* | ||
* Additional admin method to create a custom order status. | ||
* | ||
* @api | ||
* @since 0.0.5 | ||
*/ | ||
interface SalesManagementInterface | ||
{ | ||
/** | ||
* Post a new order status to make sure Magento knows the status NAV/BC is using | ||
* | ||
* @api | ||
* @param string $statusCode | ||
* @param string $statusLabel | ||
* @return boolean | ||
*/ | ||
public function createOrderStatus($statusCode, $statusLabel); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
namespace Commerce365\MagentoApiExtensions\Api; | ||
|
||
/** | ||
* Shipping Method Management Interface. | ||
* | ||
* Additional admin method to retrieve a list of installed shipping methods. | ||
* | ||
* @api | ||
* @since 0.0.3 | ||
*/ | ||
interface ShippingMethodManagementInterface | ||
{ | ||
/** | ||
* Get active carriers / shipping methods | ||
* | ||
* @api | ||
* @return string[] | ||
*/ | ||
public function getActiveMethods(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
namespace Commerce365\MagentoApiExtensions\Model; | ||
use Commerce365\MagentoApiExtensions\Api\CategoryManagementInterface; | ||
|
||
class Category implements CategoryManagementInterface | ||
{ | ||
|
||
/** | ||
* Put category position (within tree) | ||
* | ||
* @api | ||
* @param int $categoryId | ||
* @param int $new | ||
* @return boolean | ||
*/ | ||
public function updatePosition($categoryId, $new){ | ||
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | ||
$category = $objectManager->create('Magento\Catalog\Model\Category')->load($categoryId); | ||
|
||
if (!$category->getId()) | ||
throw new Exception("Category does not exist"); | ||
|
||
$category->setPosition($new); | ||
|
||
$objectManager->get('\Magento\Catalog\Api\CategoryRepositoryInterface')->save($category); | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
namespace Commerce365\MagentoApiExtensions\Model; | ||
use Commerce365\MagentoApiExtensions\Api\MagentoManagementInterface; | ||
use Magento\Framework\App\ProductMetadataInterface; | ||
|
||
class Magento implements MagentoManagementInterface | ||
{ | ||
|
||
protected $productMetadata; | ||
|
||
public function __construct(ProductMetadataInterface $productMetadata) { | ||
$this->productMetadata = $productMetadata; | ||
} | ||
|
||
/** | ||
* Get current Magento version | ||
* | ||
* @api | ||
* @return string | ||
*/ | ||
public function getMagentoVersion(){ | ||
return $this->productMetadata->getVersion(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
namespace Commerce365\MagentoApiExtensions\Model; | ||
use Commerce365\MagentoApiExtensions\Api\PaymentMethodManagementInterface; | ||
|
||
class PaymentMethod implements PaymentMethodManagementInterface | ||
{ | ||
|
||
protected $scopeConfig; | ||
|
||
protected $paymentConfig; | ||
|
||
public function __construct( | ||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, | ||
\Magento\Payment\Model\Config $paymentConfig | ||
) { | ||
$this->paymentConfig= $paymentConfig; | ||
$this->scopeConfig = $scopeConfig; | ||
} | ||
|
||
/** | ||
* Get active payment methods | ||
* | ||
* @api | ||
* @return object | ||
*/ | ||
public function getActiveMethods(){ | ||
|
||
$activeMethods = $this->paymentConfig->getActiveMethods(); | ||
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; | ||
$methods = array(); | ||
|
||
foreach($activeMethods as $paymentCode => $paymentModel) | ||
{ | ||
$paymentTitle = $this->scopeConfig->getValue('payment/'.$paymentCode.'/title'); | ||
$methods[$paymentCode] = array( | ||
'label' => $paymentTitle, | ||
'value' => $paymentCode | ||
); | ||
} | ||
|
||
return $methods; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
namespace Commerce365\MagentoApiExtensions\Model; | ||
|
||
use Commerce365\MagentoApiExtensions\Api\SalesManagementInterface; | ||
|
||
use Magento\Framework\Exception\AlreadyExistsException; | ||
use Magento\Sales\Model\Order; | ||
use Magento\Sales\Model\Order\StatusFactory; | ||
use Magento\Sales\Model\ResourceModel\Order\StatusFactory as StatusResourceFactory; | ||
|
||
class Sales implements SalesManagementInterface | ||
{ | ||
protected StatusFactory $statusFactory; | ||
protected StatusResourceFactory $statusResourceFactory; | ||
|
||
public function __construct(StatusFactory $statusFactory, StatusResourceFactory $statusResourceFactory) | ||
{ | ||
$this->statusFactory = $statusFactory; | ||
$this->statusResourceFactory = $statusResourceFactory; | ||
} | ||
|
||
/** | ||
* Post a new order status to make sure Magento knows the status NAV/BC is using | ||
* | ||
* @api | ||
* @param string $statusCode | ||
* @param string $statusLabel | ||
* @return boolean | ||
*/ | ||
public function createOrderStatus($statusCode, $statusLabel) | ||
{ | ||
$statusResource = $this->statusResourceFactory->create(); | ||
$status = $this->statusFactory->create(); | ||
$status->setData([ | ||
'status' => $statusCode, | ||
'label' => $statusLabel, | ||
]); | ||
|
||
try { | ||
$statusResource->save($status); | ||
} catch (AlreadyExistsException $exception) { | ||
return; | ||
} | ||
|
||
$status->assignState(Order::STATE_PROCESSING, false, true); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
namespace Commerce365\MagentoApiExtensions\Model; | ||
use Commerce365\MagentoApiExtensions\Api\ShippingMethodManagementInterface; | ||
|
||
class ShippingMethod implements ShippingMethodManagementInterface | ||
{ | ||
|
||
protected $scopeConfig; | ||
|
||
protected $shipmentConfig; | ||
|
||
public function __construct( | ||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, | ||
\Magento\Shipping\Model\Config $shipmentConfig | ||
) { | ||
$this->shipmentConfig = $shipmentConfig; | ||
$this->scopeConfig = $scopeConfig; | ||
} | ||
|
||
/** | ||
* Get active carriers / shipping methods | ||
* | ||
* @api | ||
* @return object | ||
*/ | ||
public function getActiveMethods(){ | ||
|
||
$activeCarriers = $this->shipmentConfig->getActiveCarriers(); | ||
$methods = array(); | ||
|
||
foreach($activeCarriers as $carrierCode => $carrierModel) | ||
{ | ||
$carrierTitle =$this->scopeConfig->getValue('carriers/'.$carrierCode.'/title'); | ||
|
||
if( $carrierMethods = $carrierModel->getAllowedMethods() ) | ||
{ | ||
foreach ($carrierMethods as $methodCode => $method) | ||
{ | ||
$code= $carrierCode.'_'.$methodCode; | ||
$methods[]=array( | ||
'label'=>$carrierTitle, | ||
'value'=>$code | ||
); | ||
} | ||
} | ||
} | ||
|
||
return $methods; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Commerce365\MagentoApiExtensions\Plugin; | ||
|
||
use Magento\Catalog\Api\Data\ProductAttributeInterface; | ||
use Magento\Catalog\Model\Attribute as AttributeModel; | ||
|
||
class ProductAttributeExtensionAttributes | ||
{ | ||
public function afterGetAttributes( | ||
\Magento\Catalog\Api\ProductAttributeManagementInterface $subject, | ||
$searchResult | ||
) { | ||
foreach ($searchResult as &$attribute) { | ||
$extensionAttributes = $attribute->getExtensionAttributes(); | ||
if($attribute->getAttributeGroupId()){ | ||
$extensionAttributes->setAttributeGroupId($attribute->getAttributeGroupId()); | ||
$extensionAttributes->setEntityAttributeId($attribute->getEntityAttributeId()); | ||
$extensionAttributes->setSortOrder($attribute->getSortOrder()); | ||
} | ||
$attribute->setExtensionAttributes($extensionAttributes); | ||
} | ||
return $searchResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "commerce365/module-apiextensions", | ||
"version": "1.0.0", | ||
"description": "N/A", | ||
"type": "magento2-module", | ||
"require": { | ||
"magento/framework": "*", | ||
"magento/module-sales": "*" | ||
}, | ||
"license": [ | ||
"" | ||
], | ||
"autoload": { | ||
"files": [ | ||
"registration.php" | ||
], | ||
"psr-4": { | ||
"Commerce365\\MagentoApiExtensions\\\\": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
|
||
<preference for="Commerce365\MagentoApiExtensions\Api\CategoryManagementInterface" | ||
type="Commerce365\MagentoApiExtensions\Model\Category" /> | ||
|
||
<preference for="Commerce365\MagentoApiExtensions\Api\ShippingMethodManagementInterface" | ||
type="Commerce365\MagentoApiExtensions\Model\ShippingMethod" /> | ||
|
||
<preference for="Commerce365\MagentoApiExtensions\Api\PaymentMethodManagementInterface" | ||
type="Commerce365\MagentoApiExtensions\Model\PaymentMethod" /> | ||
|
||
<preference for="Commerce365\MagentoApiExtensions\Api\MagentoManagementInterface" | ||
type="Commerce365\MagentoApiExtensions\Model\Magento" /> | ||
|
||
<preference for="Commerce365\MagentoApiExtensions\Api\SalesManagementInterface" | ||
type="Commerce365\MagentoApiExtensions\Model\Sales" /> | ||
</config> |
Oops, something went wrong.