Skip to content

Commit

Permalink
Merge pull request #74 from magmodules/1.4.11
Browse files Browse the repository at this point in the history
1.4.11
  • Loading branch information
Marvin-Magmodules authored Jul 12, 2019
2 parents e603278 + 1fca146 commit 3b0913c
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 50 deletions.
57 changes: 12 additions & 45 deletions Helper/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand All @@ -52,9 +53,9 @@ class Order extends AbstractHelper
*/
private $storeManager;
/**
* @var ProductFactory
* @var TestData
*/
private $product;
private $testData;
/**
* @var OrderCollectionFactory
*/
Expand All @@ -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);
}
Expand Down Expand Up @@ -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!');
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion Helper/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public function validateProduct($product, $parent, $config)
$filters = $config['filters'];
if (!empty($parent)) {
if (!empty($filters['stock'])) {
if (!$parent->getIsSalable() && !$parent->getIsInStock()) {
if (!$parent->getIsInStock()) {
return false;
}
}
Expand Down
6 changes: 4 additions & 2 deletions Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,9 @@ public function getAddressData($type, $order, $customerId = null)
'street' => $this->getStreet($address),
'city' => $address['city'],
'country_id' => $address['country_code'],
'region' => !empty($address['state_code']) ? $address['state_code'] : null,
'postcode' => $address['zip_code'],
'telephone' => $telephone
'telephone' => $telephone,
];

if ($this->importCustomer) {
Expand All @@ -516,6 +517,7 @@ public function getAddressData($type, $order, $customerId = null)
->setStreet($addressData['street'])
->setCity($addressData['city'])
->setCountryId($addressData['country_id'])
->setRegion($addressData['region'])
->setPostcode($addressData['postcode'])
->setTelephone($addressData['telephone']);

Expand Down Expand Up @@ -589,7 +591,7 @@ private function addProductsToQuote($cart, $data, $store)
$price = ($item['price'] / (100 + $percent) * 100);
}

$product->setPrice($price)->setFinalPrice($price)->setSpecialPrice($price);
$product->setPrice($price)->setFinalPrice($price)->setSpecialPrice($price)->setTierPrice([]);
if ($this->orderHelper->getEnableBackorders($store->getId())) {
$stockItem->setUseConfigBackorders(false)->setBackorders(true)->setIsInStock(true);
$productData = $product->getData();
Expand Down
129 changes: 129 additions & 0 deletions Service/Order/TestData.php
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",
];
}

}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magmodules/magento2-channable",
"description": "Channable integration for Magento 2",
"type": "magento2-module",
"version": "1.4.10",
"version": "1.4.11",
"license": "BSD-2-Clause",
"homepage": "https://github.com/magmodules/magento2-channable",
"require": {
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magmodules_Channable" setup_version="1.4.10"/>
<module name="Magmodules_Channable" setup_version="1.4.11"/>
</config>

0 comments on commit 3b0913c

Please sign in to comment.