Skip to content

Commit

Permalink
Merge pull request #82 from magmodules/1.4.12
Browse files Browse the repository at this point in the history
1.4.12
  • Loading branch information
Marvin-Magmodules authored Sep 6, 2019
2 parents 3b0913c + 2d898a7 commit 64c399a
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 139 deletions.
96 changes: 0 additions & 96 deletions Helper/Inventory.php

This file was deleted.

21 changes: 21 additions & 0 deletions Helper/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Order extends AbstractHelper
const XPATH_LVB_AUTO_SHIP = 'magmodules_channable_marketplace/order/lvb_ship';
const XPATH_ORDERID_PREFIX = 'magmodules_channable_marketplace/order/orderid_prefix';
const XPATH_ORDERID_ALPHANUMERIC = 'magmodules_channable_marketplace/order/orderid_alphanumeric';
const XPATH_IMPORT_COMPANY_NAME = 'magmodules_channable_marketplace/order/import_company_name';
const XPATH_LOG = 'magmodules_channable_marketplace/order/log';
const XPATH_TAX_PRICE = 'tax/calculation/price_includes_tax';
const XPATH_TAX_SHIPPING = 'tax/calculation/shipping_includes_tax';
Expand Down Expand Up @@ -326,6 +327,16 @@ public function getCustomerStreetLines($storeId)
return (int) $this->generalHelper->getStoreValue(self::XPATH_CUSTOMER_STREET_LINES, $storeId);
}

/**
* @param $storeId
*
* @return bool
*/
public function importCompanyName($storeId)
{
return (bool)$this->generalHelper->getStoreValue(self::XPATH_IMPORT_COMPANY_NAME, $storeId);
}

/**
* @param $channelId
* @param $storeId
Expand Down Expand Up @@ -507,4 +518,14 @@ public function isLoggingEnabled()
return $this->generalHelper->getStoreValue(self::XPATH_LOG);
}

/**
* @param $email
*
* @return mixed
*/
public function cleanEmail($email)
{
return str_replace([':'], '', $email);
}

}
25 changes: 12 additions & 13 deletions Helper/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magento\GroupedProduct\Model\ResourceModel\Product\Link as GroupedResource;
use Magento\Bundle\Model\ResourceModel\Selection as BundleResource;
use Magmodules\Channable\Logger\ChannableLogger;
use Magmodules\Channable\Service\Product\InventoryData;

/**
* Class Product
Expand Down Expand Up @@ -64,9 +65,9 @@ class Product extends AbstractHelper
*/
private $productImageHelper;
/**
* @var Inventory
* @var InventoryData
*/
private $inventoryHelper;
private $inventoryData;
/**
* @var GalleryReadHandler
*/
Expand Down Expand Up @@ -96,7 +97,6 @@ class Product extends AbstractHelper
* @param CatalogProductMediaConfig $catalogProductMediaConfig
* @param CatalogHelper $catalogHelper
* @param ProductImageHelper $productImageHelper
* @param Inventory $inventoryHelper
* @param RuleFactory $ruleFactory
* @param EavConfig $eavConfig
* @param FilterManager $filter
Expand All @@ -105,6 +105,7 @@ class Product extends AbstractHelper
* @param BundleResource $catalogProductTypeBundle
* @param ConfigurableResource $catalogProductTypeConfigurable
* @param CatalogPrice $commonPriceModel
* @param InventoryData $inventoryData
* @param ChannableLogger $logger
*/
public function __construct(
Expand All @@ -113,7 +114,6 @@ public function __construct(
CatalogProductMediaConfig $catalogProductMediaConfig,
CatalogHelper $catalogHelper,
ProductImageHelper $productImageHelper,
Inventory $inventoryHelper,
RuleFactory $ruleFactory,
EavConfig $eavConfig,
FilterManager $filter,
Expand All @@ -122,13 +122,13 @@ public function __construct(
BundleResource $catalogProductTypeBundle,
ConfigurableResource $catalogProductTypeConfigurable,
CatalogPrice $commonPriceModel,
InventoryData $inventoryData,
ChannableLogger $logger
) {
$this->galleryReadHandler = $galleryReadHandler;
$this->catalogProductMediaConfig = $catalogProductMediaConfig;
$this->catalogHelper = $catalogHelper;
$this->productImageHelper = $productImageHelper;
$this->inventoryHelper = $inventoryHelper;
$this->ruleFactory = $ruleFactory;
$this->eavConfig = $eavConfig;
$this->filter = $filter;
Expand All @@ -137,6 +137,7 @@ public function __construct(
$this->catalogProductTypeGrouped = $catalogProductTypeGrouped;
$this->catalogProductTypeBundle = $catalogProductTypeBundle;
$this->commonPriceModel = $commonPriceModel;
$this->inventoryData = $inventoryData;
$this->logger = $logger;
parent::__construct($context);
}
Expand All @@ -153,6 +154,8 @@ public function getDataRow($product, $parent, $config)
{
$dataRow = [];

$product = $this->inventoryData->addDataToProduct($product, $config);

if (!$this->validateProduct($product, $parent, $config)) {
return $dataRow;
}
Expand Down Expand Up @@ -292,7 +295,7 @@ public function getAttributeValue($type, $attribute, $config, $product, $simple)
$value = $this->getAttributeSetName($product);
break;
case 'qty':
$value = $this->getQtyValue($product, $config['inventory']);
$value = $this->getQtyValue($product);
break;
case 'manage_stock':
$value = $this->getManageStockValue($product, $config['inventory']);
Expand Down Expand Up @@ -345,7 +348,7 @@ public function getProductUrl($product, $simple, $config)
{
$url = null;
if ($requestPath = $product->getRequestPath()) {
$url = $config['base_url'] . $requestPath;
$url = $product->getProductUrl();
} else {
$url = $config['base_url'] . 'catalog/product/view/id/' . $product->getEntityId();
}
Expand Down Expand Up @@ -579,13 +582,9 @@ public function getAttributeSetName($product)
*
* @return float
*/
private function getQtyValue($product, $inventory)
private function getQtyValue($product)
{
$qty = $product->getQty();
if (!empty($inventory['use_salable_qty']) && !empty($inventory['stock_id'])) {
$qty -= $this->inventoryHelper->getReservations($product->getSku(), $inventory['stock_id']);
}
return $qty;
return $product->getQty();
}

/**
Expand Down
21 changes: 9 additions & 12 deletions Helper/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Framework\Exception\LocalizedException;
use Magmodules\Channable\Service\Product\InventorySource;

/**
* Class Source
Expand Down Expand Up @@ -41,7 +42,6 @@ class Source extends AbstractHelper
const XPATH_DELIVERY_TIME = 'magmodules_channable/advanced/delivery_time';
const XPATH_INVENTORY = 'magmodules_channable/advanced/inventory';
const XPATH_INVENTORY_DATA = 'magmodules_channable/advanced/inventory_fields';
const XPATH_INVENTORY_SALABLE = 'magmodules_channable/advanced/use_salable_qty';
const XPATH_TAX = 'magmodules_channable/advanced/tax';
const XPATH_MANAGE_STOCK = 'cataloginventory/item_options/manage_stock';
const XPATH_MIN_SALES_QTY = 'cataloginventory/item_options/min_sale_qty';
Expand Down Expand Up @@ -90,9 +90,9 @@ class Source extends AbstractHelper
*/
private $storeManager;
/**
* @var Inventory
* @var InventorySource
*/
private $inventoryHelper;
private $inventorySource;
/**
* @var
*/
Expand All @@ -106,24 +106,24 @@ class Source extends AbstractHelper
* @param General $generalHelper
* @param Category $categoryHelper
* @param Product $productHelper
* @param InventorySource $inventorySource
* @param Item $itemHelper
* @param Inventory $inventoryHelper
*/
public function __construct(
Context $context,
StoreManagerInterface $storeManager,
General $generalHelper,
Category $categoryHelper,
Product $productHelper,
Item $itemHelper,
Inventory $inventoryHelper
InventorySource $inventorySource,
Item $itemHelper
) {
$this->generalHelper = $generalHelper;
$this->productHelper = $productHelper;
$this->itemHelper = $itemHelper;
$this->categoryHelper = $categoryHelper;
$this->storeManager = $storeManager;
$this->inventoryHelper = $inventoryHelper;
$this->inventorySource = $inventorySource;
parent::__construct($context);
}

Expand Down Expand Up @@ -727,11 +727,8 @@ public function getInventoryData($type)
$invAtt['config_min_sale_qty'] = $this->getStoreValue(self::XPATH_MIN_SALES_QTY);
}

$invAtt['use_salable_qty'] = $this->getStoreValue(self::XPATH_INVENTORY_SALABLE);
if ($invAtt['use_salable_qty']) {
$websiteCode = $this->storeManager->getWebsite()->getCode();
$invAtt['stock_id'] = $this->inventoryHelper->getInventorySource($websiteCode);
}
$websiteCode = $this->storeManager->getWebsite()->getCode();
$invAtt['stock_id'] = $this->inventorySource->execute($websiteCode);

return $invAtt;
}
Expand Down
15 changes: 8 additions & 7 deletions Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ private function checkItems($items)
if (!empty($item['title']) && !empty($item['id'])) {
$error[] = __(
'Product "%1" not found in catalog (ID: %2)',
$product['title'],
$product['id']
$item['title'],
$item['id']
);
} else {
$error[] = __('Product not found in catalog');
Expand Down Expand Up @@ -436,20 +436,21 @@ private function setCustomerCart($cart, $store, $data)
{
$storeId = $store->getId();
$websiteId = $store->getWebsiteId();
$email = $this->orderHelper->cleanEmail($data['customer']['email']);

if ($this->importCustomer) {
$customerGroupId = $this->orderHelper->getCustomerGroupId($storeId);
$customer = $this->customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($data['customer']['email']);
$customer->loadByEmail($email);
if (!$customerId = $customer->getEntityId()) {
$customer->setWebsiteId($websiteId)
->setStore($store)
->setFirstname($data['customer']['first_name'])
->setMiddlename($data['customer']['middle_name'])
->setLastname($data['customer']['last_name'])
->setEmail($data['customer']['email'])
->setPassword($data['customer']['email'])
->setEmail($email)
->setPassword($email)
->setGroupId($customerGroupId)
->save();
$customerId = $customer->getId();
Expand All @@ -459,7 +460,7 @@ private function setCustomerCart($cart, $store, $data)
} else {
$customerId = 0;
$cart->setCustomerId($customerId)
->setCustomerEmail($data['customer']['email'])
->setCustomerEmail($email)
->setCustomerFirstname($data['customer']['first_name'])
->setCustomerMiddlename($data['customer']['middle_name'])
->setCustomerLastname($data['customer']['last_name'])
Expand Down Expand Up @@ -495,7 +496,7 @@ public function getAddressData($type, $order, $customerId = null)

$addressData = [
'customer_id' => $customerId,
'company' => $address['company'],
'company' => $this->orderHelper->importCompanyName($this->storeId) ? $address['company'] : null,
'firstname' => $address['first_name'],
'middlename' => $address['middle_name'],
'lastname' => $address['last_name'],
Expand Down
Loading

0 comments on commit 64c399a

Please sign in to comment.