diff --git a/Helper/Constants.php b/Helper/Constants.php index 746bf36..8b0280a 100644 --- a/Helper/Constants.php +++ b/Helper/Constants.php @@ -5,15 +5,15 @@ class Constants { const CACHE_KEY_MERCHANT_CONTRACT_IMPORT_FLAG = 'payline_merchant_contract_import_flag'; - + const WEB_PAYMENT_CPT = 'payline_web_payment_cpt'; - + const CONFIG_PATH_PAYLINE_GENERAL_ENVIRONMENT = 'payline/general/environment'; const CONFIG_PATH_PAYLINE_GENERAL_MERCHANT_ID = 'payline/general/merchant_id'; const CONFIG_PATH_PAYLINE_GENERAL_ACCESS_KEY = 'payline/general/access_key'; const CONFIG_PATH_PAYLINE_GENERAL_DEBUG = 'payline/general/debug'; const CONFIG_PATH_PAYLINE_GENERAL_CONTRACTS = 'payline/general/contracts'; - + const ORDER_STATUS_PAYLINE_PENDING = 'payline_pending'; const ORDER_STATUS_PAYLINE_WAITING_CAPTURE = 'payline_waiting_capture'; const ORDER_STATUS_PAYLINE_CAPTURED = 'payline_captured'; @@ -22,4 +22,8 @@ class Constants const ORDER_STATUS_PAYLINE_REFUSED = 'payline_refused'; const ORDER_STATUS_PAYLINE_FRAUD = 'payline_fraud'; const ORDER_STATUS_PAYLINE_WAITING_ACCEPTANCE = 'payline_waiting_acceptance'; + + const PAYLINE_API_USED_BY_PREFIX = 'MGT2'; + + const MODULE_NAME = 'Monext_Payline'; } \ No newline at end of file diff --git a/Model/CartManagement.php b/Model/CartManagement.php index 00e97ed..4a4beb2 100644 --- a/Model/CartManagement.php +++ b/Model/CartManagement.php @@ -2,6 +2,8 @@ namespace Monext\Payline\Model; +use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory; +use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory; use Magento\Checkout\Model\Cart as CheckoutCart; use Magento\Quote\Api\CartManagementInterface; use Magento\Quote\Api\CartRepositoryInterface; @@ -12,17 +14,17 @@ class CartManagement { /** - * @var CartRepositoryInterface + * @var CartRepositoryInterface */ protected $cartRepository; /** - * @var CartManagementInterface + * @var CartManagementInterface */ protected $cartManagement; /** - * @var QuoteFactory + * @var QuoteFactory */ protected $quoteFactory; @@ -32,16 +34,28 @@ class CartManagement protected $orderIncrementIdTokenFactory; /** - * @var CheckoutCart + * @var CheckoutCart */ protected $checkoutCart; + /** + * @var ProductCollectionFactory + */ + protected $productCollectionFactory; + + /** + * @var CategoryCollectionFactory + */ + protected $categoryCollectionFactory; + public function __construct( CartRepositoryInterface $cartRepository, CartManagementInterface $cartManagement, OrderIncrementIdTokenFactory $orderIncrementIdTokenFactory, QuoteFactory $quoteFactory, - CheckoutCart $checkoutCart + CheckoutCart $checkoutCart, + ProductCollectionFactory $productCollectionFactory, + CategoryCollectionFactory $categoryCollectionFactory ) { $this->cartRepository = $cartRepository; @@ -49,6 +63,8 @@ public function __construct( $this->quoteFactory = $quoteFactory; $this->orderIncrementIdTokenFactory = $orderIncrementIdTokenFactory; $this->checkoutCart = $checkoutCart; + $this->productCollectionFactory = $productCollectionFactory; + $this->categoryCollectionFactory = $categoryCollectionFactory; } public function handleReserveCartOrderId($cartId, $forceReserve = false) @@ -92,5 +108,54 @@ public function getCartByToken($token) // TODO Use QuoteRepository instead of quote::load return $this->quoteFactory->create()->load($orderIncrementId, 'reserved_order_id'); } + + public function getProductCollectionFromCart($cartId) + { + $cart = $this->cartRepository->getActive($cartId); + + $productIds = []; + $categoryIds = []; + $productCollection = $this->productCollectionFactory->create(); + $categoryCollection = $this->categoryCollectionFactory->create(); + + foreach ($cart->getItems() as $item) { + $productIds[] = $item->getProductId(); + } + + $productCollection + ->addAttributeToFilter('entity_id', ['in' => $productIds]) + ->addAttributeToSelect('*') + ->addCategoryIds(); + + foreach ($productCollection as $product) { + $categoryIds = array_merge($categoryIds, $product->getCategoryIds()); + } + + $categoryCollection + ->addAttributeToFilter('entity_id', ['in' => $categoryIds]) + ->addAttributeToSelect(['name', 'payline_category_mapping', 'level']); + + foreach ($productCollection as $product) { + $categoryCandidate = null; + + foreach ($product->getCategoryIds() as $categoryId) { + $tmpCategory = $categoryCollection->getItemById($categoryId); + + if (!$tmpCategory) { + continue; + } + + if (!$categoryCandidate || $tmpCategory->getLevel() > $categoryCandidate->getLevel()) { + $categoryCandidate = $tmpCategory; + } + } + + $product->setPaylineCategoryMapping( + $categoryCandidate->getPaylineCategoryMapping() ? $categoryCandidate->getPaylineCategoryMapping() : $categoryCandidate->getName() + ); + } + + return $productCollection; + } } diff --git a/Model/Category/Attribute/Source/CategoryMapping.php b/Model/Category/Attribute/Source/CategoryMapping.php new file mode 100644 index 0000000..fd52a53 --- /dev/null +++ b/Model/Category/Attribute/Source/CategoryMapping.php @@ -0,0 +1,53 @@ +componentRegistrar = $componentRegistrar; + $this->csvReader = $csvReader; + } + + /** + * {@inheritdoc} + * @codeCoverageIgnore + */ + public function getAllOptions() + { + if (!$this->_options) { + $this->_options = []; + + $csvFile = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, HelperConstants::MODULE_NAME) . '/fixtures/category_mapping.csv'; + $rows = $this->csvReader->getData($csvFile); + + foreach ($rows as $row) { + $this->_options[] = ['value' => $row[0], 'label' => __($row[1])]; + } + + array_unshift($this->_options, ['value' => '', 'label' => __('Please select a category mapping...')]); + } + return $this->_options; + } +} \ No newline at end of file diff --git a/Model/PaymentManagement.php b/Model/PaymentManagement.php index 60efde3..4db326e 100644 --- a/Model/PaymentManagement.php +++ b/Model/PaymentManagement.php @@ -7,6 +7,7 @@ use Magento\Framework\Api\SortOrderBuilder; use Magento\Framework\Data\Collection; +use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection; use Magento\Checkout\Api\PaymentInformationManagementInterface as CheckoutPaymentInformationManagementInterface; use Magento\Quote\Api\BillingAddressManagementInterface as QuoteBillingAddressManagementInterface; use Magento\Quote\Api\CartRepositoryInterface; @@ -205,6 +206,7 @@ public function wrapCallPaylineApiDoWebPaymentFacade($cartId) { $response = $this->callPaylineApiDoWebPaymentFacade( $this->cartRepository->getActive($cartId), + $this->paylineCartManagement->getProductCollectionFromCart($cartId), $this->cartTotalRepository->get($cartId), $this->quotePaymentMethodManagement->get($cartId), $this->quoteBillingAddressManagement->get($cartId), @@ -219,6 +221,7 @@ public function wrapCallPaylineApiDoWebPaymentFacade($cartId) protected function callPaylineApiDoWebPaymentFacade( CartInterface $cart, + ProductCollection $productCollection, TotalsInterface $totals, PaymentInterface $payment, AddressInterface $billingAddress, @@ -231,7 +234,7 @@ protected function callPaylineApiDoWebPaymentFacade( $shippingAddress = null; } - $response = $this->callPaylineApiDoWebPayment($cart, $totals, $payment, $billingAddress, $shippingAddress); + $response = $this->callPaylineApiDoWebPayment($cart, $productCollection, $totals, $payment, $billingAddress, $shippingAddress); if(!$response->isSuccess()) { // TODO log @@ -248,6 +251,7 @@ protected function callPaylineApiDoWebPaymentFacade( protected function callPaylineApiDoWebPayment( CartInterface $cart, + ProductCollection $productCollection, TotalsInterface $totals, PaymentInterface $payment, AddressInterface $billingAddress, @@ -257,6 +261,7 @@ protected function callPaylineApiDoWebPayment( $request = $this->requestDoWebPaymentFactory->create(); $request ->setCart($cart) + ->setProductCollection($productCollection) ->setBillingAddress($billingAddress) ->setShippingAddress($shippingAddress) ->setTotals($totals) diff --git a/PaylineApi/Client.php b/PaylineApi/Client.php index 534771e..121fb48 100644 --- a/PaylineApi/Client.php +++ b/PaylineApi/Client.php @@ -4,6 +4,7 @@ use Magento\Framework\Encryption\EncryptorInterface; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Module\ModuleListInterface; use Monext\Payline\Helper\Constants as HelperConstants; use Monext\Payline\PaylineApi\PaylineSDKFactory; use Monext\Payline\PaylineApi\Request\DoCapture as RequestDoCapture; @@ -37,9 +38,9 @@ class Client protected $paylineSDKFactory; /** - * @var PaylineSDK + * @var PaylineSDK */ - protected $paylineSDK; + protected $paylineSDK; /** * @var ScopeConfigInterface @@ -60,19 +61,19 @@ class Client * @var ResponseDoVoidFactory */ protected $responseDoVoidFactory; - + /** * @var ResponseDoRefundFactory */ protected $responseDoRefundFactory; - + /** - * @var ResponseGetMerchantSettingsFactory + * @var ResponseGetMerchantSettingsFactory */ protected $responseGetMerchantSettingsFactory; /** - * @var ResponseGetWebPaymentDetailsFactory + * @var ResponseGetWebPaymentDetailsFactory */ protected $responseGetWebPaymentDetailsFactory; @@ -85,12 +86,17 @@ class Client * @var Logger */ protected $logger; - + /** * @var EncryptorInterface */ protected $encryptor; - + + /** + * @var ModuleListInterface + */ + protected $moduleList; + public function __construct( PaylineSDKFactory $paylineSDKFactory, ScopeConfigInterface $scopeConfig, @@ -102,7 +108,8 @@ public function __construct( ResponseGetWebPaymentDetailsFactory $responseGetWebPaymentDetailsFactory, ResponseManageWebWalletFactory $responseManageWebWalletFactory, Logger $logger, - EncryptorInterface $encryptor + EncryptorInterface $encryptor, + ModuleListInterface $moduleList ) { $this->paylineSDKFactory = $paylineSDKFactory; @@ -116,8 +123,9 @@ public function __construct( $this->responseManageWebWalletFactory = $responseManageWebWalletFactory; $this->logger = $logger; $this->encryptor = $encryptor; + $this->moduleList = $moduleList; } - + /** * @param RequestDoWebPayment $request * @return ResponseDoWebPayment @@ -127,8 +135,15 @@ public function callDoWebPayment(RequestDoWebPayment $request) $this->initPaylineSDK(); $response = $this->responseDoWebPaymentFactory->create(); + + $data = $request->getData(); + foreach ($data['order']['details'] as $orderDetail) { + $this->paylineSDK->addOrderDetail($orderDetail); + } + unset($data['order']['details']); + $response->fromData( - $this->paylineSDK->doWebPayment($request->getData()) + $this->paylineSDK->doWebPayment($data) ); if($this->scopeConfig->getValue(HelperConstants::CONFIG_PATH_PAYLINE_GENERAL_DEBUG)) { @@ -138,7 +153,7 @@ public function callDoWebPayment(RequestDoWebPayment $request) return $response; } - + /** * @param RequestDoCapture $request * @return ResponseDoCapture @@ -180,7 +195,7 @@ public function callDoVoid(RequestDoVoid $request) return $response; } - + /** * @param RequestDoRefund $request * @return ResponseDoRefund @@ -201,7 +216,7 @@ public function callDoRefund(RequestDoRefund $request) return $response; } - + /** * @param RequestGetMerchantSettings $request * @return ResponseGetMerchantSettings @@ -217,7 +232,7 @@ public function callGetMerchantSettings(RequestGetMerchantSettings $request) return $response; } - + /** * @param RequestGetWebPaymentDetails $request * @return ResponseGetWebPaymentDetails @@ -276,14 +291,16 @@ protected function initPaylineSDK() 'pathLog' => BP . '/var/log/payline_sdk/', 'logLevel' => LoggerConstants::INFO, ); - + if($this->scopeConfig->getValue(HelperConstants::CONFIG_PATH_PAYLINE_GENERAL_DEBUG)) { $this->logger->log(LoggerConstants::DEBUG, print_r($paylineSdkParams, true)); } - + $this->paylineSDK = $this->paylineSDKFactory->create($paylineSdkParams); + $currentModule = $this->moduleList->getOne(HelperConstants::MODULE_NAME); + $this->paylineSDK->usedBy(HelperConstants::PAYLINE_API_USED_BY_PREFIX.' v'.$currentModule['setup_version']); //} - + return $this; } diff --git a/PaylineApi/Request/DoWebPayment.php b/PaylineApi/Request/DoWebPayment.php index 2daf065..941a659 100644 --- a/PaylineApi/Request/DoWebPayment.php +++ b/PaylineApi/Request/DoWebPayment.php @@ -2,6 +2,7 @@ namespace Monext\Payline\PaylineApi\Request; +use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\UrlInterface; use Magento\Quote\Api\Data\AddressInterface; @@ -20,52 +21,57 @@ class DoWebPayment extends AbstractRequest * @var CartInterface */ protected $cart; - + + /** + * @var ProductCollection + */ + protected $productCollection; + /** * @var TotalsInterface */ protected $totals; - + /** * @var PaymentInterface */ protected $payment; - + /** - * @var AddressInterface + * @var AddressInterface */ protected $billingAddress; - + /** - * @var AddressInterface + * @var AddressInterface */ protected $shippingAddress; - + /** * @var ScopeConfigInterface */ protected $scopeConfig; - + /** - * @var HelperCurrency + * @var HelperCurrency */ protected $helperCurrency; - + /** * @var UrlInterface */ protected $urlBuilder; - + /** * @var ContractManagement */ protected $contractManagement; - + /** - * @var HelperData + * @var HelperData */ protected $helperData; - + public function __construct( ScopeConfigInterface $scopeConfig, HelperCurrency $helperCurrency, @@ -80,37 +86,43 @@ public function __construct( $this->urlBuilder = $urlBuilder; $this->contractManagement = $contractManagement; } - + public function setCart(CartInterface $cart) { $this->cart = $cart; return $this; } - + + public function setProductCollection(ProductCollection $productCollection) + { + $this->productCollection = $productCollection; + return $this; + } + public function setBillingAddress(AddressInterface $billingAddress) { $this->billingAddress = $billingAddress; return $this; } - + public function setShippingAddress(AddressInterface $shippingAddress) { $this->shippingAddress = $shippingAddress; return $this; } - + public function setTotals(TotalsInterface $totals) { $this->totals = $totals; return $this; } - + public function setPayment(PaymentInterface $payment) { $this->payment = $payment; return $this; } - + public function getData() { if(!isset($this->data)) { @@ -142,33 +154,53 @@ public function getData() return $this->data; } - + protected function preparePaymentData(&$data) { $paymentMethod = $this->payment->getMethod(); $paymentAdditionalInformation = $this->payment->getAdditionalInformation(); - + $data['payment']['amount'] = $this->helperData->mapMagentoAmountToPaylineAmount($this->totals->getGrandTotal() + $this->totals->getTaxAmount()); $data['payment']['currency'] = $this->helperCurrency->getNumericCurrencyCode($this->totals->getBaseCurrencyCode()); $data['payment']['action'] = $this->scopeConfig->getValue('payment/'.$paymentMethod.'/payment_action'); $data['payment']['mode'] = $paymentAdditionalInformation['payment_mode']; } - + protected function prepareOrderData(&$data) { $data['order']['ref'] = $this->cart->getReservedOrderId(); $data['order']['amount'] = $this->helperData->mapMagentoAmountToPaylineAmount($this->totals->getGrandTotal() + $this->totals->getTaxAmount()); $data['order']['currency'] = $this->helperCurrency->getNumericCurrencyCode($this->totals->getBaseCurrencyCode()); $data['order']['date'] = $this->formatDateTime($this->cart->getCreatedAt()); + $this->prepareOrderDetailsData($data); + } + + protected function prepareOrderDetailsData(&$data) + { + $data['order']['details'] = []; + + foreach ($this->cart->getItems() as $item) { + $tmpProduct = $this->productCollection->getItemById($item->getProductId()); + $orderDetail = [ + 'ref' => $item->getSku(), + 'price' => $this->helperData->mapMagentoAmountToPaylineAmount($item->getPrice()), + 'quantity' => $item->getQty(), + 'brand' => $tmpProduct->getManufacturer(), + 'category' => $tmpProduct->getPaylineCategoryMapping(), + 'taxRate' => $this->helperData->mapMagentoAmountToPaylineAmount($item->getTaxPercent()), + ]; + + $data['order']['details'][] = $orderDetail; + } } - + protected function prepareUrlsForIntegrationTypeRedirect(&$data) { $data['returnURL'] = $this->urlBuilder->getUrl('payline/webpayment/returnfrompaymentgateway'); $data['cancelURL'] = $this->urlBuilder->getUrl('payline/webpayment/returnfrompaymentgateway'); $data['notificationURL'] = $this->urlBuilder->getUrl('payline/webpayment/notifyfrompaymentgateway'); } - + protected function prepareUrlsForIntegrationTypeWidget(&$data) { $customer = $this->cart->getCustomer(); @@ -183,7 +215,7 @@ protected function prepareUrlsForIntegrationTypeWidget(&$data) $data['notificationURL'] = $this->urlBuilder->getUrl('payline/webpayment/notifyfrompaymentgateway'); } - + protected function prepareBuyerData(&$data) { $customer = $this->cart->getCustomer(); @@ -229,27 +261,27 @@ protected function prepareBillingAddressData(&$data) $data['billingAddress']['zipCode'] = substr($this->billingAddress->getPostcode(), 0, 12); $data['billingAddress']['country'] = $this->billingAddress->getCountry(); $data['billingAddress']['state'] = $this->helperData->encodeString($this->billingAddress->getRegion()); - + $billingPhone = $this->helperData->getNormalizedPhoneNumber($this->billingAddress->getTelephone()); if($billingPhone) { $data['billingAddress']['phone'] = $billingPhone; } - + $streetData = $this->billingAddress->getStreet(); for($i = 0; $i <= 1; $i++) { if(isset($streetData[$i])) { $data['billingAddress']['street'.($i+1)] = $this->helperData->encodeString(substr($streetData[$i], 0, 100)); } } - + $name = $this->helperData->buildPersonNameFromParts( $this->billingAddress->getFirstname(), - $this->billingAddress->getLastname(), + $this->billingAddress->getLastname(), $this->billingAddress->getPrefix() ); $data['billingAddress']['name'] = $this->helperData->encodeString(substr($name, 0, 100)); } - + protected function prepareShippingAddressData(&$data) { if(!$this->cart->getIsVirtual() && isset($this->shippingAddress)) { @@ -260,12 +292,12 @@ protected function prepareShippingAddressData(&$data) $data['shippingAddress']['zipCode'] = substr($this->shippingAddress->getPostcode(), 0, 12); $data['shippingAddress']['country'] = $this->shippingAddress->getCountry(); $data['shippingAddress']['state'] = $this->helperData->encodeString($this->shippingAddress->getRegion()); - + $shippingPhone = $this->helperData->getNormalizedPhoneNumber($this->shippingAddress->getTelephone()); if($shippingPhone) { $data['shippingAddress']['phone'] = $shippingPhone; } - + $streetData = $this->shippingAddress->getStreet(); for($i = 0; $i <= 1; $i++) { if(isset($streetData[$i])) { @@ -275,7 +307,7 @@ protected function prepareShippingAddressData(&$data) $name = $this->helperData->buildPersonNameFromParts( $this->shippingAddress->getFirstname(), - $this->shippingAddress->getLastname(), + $this->shippingAddress->getLastname(), $this->shippingAddress->getPrefix() ); $data['shippingAddress']['name'] = $this->helperData->encodeString(substr($name, 0, 100)); diff --git a/PaylineApi/Response/GetMerchantSettings.php b/PaylineApi/Response/GetMerchantSettings.php index 95f2d0d..512579f 100644 --- a/PaylineApi/Response/GetMerchantSettings.php +++ b/PaylineApi/Response/GetMerchantSettings.php @@ -9,22 +9,15 @@ class GetMerchantSettings extends AbstractResponse public function getContractsData() { $result = array(); - - foreach($this->data['listPointOfSell']['pointOfSell'] as $pointOfSell) { - if (is_object($pointOfSell)) { - $contractsList = $pointOfSell->contracts->contract; - $pointOfSellLabel = $pointOfSell->label; - } else { //if only one point of sell, we parse an array - if(!empty($pointOfSell['contracts'])) { - $contractsList = !empty($pointOfSell['contracts']['contract']) ? $pointOfSell['contracts']['contract'] : []; - } - $pointOfSellLabel = (!empty($pointOfSell['label'])) ? $pointOfSell['label']: ''; - } - if (!is_array($contractsList)) { - $contractsList = [$contractsList]; - } + if(empty($this->data['listPointOfSell']['pointOfSell']) || !is_array($this->data['listPointOfSell']['pointOfSell'])) { + return $result; + } + $allPointOfSell = $this->data['listPointOfSell']['pointOfSell']; + if(!empty($allPointOfSell['contracts']) && !empty($allPointOfSell['label'])) { + $contractsList = !empty($allPointOfSell['contracts']['contract']) ? $allPointOfSell['contracts']['contract'] : []; + $pointOfSellLabel = $allPointOfSell['label']; foreach ($contractsList as $contract) { $result[] = [ 'label' => $contract['label'], @@ -34,8 +27,34 @@ public function getContractsData() 'point_of_sell_label' => $pointOfSellLabel, ]; } + } else { + foreach($this->data['listPointOfSell']['pointOfSell'] as $pointOfSell) { + if (is_object($pointOfSell)) { + $contractsList = $pointOfSell->contracts->contract; + $pointOfSellLabel = $pointOfSell->label; + } else { //if only one point of sell, we parse an array + if(!empty($pointOfSell['contracts'])) { + $contractsList = !empty($pointOfSell['contracts']['contract']) ? $pointOfSell['contracts']['contract'] : []; + } + $pointOfSellLabel = (!empty($pointOfSell['label'])) ? $pointOfSell['label']: ''; + } + + if (!is_array($contractsList)) { + $contractsList = [$contractsList]; + } + + foreach ($contractsList as $contract) { + $result[] = [ + 'label' => $contract['label'], + 'number' => $contract['contractNumber'], + 'card_type' => $contract['cardType'], + 'currency' => isset($contract['currency']) ? $contract['currency'] : null, + 'point_of_sell_label' => $pointOfSellLabel, + ]; + } + } } - + return $result; } } \ No newline at end of file diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index dc71fdc..07bf2e6 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -13,20 +13,27 @@ class UpgradeData implements UpgradeDataInterface /** * @var \Magento\Customer\Model\AttributeFactory */ - protected $attributeFactory; + protected $customerAttributeFactory; /** * @var \Magento\Eav\Model\Entity\Attribute\SetFactory */ protected $attributeSetFactory; + /** + * @var \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory + */ + protected $eavSetupFactory; + public function __construct( - \Magento\Customer\Model\AttributeFactory $attributeFactory, - \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory + \Magento\Customer\Model\AttributeFactory $customerAttributeFactory, + \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory, + \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory ) { - $this->attributeFactory = $attributeFactory; + $this->customerAttributeFactory = $customerAttributeFactory; $this->attributeSetFactory = $attributeSetFactory; + $this->eavSetupFactory = $eavSetupFactory; } public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) @@ -43,25 +50,25 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface foreach ($statuses as $code => $info) { $data[] = ['status' => $code, 'label' => $info]; } - + $setup->getConnection()->insertArray( - $setup->getTable('sales_order_status'), - ['status', 'label'], + $setup->getTable('sales_order_status'), + ['status', 'label'], $data ); - + $data = []; foreach ($statuses as $code => $info) { $data[] = ['status' => $code, 'state' => Order::STATE_PROCESSING, 'default' => 0, 'visible_on_front' => 1]; } - + $setup->getConnection()->insertArray( $setup->getTable('sales_order_status_state'), ['status', 'state', 'is_default', 'visible_on_front'], $data ); } - + if (version_compare($context->getVersion(), '1.0.4', '<')) { $data = []; $statuses = [ @@ -70,25 +77,25 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface foreach ($statuses as $code => $info) { $data[] = ['status' => $code, 'label' => $info]; } - + $setup->getConnection()->insertArray( - $setup->getTable('sales_order_status'), - ['status', 'label'], + $setup->getTable('sales_order_status'), + ['status', 'label'], $data ); - + $data = []; foreach ($statuses as $code => $info) { $data[] = ['status' => $code, 'state' => Order::STATE_NEW, 'default' => 0, 'visible_on_front' => 1]; } - + $setup->getConnection()->insertArray( $setup->getTable('sales_order_status_state'), ['status', 'state', 'is_default', 'visible_on_front'], $data ); } - + if (version_compare($context->getVersion(), '1.0.5', '<')) { $setup->getConnection()->update( $setup->getTable('sales_order_status_state'), @@ -96,7 +103,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface ['status = ?' => HelperConstants::ORDER_STATUS_PAYLINE_CANCELED] ); } - + if (version_compare($context->getVersion(), '1.0.7', '<')) { $data = []; $statuses = [ @@ -110,17 +117,17 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface } $setup->getConnection()->insertArray( - $setup->getTable('sales_order_status'), - ['status', 'label'], + $setup->getTable('sales_order_status'), + ['status', 'label'], $data ); $data = []; foreach ($statuses as $code => $info) { $data[] = [ - 'status' => $code, - 'state' => $code == HelperConstants::ORDER_STATUS_PAYLINE_WAITING_ACCEPTANCE ? Order::STATE_PROCESSING : Order::STATE_CANCELED, - 'default' => 0, + 'status' => $code, + 'state' => $code == HelperConstants::ORDER_STATUS_PAYLINE_WAITING_ACCEPTANCE ? Order::STATE_PROCESSING : Order::STATE_CANCELED, + 'default' => 0, 'visible_on_front' => $code == HelperConstants::ORDER_STATUS_PAYLINE_FRAUD ? 0 : 1 ]; } @@ -133,7 +140,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface } if (version_compare($context->getVersion(), '1.2.0', '<')) { - $attribute = $this->attributeFactory->create(); + $attribute = $this->customerAttributeFactory->create(); $attribute->setData(array( 'entity_type_id' => \Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER, @@ -166,6 +173,22 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface ->save(); } + if (version_compare($context->getVersion(), '1.2.3', '<')) { + $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); + $eavSetup->addAttribute(\Magento\Catalog\Model\Category::ENTITY, 'payline_category_mapping', [ + 'type' => 'int', + 'label' => 'Payline Category Mapping', + 'input' => 'select', + 'source' => 'Monext\Payline\Model\Category\Attribute\Source\CategoryMapping', + 'visible' => true, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, + 'group' => 'Content', + 'sort_order' => 2000, + 'required' => false, + 'user_defined' => true, + ]); + } + $setup->endSetup(); } } diff --git a/composer.json b/composer.json index e56d607..65825d5 100644 --- a/composer.json +++ b/composer.json @@ -2,16 +2,15 @@ "name": "monext/module-payline", "description": "N/A", "require": { - "php": "~5.6.5||^7.0.0", "monext/payline-sdk": "*" }, "type": "magento2-module", - "version": "1.2.0", + "version": "1.2.3", "authors" : [ { "name" : "Matthieu BOUCHOT", - "email" : "matthieu.bouchot@ecommerce-academy.fr", - "homepage" : "http://www.academy-ecommerce.com/" + "email" : "matthieu.bouchot@agence-tbd.com", + "homepage" : "https://www.agence-tbd.com/" } ], "autoload": { diff --git a/etc/module.xml b/etc/module.xml index 850419f..3570a16 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + diff --git a/fixtures/category_mapping.csv b/fixtures/category_mapping.csv new file mode 100644 index 0000000..025da1b --- /dev/null +++ b/fixtures/category_mapping.csv @@ -0,0 +1,79 @@ +1,"Informatique (matériel et logiciel)" +100010001,"Ordinateur" +100010002,"Imprimante" +100010003,"Scanner" +2,"Électronique – TV - Hifi" +20001,"Vidéo" +200010001,"Caméscope" +200010002,"Magnétoscope" +200010003,"TV" +200010004,"Écran LCD" +200010005,"Écran Plasma" +200010006,"Home cinema" +200010007,"HIFI" +3,"Téléphone" +4,"Électroménager" +40001,"Froid" +400010001,"Réfrigérateur" +400010002,"Congélateur" +40002,"Lavage" +400020001,"Lave-vaisselle" +400020002,"Lave-linge" +400020003,"Sèche-linge" +40003,"Cuisson" +400030001,"Cuisinière" +400030002,"Table de cuisson" +5,"Habitat et jardin" +50001,"Chauffage" +500010001,"Radiateur" +50002,"Sanitaires" +50003,"Huisserie" +500030001,"Volet" +50004,"Outil de jardin" +500040001,"Tondeuse" +500040002,"Motoculteur" +500040003,"Tronçonneuse" +500040004,"Débroussailleuse" +599990001,"Cuisine livrée sans pose" +599990002,"Cuisine livrée posée" +6,"Mode Habillement" +7,"Produit de beauté" +8,"Bijouterie" +9,"Sport" +10,"Loisirs" +11,"Automobiles / motos" +110001,"Quad" +12,"Ameublement" +120001,"Mobilier de salon" +1200010001,"Canapé" +1200010002,"Fauteuil" +1200010003,"Armoire" +1200010004,"Bibliothèque" +120002,"Mobilier salle à manger" +120003,"Chambre" +1200030001,"Literie" +120004,"Mobilier de bureau" +120005,"Tissu ameublement" +120006,"Mobilier de cuisine" +120007,"Mobilier de salle de bain" +120008,"Meuble de jardin" +1200080001,"Barbecue" +13,"Enfants" +14,"Jeux vidéo" +15,"Jouets" +16,"Animaux" +17,"Alimentation" +170001,"Alimentation produits éligibles TRD" +170002,"Alimentation produits non éligibles TRD" +18,"Cadeaux" +19,"Spectacles" +20,"Voyages" +21,"Enchères" +22,"Services aux particuliers" +23,"Services aux professionnels" +24,"Musique" +240001,"Instrument de musique" +2400010001,"Piano" +2400010002,"Orgue" +25,"Livre" +26,"Photo" \ No newline at end of file diff --git a/view/adminhtml/ui_component/category_form.xml b/view/adminhtml/ui_component/category_form.xml new file mode 100644 index 0000000..644ca81 --- /dev/null +++ b/view/adminhtml/ui_component/category_form.xml @@ -0,0 +1,18 @@ + +
+
+ + + string + + + + + + +
+