Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #393

Merged
merged 31 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d897a57
[EX-466] Refactor Order Create functionality
boorlyk Apr 28, 2023
ab78b18
[EX-466] Refactor Order Create functionality
boorlyk May 17, 2023
bff9e38
Merge remote-tracking branch 'origin/master' into EX-466
boorlyk May 17, 2023
f962423
[EX-466] Refactor Order Create functionality
boorlyk May 18, 2023
c335559
[EX-466] Refactor Order Create functionality
boorlyk May 19, 2023
3aa25a9
[EX-466] Refactor Order Create functionality
boorlyk May 19, 2023
c018b82
[EX-466] Refactor Order Create functionality
boorlyk May 22, 2023
811457f
[EX-466] Refactor Order Create functionality
boorlyk May 22, 2023
aa8cb79
[EX-466] Refactor Order Create functionality
boorlyk May 22, 2023
2c224f2
Merge pull request #383 from helloextend/EX-466
ahofstetter May 22, 2023
2ae702c
branch update deployment
martin-liriano May 22, 2023
639d2ba
[EX-477] [M2] Admin post-purchase lead offer does not take into accou…
boorlyk May 23, 2023
151e933
Merge branch 'develop' into EX-477
boorlyk May 23, 2023
aef6a2b
Merge pull request #385 from helloextend/EX-477
ahofstetter May 23, 2023
60b38fa
branch update deployment
martin-liriano May 23, 2023
5eb9084
[EX-484] [M2] Pass 'price' and 'category' parameters & values to the …
boorlyk May 23, 2023
704beed
[EX-466] Refactor Order Create functionality
boorlyk May 23, 2023
a427055
[EX-466] Refactor Order Create functionality
boorlyk May 23, 2023
ce01261
[EX-466] Refactor Order Create functionality
boorlyk May 23, 2023
5f4e8d9
Merge pull request #388 from helloextend/EX-466
ahofstetter May 23, 2023
78e6099
branch update deployment
martin-liriano May 23, 2023
44b5b83
[EX-484] [M2] Pass 'price' and 'category' parameters & values to the …
boorlyk May 24, 2023
3538972
[EX-484] [M2] Pass 'price' and 'category' parameters & values to the …
boorlyk May 24, 2023
8277741
Merge branch 'develop' into EX-484
boorlyk May 24, 2023
2590fe8
Merge pull request #389 from helloextend/EX-484
ahofstetter May 24, 2023
79955a8
branch update deployment
martin-liriano May 24, 2023
a9c944c
[EX-484] [M2] Pass 'price' and 'category' parameters & values to the …
boorlyk May 24, 2023
cbd8a7a
Merge pull request #391 from helloextend/EX-484
ahofstetter May 24, 2023
6a7f3b1
branch update deployment
martin-liriano May 24, 2023
f6c070e
SEINT-1701 Updated highest PHP version to 8.2
Johnathnnault Jul 24, 2023
31c344e
branch update deployment
martin-liriano Jul 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/branch_changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
SEINT-1701 Updated highest PHP version to 8.2

Merge pull request #391 from helloextend/EX-484

[EX-484] [M2] Pass 'price' and 'category' parameters & values to the …

Merge pull request #389 from helloextend/EX-484

Ex 484

Merge pull request #388 from helloextend/EX-466

Ex 466

Merge pull request #385 from helloextend/EX-477

Ex 477

Merge pull request #383 from helloextend/EX-466

Ex 466

Update composer.json

Update composer.json version to v2.2.1

Merge pull request #379 from helloextend/EX-486

[EX-486] [M2] Missing logging for add to cart failures, and overall n…

Merge pull request #380 from helloextend/EX-487

[EX-487] [M2] cart and minicart normalization not running after remov…
20 changes: 20 additions & 0 deletions Api/Data/ExtendOrderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Extend Warranty
*
* @author Extend Magento Team <[email protected]>
* @category Extend
* @package Warranty
* @copyright Copyright (c) 2023 Extend Inc. (https://www.extend.com/)
*/


namespace Extend\Warranty\Api\Data;

interface ExtendOrderInterface
{

public function getOrderId();

public function getExtendOrderId();
}
9 changes: 7 additions & 2 deletions Block/Adminhtml/Order/Create/Installation.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?php
/**
* @author Guidance Magento Team <[email protected]>
* @copyright Copyright (c) 2023 Guidance Solutions (http://www.guidance.com)
* Extend Warranty
*
* @author Extend Magento Team <[email protected]>
* @category Extend
* @package Warranty
* @copyright Copyright (c) 2023 Extend Inc. (https://www.extend.com/)
*/


namespace Extend\Warranty\Block\Adminhtml\Order\Create;

use Magento\Backend\Block\Template;
Expand Down
4 changes: 2 additions & 2 deletions Helper/Api/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ public function getContractCreateEvent(
* @return bool
*/
public function isContractCreateModeScheduled(
string $scopeType = ScopeInterface::SCOPE_STORES,
$scopeId = null
$scopeId = null,
string $scopeType = ScopeInterface::SCOPE_STORES
) {
return $this->scopeConfig->isSetFlag(
self::WARRANTY_CONTRACTS_MODE_XML_PATH,
Expand Down
34 changes: 20 additions & 14 deletions Model/Api/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,30 @@ public function call(
array $data = []
): Response
{
switch (strtoupper($method)) {
case "GET":
/** @var ClientInterface $client */
$client = $this->callGet($endpoint, $headers);
break;
case "POST":
/** @var ClientInterface $client */
$client = $this->callPost($endpoint, $headers, $data);
break;
}

/** @var Response $response */
$response = $this->responseFactory->create();

$response->setBody($client->getBody())
->setRequestEndpoint($endpoint)
->setHeaders($client->getHeaders())
->setStatusCode($client->getStatus());
try {
switch (strtoupper($method)) {
case "GET":
/** @var ClientInterface $client */
$client = $this->callGet($endpoint, $headers);
break;
case "POST":
/** @var ClientInterface $client */
$client = $this->callPost($endpoint, $headers, $data);
break;
}

$response->setBody($client->getBody())
->setRequestEndpoint($endpoint)
->setHeaders($client->getHeaders())
->setStatusCode($client->getStatus());
} catch (\Exception $e) {
$this->logger->critical($e->getMessage());
}

return $response;
}
}
2 changes: 2 additions & 0 deletions Model/Api/Request/ContractBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* Class ContractBuilder
*
* Warranty ContractBuilder
*
* @deprecated 1.3.0 Orders API should be used in all circumstances instead of the Contracts API
*/
class ContractBuilder
{
Expand Down
255 changes: 255 additions & 0 deletions Model/Api/Request/FullOrderBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
<?php
/**
* Extend Warranty
*
* @author Extend Magento Team <[email protected]>
* @category Extend
* @package Warranty
* @copyright Copyright (c) 2023 Extend Inc. (https://www.extend.com/)
*/

namespace Extend\Warranty\Model\Api\Request;

use Extend\Warranty\Helper\Data as DataHelper;
use Extend\Warranty\Helper\Api\Data as ApiDataHelper;
use Extend\Warranty\Model\WarrantyRelation;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Locale\Currency;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderItemInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Directory\Api\CountryInformationAcquirerInterface;
use Extend\Warranty\Model\Product\Type;
use Exception;

class FullOrderBuilder
{
/**
* Platform code
*/
public const PLATFORM_CODE = 'magento';

/**
* Product Repository Interface
*
* @var ProductRepositoryInterface
*/
private $productRepository;

/**
* Store Manager Interface
*
* @var StoreManagerInterface
*/
private $storeManager;

/**
* Country Information Acquirer Interface
*
* @var CountryInformationAcquirerInterface
*/
private $countryInformationAcquirer;

/**
* Data Helper
*
* @var DataHelper
*/
private $helper;

/**
* Extend API helper
*
* @var ApiDataHelper
*/
private $apiHelper;

/**
* @var WarrantyRelation
*/
private $warrantyRelation;

/**
* @var ProductDataBuilder
*/
protected $productDataBuilder;

/**
* @var LineItemBuilderFactory
*/
protected $lineItemBuilderFactory;

/**
* @param StoreManagerInterface $storeManager
* @param ProductRepositoryInterface $productRepository
* @param CountryInformationAcquirerInterface $countryInformationAcquirer
* @param DataHelper $helper
* @param ApiDataHelper $apiHelper
* @param WarrantyRelation $warrantyRelation
* @param ProductDataBuilder $productDataBuilder
* @param LineItemBuilderFactory $lineItemBuilder
*/
public function __construct(
StoreManagerInterface $storeManager,
ProductRepositoryInterface $productRepository,
CountryInformationAcquirerInterface $countryInformationAcquirer,
DataHelper $helper,
ApiDataHelper $apiHelper,
WarrantyRelation $warrantyRelation,
ProductDataBuilder $productDataBuilder,
LineItemBuilderFactory $lineItemBuilder
)
{
$this->productRepository = $productRepository;
$this->storeManager = $storeManager;
$this->countryInformationAcquirer = $countryInformationAcquirer;
$this->helper = $helper;
$this->apiHelper = $apiHelper;
$this->warrantyRelation = $warrantyRelation;
$this->productDataBuilder = $productDataBuilder;
$this->lineItemBuilderFactory = $lineItemBuilder;
}

/**
* Prepare payload
*
* @param OrderInterface $order
* @param OrderItemInterface $orderItem
* @param int $qty
* @param string $type
*
* @return array
* @throws NoSuchEntityException
*/
public function preparePayload(
OrderInterface $order
): array
{
$storeId = $order->getStoreId();

$extendStoreId = $this->apiHelper->getStoreId(ScopeInterface::SCOPE_STORES, $storeId);
$extendStoreName = $this->apiHelper->getStoreName(ScopeInterface::SCOPE_STORES, $storeId);

$store = $this->storeManager->getStore($storeId);
$currencyCode = $order->getOrderCurrencyCode() ?: $store->getBaseCurrencyCode() ?? Currency::DEFAULT_CURRENCY;

$transactionTotal = $this->helper->formatPrice($order->getGrandTotal());

foreach ($order->getItems() as $orderItem) {
if ($orderItem->getParentItem()) {
continue;
}

/** @var LineItemBuilder $lineItemBuilder */
$lineItemBuilder = $this->lineItemBuilderFactory->create(['item' => $orderItem]);
if ($lineItem = $lineItemBuilder->preparePayload()) {
$lineItems[] = $lineItem;
}
}

if (empty($lineItems)) {
return [];
}

$saleOrigin = [
'platform' => self::PLATFORM_CODE,
];

$createdAt = $order->getCreatedAt();
$customerData = $this->getCustomerData($order);

if (empty($customerData)) {
return [];
}

return [
'isTest' => !$this->apiHelper->isExtendLive(ScopeInterface::SCOPE_STORES, $storeId),
'currency' => $currencyCode,
'createdAt' => $createdAt ? strtotime($createdAt) : 0,
'customer' => $customerData,
'lineItems' => $lineItems,
'total' => $transactionTotal,
'taxCostTotal' => $this->helper->formatPrice($order->getTaxAmount()),
'productCostTotal' => $this->helper->formatPrice($order->getSubtotal()),
'discountAmountTotal' => $this->helper->formatPrice(abs($order->getDiscountAmount())),
'shippingCostTotal' => $this->helper->formatPrice($order->getShippingAmount()),
'shippingTaxCostTotal' => $this->helper->formatPrice($order->getShippingTaxAmount()),
'storeId' => $extendStoreId,
'storeName' => $extendStoreName,
'transactionId' => $order->getIncrementId(),
'saleOrigin' => $saleOrigin,
];
}

/**
* Format street
*
* @param array $street
* @return array
*/
protected function formatStreet(array $street = []): array
{
$address = [];

$address['address1'] = array_shift($street);
if (!empty($street)) {
$address['address2'] = implode(",", $street);
}

return $address;
}


/**
* Prepare customer data
*
* @param OrderInterface $order
* @return array
* @throws NoSuchEntityException
*/
protected function getCustomerData(OrderInterface $order): array
{
$customer = [];
$billingAddress = $order->getBillingAddress();
if ($billingAddress) {
$billingCountryId = $billingAddress->getCountryId();
$billingCountryInfo = $this->countryInformationAcquirer->getCountryInfo($billingCountryId);
$billingStreet = $this->formatStreet($billingAddress->getStreet());

$customer = [
'name' => $this->helper->getCustomerFullName($order),
'email' => $order->getCustomerEmail(),
'phone' => $billingAddress->getTelephone(),
'billingAddress' => [
'address1' => $billingStreet['address1'] ?? '',
'address2' => $billingStreet['address2'] ?? '',
'city' => $billingAddress->getCity(),
'countryCode' => $billingCountryInfo->getThreeLetterAbbreviation(),
'postalCode' => $billingAddress->getPostcode(),
'province' => $billingAddress->getRegionCode() ?? ''
],
];
}

$shippingAddress = $order->getShippingAddress();
if ($shippingAddress) {
$shippingCountryId = $shippingAddress->getCountryId();
$shippingCountryInfo = $this->countryInformationAcquirer->getCountryInfo($shippingCountryId);
$shippingStreet = $this->formatStreet($shippingAddress->getStreet());

$customer['shippingAddress'] = [
'address1' => $shippingStreet['address1'] ?? '',
'address2' => $shippingStreet['address2'] ?? '',
'city' => $shippingAddress->getCity(),
'countryCode' => $shippingCountryInfo->getThreeLetterAbbreviation(),
'postalCode' => $shippingAddress->getPostcode(),
];
}

return $customer;
}
}
Loading