Skip to content

Commit

Permalink
Merge pull request #87 from magmodules/fix/order-item-refactor
Browse files Browse the repository at this point in the history
Order item refactor
  • Loading branch information
Marvin-Magmodules authored Feb 21, 2020
2 parents 27d2a82 + f9d1a8b commit b2ce397
Show file tree
Hide file tree
Showing 11 changed files with 482 additions and 174 deletions.
9 changes: 9 additions & 0 deletions Controller/Order/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magmodules\Channable\Helper\General as GeneralHelper;
use Magmodules\Channable\Helper\Order as OrderHelper;
use Magmodules\Channable\Model\Order as OrderModel;
use Magmodules\Channable\Service\Order\Items\Validate as ValidateItems;

/**
* Class Hook
Expand All @@ -33,6 +34,10 @@ class Hook extends Action
* @var OrderModel
*/
private $orderModel;
/**
* @var ValidateItems
*/
private $validateItems;
/**
* @var JsonFactory
*/
Expand All @@ -45,18 +50,21 @@ class Hook extends Action
* @param GeneralHelper $generalHelper
* @param OrderHelper $orderHelper
* @param OrderModel $orderModel
* @param ValidateItems $validateItems
* @param JsonFactory $resultJsonFactory
*/
public function __construct(
Context $context,
GeneralHelper $generalHelper,
OrderHelper $orderHelper,
OrderModel $orderModel,
ValidateItems $validateItems,
JsonFactory $resultJsonFactory
) {
$this->generalHelper = $generalHelper;
$this->orderHelper = $orderHelper;
$this->orderModel = $orderModel;
$this->validateItems = $validateItems;
$this->resultJsonFactory = $resultJsonFactory;
parent::__construct($context);
}
Expand All @@ -81,6 +89,7 @@ public function execute()

if (empty($response['errors'])) {
try {
$this->validateItems->execute($orderData['products']);
$response = $this->orderModel->importOrder($orderData, $storeId);
} catch (\Exception $e) {
$response = $this->orderHelper->jsonResponse($e->getMessage());
Expand Down
14 changes: 14 additions & 0 deletions Exceptions/CouldNotImportOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Copyright © Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magmodules\Channable\Exceptions;

use Magento\Framework\Exception\LocalizedException;

class CouldNotImportOrder extends LocalizedException
{

}
60 changes: 49 additions & 11 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Config
const XPATH_IMPORT_COMPANY_NAME = 'magmodules_channable_marketplace/order/import_company_name';
const XPATH_SEPERATE_HOUSENUMBER = 'magmodules_channable_marketplace/order/seperate_housenumber';
const XPATH_CUSTOMER_STREET_LINES = 'customer/address/street_lines';
const XPATH_TAX_PRICE = 'tax/calculation/price_includes_tax';
const XPATH_TAX_SHIPPING = 'tax/calculation/shipping_includes_tax';
const XPATH_ENABLE_BACKORDERS = 'magmodules_channable_marketplace/order/backorders';

/**
* @var ScopeConfigInterface
Expand Down Expand Up @@ -50,6 +53,17 @@ public function processingStatus($storeId = null)
return $this->getPath(self::XPATH_CUSTOM_STATUS, $storeId);
}

/**
* @param $path
* @param $storeId
*
* @return string
*/
private function getPath($path, $storeId)
{
return $this->config->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param $storeId
*
Expand All @@ -60,6 +74,17 @@ public function sendInvoiceEmail($storeId)
return $this->getFlag(self::XPATH_SEND_INVOICE, $storeId);
}

/**
* @param $path
* @param $storeId
*
* @return bool
*/
private function getFlag($path, $storeId)
{
return $this->config->isSetFlag($path, ScopeInterface::SCOPE_STORE, $storeId);
}

/**
* @param null $storeId
*
Expand Down Expand Up @@ -97,28 +122,41 @@ public function getSeperateHousenumber($storeId = null)
*/
public function getCustomerStreetLines($storeId)
{
return (int) $this->getPath(self::XPATH_CUSTOMER_STREET_LINES, $storeId);
return (int)$this->getPath(self::XPATH_CUSTOMER_STREET_LINES, $storeId);
}

/**
* @param $path
* @param $storeId
* @param null $storeId
*
* @return string
* @return mixed
*/
private function getPath($path, $storeId)
public function getDefaultManageStock($storeId = null)
{
return $this->config->getValue($path, ScopeInterface::SCOPE_STORE, $storeId);
return $this->getPath(\Magento\CatalogInventory\Model\Configuration::XML_PATH_MANAGE_STOCK, $storeId);
}

/**
* @param $path
* @param $storeId
* @param $type
* @param null $storeId
*
* @return bool
* @return int
*/
private function getFlag($path, $storeId)
public function getNeedsTaxCalulcation($type, $storeId = null)
{
return $this->config->isSetFlag($path, ScopeInterface::SCOPE_STORE, $storeId);
if ($type == 'shipping') {
return $this->getFlag(self::XPATH_TAX_SHIPPING, $storeId);
} else {
return $this->getFlag(self::XPATH_TAX_PRICE, $storeId);
}
}

/**
* @param null $storeId
*
* @return mixed
*/
public function getEnableBackorders($storeId = null)
{
return $this->getFlag(self::XPATH_ENABLE_BACKORDERS, $storeId);
}
}
Loading

0 comments on commit b2ce397

Please sign in to comment.