-
Notifications
You must be signed in to change notification settings - Fork 41
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 #74 from magmodules/1.4.11
1.4.11
- Loading branch information
Showing
6 changed files
with
148 additions
and
50 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 |
---|---|---|
|
@@ -9,9 +9,9 @@ | |
use Magento\Framework\App\Helper\AbstractHelper; | ||
use Magento\Framework\App\Helper\Context; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magmodules\Channable\Helper\General as GeneralHelper; | ||
use Magento\Catalog\Model\ProductFactory; | ||
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory as OrderCollectionFactory; | ||
use Magmodules\Channable\Helper\General as GeneralHelper; | ||
use Magmodules\Channable\Service\Order\TestData; | ||
|
||
/** | ||
* Class Order | ||
|
@@ -43,6 +43,7 @@ class Order extends AbstractHelper | |
const XPATH_TAX_SHIPPING = 'tax/calculation/shipping_includes_tax'; | ||
const XPATH_SHIPPING_TAX_CLASS = 'tax/classes/shipping_tax_class'; | ||
const XPATH_CUSTOMER_STREET_LINES = 'customer/address/street_lines'; | ||
|
||
/** | ||
* @var General | ||
*/ | ||
|
@@ -52,9 +53,9 @@ class Order extends AbstractHelper | |
*/ | ||
private $storeManager; | ||
/** | ||
* @var ProductFactory | ||
* @var TestData | ||
*/ | ||
private $product; | ||
private $testData; | ||
/** | ||
* @var OrderCollectionFactory | ||
*/ | ||
|
@@ -66,19 +67,19 @@ class Order extends AbstractHelper | |
* @param Context $context | ||
* @param StoreManagerInterface $storeManager | ||
* @param General $generalHelper | ||
* @param ProductFactory $product | ||
* @param TestData $testData | ||
* @param OrderCollectionFactory $orderCollectionFactory | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
StoreManagerInterface $storeManager, | ||
GeneralHelper $generalHelper, | ||
ProductFactory $product, | ||
TestData $testData, | ||
OrderCollectionFactory $orderCollectionFactory | ||
) { | ||
$this->generalHelper = $generalHelper; | ||
$this->storeManager = $storeManager; | ||
$this->product = $product; | ||
$this->testData = $testData; | ||
$this->orderCollectionFactory = $orderCollectionFactory; | ||
parent::__construct($context); | ||
} | ||
|
@@ -164,16 +165,19 @@ public function getEnabled($storeId = null) | |
* @param \Magento\Framework\App\RequestInterface $request | ||
* | ||
* @return bool|mixed | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function validateJsonData($orderData, $request) | ||
{ | ||
$data = null; | ||
$test = $request->getParam('test'); | ||
$lvb = $request->getParam('lvb'); | ||
$country = $request->getParam('country', 'NL'); | ||
$storeId = $request->getParam('store'); | ||
|
||
if ($test) { | ||
$data = $this->getTestJsonData($test, $lvb); | ||
$data = $this->testData->getOrder($test, $lvb, $country); | ||
} else { | ||
if ($orderData == null) { | ||
return $this->jsonResponse('Post data empty!'); | ||
|
@@ -207,43 +211,6 @@ public function validateJsonData($orderData, $request) | |
return $data; | ||
} | ||
|
||
/** | ||
* @param $productId | ||
* @param bool $lvb | ||
* | ||
* @return bool|string | ||
*/ | ||
public function getTestJsonData($productId, $lvb = false) | ||
{ | ||
$orderStatus = $lvb ? 'shipped' : 'not_shipped'; | ||
/** @var \Magento\Catalog\Model\Product $product */ | ||
$product = $this->product->create()->load($productId); | ||
if ($product) { | ||
$data = '{"channable_id": 112345, "channable_channel_label": "Bol NL", "channel_id": 123456, | ||
"channel_name": "Bol", "order_status": "' . $orderStatus . '", "extra": {"memo": "Channable Test", | ||
"comment": "Channable order id: 999999999"}, "price": {"total": "' . $product->getFinalPrice() . '", | ||
"currency": "EUR", "shipping": 0, "subtotal": "' . $product->getFinalPrice() . '", | ||
"commission": 2.50, "payment_method": "bol", "transaction_fee": 0}, | ||
"billing": { "city": "Amsterdam", "state": "", "email": "[email protected]", | ||
"address_line_1": "Billing Line 1", "address_line_2": "Billing Line 2", "street": "Donkere Spaarne", | ||
"company": "Test company", "zip_code": "5000 ZZ", "last_name": "Channable", "first_name": "Test", | ||
"middle_name": "from", "country_code": "NL", "house_number": 100, "house_number_ext": "a", | ||
"address_supplement": "Address supplement" }, "customer": { "email": "[email protected]", | ||
"phone": "054333333", "gender": "man", "mobile": "", "company": "Test company", "last_name": | ||
"From Channable", "first_name": "Test", "middle_name": "" }, | ||
"products": [{"id": "' . $product->getEntityId() . '", "ean": "000000000", | ||
"price": "' . $product->getFinalPrice() . '", "title": "' . htmlentities($product->getName()) . '", | ||
"quantity": 1, "shipping": 0, "commission": 2.50, "reference_code": "00000000", | ||
"delivery_period": "2016-07-12+02:00"}], "shipping": { "city": "Amsterdam", "state": "", | ||
"email": "[email protected]", "street": "Shipping Street", "company": "Magmodules", | ||
"zip_code": "1000 AA", "last_name": "from Channable", "first_name": "Test order", "middle_name": "", | ||
"country_code": "NL", "house_number": 21, "house_number_ext": "B", "address_supplement": | ||
"Address Supplement", "address_line_1": "Shipping Line 1", "address_line_2": "Shipping Line 2" }}'; | ||
return json_decode($data, true); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @param null $storeId | ||
* | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
/** | ||
* Copyright © 2019 Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magmodules\Channable\Service\Order; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Framework\Math\Random; | ||
|
||
class TestData | ||
{ | ||
|
||
/** | ||
* @var ProductRepositoryInterface | ||
*/ | ||
private $productRepository; | ||
/** | ||
* @var Random | ||
*/ | ||
private $random; | ||
|
||
/** | ||
* TestData constructor. | ||
* | ||
* @param ProductRepositoryInterface $productRepository | ||
* @param Random $random | ||
*/ | ||
public function __construct( | ||
ProductRepositoryInterface $productRepository, | ||
Random $random | ||
) { | ||
$this->productRepository = $productRepository; | ||
$this->random = $random; | ||
} | ||
|
||
/** | ||
* @param $productId | ||
* @param bool $lvb | ||
* @param string $country | ||
* | ||
* @return array | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function getOrder($productId, $lvb = false, $country = 'NL') | ||
{ | ||
$product = $this->productRepository->getById($productId); | ||
$random = $this->random->getRandomString(5, '0123456789'); | ||
|
||
return [ | ||
"channable_id" => $random, | ||
"channable_channel_label" => "Channable Test", | ||
"channel_id" => "TEST-" . $random, | ||
"channel_name" => "Channable", | ||
"order_status" => $lvb ? "shipped" : "not_shipped", | ||
"customer" => [ | ||
"gender" => "male", | ||
"phone" => "01234567890", | ||
"mobile" => "01234567890", | ||
"email" => "[email protected]", | ||
"first_name" => "Test", | ||
"middle_name" => "From", | ||
"last_name" => "Channable", | ||
"company" => "TestCompany" | ||
], | ||
"billing" => [ | ||
"first_name" => "Test", | ||
"middle_name" => "From", | ||
"last_name" => "Channable", | ||
"company" => "Do Not Ship", | ||
"email" => "[email protected]", | ||
"address_line_1" => "Billing Line 1", | ||
"address_line_2" => "Billing Line 2", | ||
"street" => "Street", | ||
"house_number" => 1, | ||
"house_number_ext" => "", | ||
"zip_code" => "1000 AA", | ||
"city" => "UTRECHT", | ||
"country_code" => $country, | ||
"state" => $country == "US" ? "Texas" : "", | ||
"state_code" => $country == "US" ? "TX" : "", | ||
], | ||
"shipping" => [ | ||
"first_name" => "Test", | ||
"middle_name" => "From", | ||
"last_name" => "Channable", | ||
"company" => "Do Not Ship", | ||
"email" => "[email protected]", | ||
"address_line_1" => "Billing Line 1", | ||
"address_line_2" => "Billing Line 2", | ||
"street" => "Street", | ||
"house_number" => 1, | ||
"house_number_ext" => "", | ||
"zip_code" => "1000 AA", | ||
"city" => "UTRECHT", | ||
"country_code" => $country, | ||
"state" => $country == "US" ? "Texas" : "", | ||
"state_code" => $country == "US" ? "TX" : "", | ||
], | ||
"price" => [ | ||
"payment_method" => "bol", | ||
"currency" => "EUR", | ||
"subtotal" => ($product->getPrice() * 2), | ||
"payment" => 0, | ||
"shipping" => 0, | ||
"total" => ($product->getPrice() * 2), | ||
"transaction_fee" => 0, | ||
"commission" => 4.59 | ||
], | ||
"products" => [ | ||
[ | ||
"id" => $product->getId(), | ||
"quantity" => 2, | ||
"price" => $product->getPrice(), | ||
"ean" => $product->getSku(), | ||
"reference_code" => $product->getSku(), | ||
"title" => $product->getName(), | ||
"delivery_period" => "2019-04-17+02=>00", | ||
"shipping" => 0, | ||
"commission" => 4.59 | ||
] | ||
], | ||
"memo" => "Test Order from Channable", | ||
]; | ||
} | ||
|
||
} |
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