-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Returnless-com/staging_giftcard_ee
Gift cards instead of coupons for Adobe Commerce users
- Loading branch information
Showing
11 changed files
with
255 additions
and
8 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,18 @@ | ||
<?php | ||
|
||
namespace Returnless\Connector\Api; | ||
|
||
/** | ||
* Interface GiftCardAccountInterface | ||
*/ | ||
interface GiftCardAccountInterface | ||
{ | ||
/** | ||
* Creates Coupon By the Request Params | ||
* | ||
* @api | ||
* @param $requestParams | ||
* @return mixed | ||
*/ | ||
public function createGiftCardAccount($requestParams); | ||
} |
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
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,113 @@ | ||
<?php | ||
|
||
namespace Returnless\Connector\Model\Api; | ||
|
||
use Returnless\Connector\Api\GiftCardAccountInterface; | ||
use Magento\Framework\Module\ResourceInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\GiftCardAccount\Model\Giftcardaccount as GiftCardModel; | ||
use Magento\GiftCardAccount\Model\Pool; | ||
use Psr\Log\LoggerInterface; | ||
use Magento\Sales\Model\Order; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* Interface OrderCoupon | ||
*/ | ||
class GiftCardAccount implements GiftCardAccountInterface | ||
{ | ||
/** | ||
* const NAMESPACE_MODULE | ||
*/ | ||
const NAMESPACE_MODULE = 'Returnless_Connector'; | ||
|
||
/** | ||
* @var ResourceInterface | ||
*/ | ||
private $moduleResource; | ||
|
||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @var Order | ||
*/ | ||
private $orderModel; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @param ResourceInterface $moduleResource | ||
* @param ObjectManagerInterface $objectManager | ||
* @param LoggerInterface $logger | ||
* @param Order $orderModel | ||
* @param StoreManagerInterface $storeManager | ||
*/ | ||
public function __construct( | ||
ResourceInterface $moduleResource, | ||
ObjectManagerInterface $objectManager, | ||
LoggerInterface $logger, | ||
Order $orderModel, | ||
StoreManagerInterface $storeManager | ||
) { | ||
$this->moduleResource = $moduleResource; | ||
$this->objectManager = $objectManager; | ||
$this->logger = $logger; | ||
$this->orderModel = $orderModel; | ||
$this->storeManager = $storeManager; | ||
} | ||
|
||
/** | ||
* @param $requestParams | ||
* @return array | ||
*/ | ||
public function createGiftCardAccount($requestParams) | ||
{ | ||
$response['installed_module_version'] = $this->moduleResource->getDbVersion(self::NAMESPACE_MODULE); | ||
$codePool = $this->objectManager->create(Pool::class); | ||
$codes = $codePool->getCollection()->addFieldToFilter('status', Pool::STATUS_FREE)->getSize(); | ||
if (!$codes) { | ||
$codePool->generatePool(); | ||
} | ||
$model = $this->objectManager->create(GiftCardModel::class); | ||
$order = $this->orderModel->loadByIncrementId($requestParams['order_id']); | ||
if ($order->getId()) { | ||
try { | ||
$websiteId = $this->storeManager->getStore($order->getStoreId())->getWebsiteId(); | ||
} catch (\Exception $e) { | ||
$websiteId = $this->storeManager->getDefaultStoreView()->getWebsiteId(); | ||
$this->logger->error($e->getMessage()); | ||
} | ||
} else { | ||
$websiteId = $this->storeManager->getDefaultStoreView()->getWebsiteId(); | ||
} | ||
$data = [ | ||
'status' => 1, | ||
'is_redeemable' => 1, | ||
'website_id' => $websiteId, | ||
'balance' => $requestParams['coupon_amount'], | ||
]; | ||
$model->addData($data); | ||
|
||
try { | ||
$model->save(); | ||
if ($model->getId()) { | ||
$response['result']['coupon_id'] = $model->getId(); | ||
$response['result']['coupon_code'] = $model->getCode(); | ||
} | ||
} catch (\Exception $e) { | ||
$this->logger->error($e->getMessage()); | ||
} | ||
return $response; | ||
} | ||
} |
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
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,46 @@ | ||
<?php | ||
|
||
namespace Returnless\Connector\Model\Config\Frontend; | ||
|
||
use Magento\Config\Block\System\Config\Form\Field; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Magento\Framework\App\ProductMetadataInterface; | ||
use Magento\Backend\Block\Template\Context; | ||
|
||
/** | ||
* Class GenerationType | ||
*/ | ||
class GenerationType extends Field | ||
{ | ||
protected $productMetadata; | ||
|
||
public function __construct( | ||
ProductMetadataInterface $productMetadata, | ||
Context $context, | ||
array $data = [] | ||
) { | ||
$this->productMetadata = $productMetadata; | ||
parent::__construct($context, $data); | ||
} | ||
|
||
/** | ||
* Render connection button considering request parameter | ||
* | ||
* @param AbstractElement $element | ||
* @return string | ||
*/ | ||
public function render(AbstractElement $element) | ||
{ | ||
if (strtolower($this->productMetadata->getEdition()) == 'enterprise' || | ||
strtolower($this->productMetadata->getEdition()) == 'b2b') { | ||
return parent::render($element); | ||
} | ||
//$isConnected = $this->_scopeConfig->isSetFlag(Config::XML_PATH_QBONLINE_IS_CONNECTED); | ||
//if ($isConnected) { | ||
//$element->setDisabled(true); | ||
//} | ||
|
||
|
||
return $this->productMetadata->getVersion() . ' ' . $this->productMetadata->getEdition();//parent::render($element); | ||
} | ||
} |
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 Returnless\Connector\Model\Config\Source; | ||
|
||
use Magento\Framework\Data\OptionSourceInterface; | ||
|
||
/** | ||
* Class GenerationType | ||
* @package Returnless\Connector\Model\Config\Source | ||
*/ | ||
class GenerationType implements OptionSourceInterface | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
return | ||
[ | ||
[ | ||
'value' => 'coupon', | ||
'label' => __('Coupon code') | ||
], | ||
[ | ||
'value' => 'gift', | ||
'label' => __('Gift card') | ||
] | ||
]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -17,5 +17,5 @@ | |
"OSL-3.0", | ||
"AFL-3.0" | ||
], | ||
"version": "1.2.0" | ||
"version": "1.2.1" | ||
} |
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
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
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
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