Skip to content

Commit

Permalink
Merge branch 'release/1.10.2' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennelandais committed Sep 4, 2020
2 parents 8f9b339 + a9b99cd commit da6af84
Show file tree
Hide file tree
Showing 21 changed files with 271 additions and 42 deletions.
38 changes: 35 additions & 3 deletions Block/Adminhtml/Mappingshipping/Edit/Form.php
Expand Up @@ -83,8 +83,9 @@ protected function _prepareForm()
'name' => 'magento_shipping_code',
'label' => __('Magento Shipping methods'),
'title' => __('Magento Shipping methods'),
'required' => true,
'values' => $options
'values' => $options,
'onchange' => 'toggleCustomShipping()',
'required' => true
];

if ($model != null) {
Expand All @@ -93,12 +94,43 @@ protected function _prepareForm()
}
}

$fieldset->addField(
$selectField = $fieldset->addField(
'magento_shipping_code',
'select',
$config
);

$carrierList = [];
foreach($this->_shippingMethodsMagento->getCarriers() as $carrier){
$carrierList[] = $carrier['label'] . ' (code : ' . $carrier['code'] . ')';
}

$customField = $fieldset->addField(
'magento_shipping_code_custom',
'text',
[
'name' => 'magento_shipping_code_custom',
'label' => __('Custom shipping method'),
'title' => __('Custom shipping method'),
'note' => __('Shipping method should be [carrier_code]_[shipping_method_id]. Available carriers are : %1', implode(', ', $carrierList))
]
);

$customField->setAfterElementHtml('
<script>
function toggleCustomShipping() {
if(jQuery("#cart_mappingshipping_magento_shipping_code").val() === "hipay_shipping_custom"){
jQuery("#cart_mappingshipping_magento_shipping_code_custom").parents(".field").show();
} else {
jQuery("#cart_mappingshipping_magento_shipping_code_custom").parents(".field").hide();
jQuery("#cart_mappingshipping_magento_shipping_code_custom").val("");
}
}
window.onload = toggleCustomShipping;
</script>
');

$options = $this->_shippingMethodsHipay->toOptionArray();
$fieldset->addField(
'hipay_shipping_id',
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,16 @@
# Changelog

## 1.10.2

This release contains SQL changes, be sure to run the magento upgrade command:

php bin/magento setup:upgrade

- **Fix**: Fix 500 error on checkout
- **Fix**: Corrected HTTP User Agent recovering
- **Fix**: Add custom shipping methods in mappings for dynamic shipping methods


## 1.10.1

- **Fix**: Fixed some errors on capture and notifications
Expand Down
37 changes: 26 additions & 11 deletions Controller/Adminhtml/MappingShipping/Save.php
Expand Up @@ -71,18 +71,33 @@ public function execute()
if ($id) {
$model->getResource()->load($model, $id);
} else {
$count = $this->_mappingShippingCollectionFactory->create()
->addFieldToFilter('magento_shipping_code', $data['magento_shipping_code'])
->addFieldToFilter('hipay_shipping_id', $data['hipay_shipping_id'])
->count();
if($data['magento_shipping_code'] !== 'hipay_shipping_custom') {
$count = $this->_mappingShippingCollectionFactory->create()
->addFieldToFilter('magento_shipping_code', $data['magento_shipping_code'])
->count();

if ($count > 0) {
$this->messageManager->addErrorMessage(__('You have already done this mapping.'));
$this->_getSession()->setFormData($data);
return $resultRedirect->setPath(
'*/*/edit',
['profile_id' => $this->getRequest()->getParam('mapping_shipping_id')]
);
}
} else {
$count = $this->_mappingShippingCollectionFactory->create()
->addFieldToFilter('magento_shipping_code_custom', $data['magento_shipping_code_custom'])
->count();

if ($count > 0) {
$this->messageManager->addErrorMessage(__('You have already done this mapping.'));
$this->_getSession()->setFormData($data);
return $resultRedirect->setPath(
'*/*/edit',
['profile_id' => $this->getRequest()->getParam('mapping_shipping_id')]
);
}

if ($count > 1) {
$this->messageManager->addErrorMessage(__('You have already done this mapping.'));
$this->_getSession()->setFormData($data);
return $resultRedirect->setPath(
'*/*/edit',
['profile_id' => $this->getRequest()->getParam('mapping_shipping_id')]
);
}
}

Expand Down
23 changes: 22 additions & 1 deletion Model/Method/Astropay/AbstractAstropay.php
Expand Up @@ -16,6 +16,7 @@
namespace HiPay\FullserviceMagento\Model\Method\Astropay;

use HiPay\FullserviceMagento\Model\Method\AbstractMethodAPI;
use Magento\Framework\Exception\LocalizedException;

/**
* Abstract Model payment method
Expand All @@ -39,7 +40,23 @@ class AbstractAstropay extends AbstractMethodAPI
*
* @var array
*/
protected $_additionalInformationKeys = ['nationalIdentification'];
protected $_additionalInformationKeys = ['nationalIdentification', 'cc_type'];

/**
* Assign data to info model instance
*
* @param \Magento\Framework\DataObject $additionalData
* @return $this
* @throws LocalizedException
*/
public function _assignAdditionalInformation(\Magento\Framework\DataObject $additionalData)
{
parent::_assignAdditionalInformation($additionalData);
$info = $this->getInfoInstance();
$info->setCcType($additionalData->getCcType());

return $this;
}

/**
* Validate payment method information object
Expand All @@ -55,6 +72,10 @@ public function validate()
parent::validate();
$info = $this->getInfoInstance();

if(!$info->getCcType()){
return $this;
}

$nationalIdentificationNumber = $info->getAdditionalInformation('nationalIdentification');
switch ($this->_typeIdentification) {
case self::IDENTIFICATION_CPF:
Expand Down
31 changes: 30 additions & 1 deletion Model/Method/Bnpp/AbstractBnpp.php
Expand Up @@ -16,9 +16,34 @@
namespace HiPay\FullserviceMagento\Model\Method\Bnpp;

use HiPay\FullserviceMagento\Model\Method\AbstractMethodAPI;
use Magento\Framework\Exception\LocalizedException;

class AbstractBnpp extends AbstractMethodAPI
{

/**
* Additional datas
*
* @var array
*/
protected $_additionalInformationKeys = ['cc_type'];

/**
* Assign data to info model instance
*
* @param \Magento\Framework\DataObject $additionalData
* @return $this
* @throws LocalizedException
*/
public function _assignAdditionalInformation(\Magento\Framework\DataObject $additionalData)
{
parent::_assignAdditionalInformation($additionalData);
$info = $this->getInfoInstance();
$info->setCcType($additionalData->getCcType());

return $this;
}

/**
* Validate payment method information object
*
Expand All @@ -33,13 +58,17 @@ public function validate()
parent::validate();
$paymentInfo = $this->getInfoInstance();

if(!$paymentInfo->getCcType()){
return $this;
}

$order = $paymentInfo->getQuote();
if ($paymentInfo->getOrder()) {
$order = $paymentInfo->getOrder();
}

$phone = $order->getBillingAddress()->getTelephone();
if (!preg_match('"(0|\\+33|0033)[1-9][0-9]{8}"', $phone)) {
if (!preg_match('/(0|\+?33|0033)[1-9][0-9]{8}/', $phone)) {
throw new \Magento\Framework\Exception\LocalizedException('Please check the phone number entered.');
}

Expand Down
4 changes: 4 additions & 0 deletions Model/Method/CcMethod.php
Expand Up @@ -198,6 +198,10 @@ public function validate()

$info = $this->getInfoInstance();

if(!$info->getCcType()){
return $this;
}

if ($info->getAdditionalInformation('card_token')) {
return $this;
}
Expand Down
6 changes: 6 additions & 0 deletions Model/Method/HostedFieldsMethod.php
Expand Up @@ -71,7 +71,13 @@ class HostedFieldsMethod extends CcMethod
public function validate()
{
$info = $this->getInfoInstance();

if(!$info->getCcType()){
return $this;
}

$errorMsg = false;

if (!$info->getAdditionalInformation('card_token')) {
$errorMsg = __('We can\'t place the order.');
}
Expand Down
4 changes: 4 additions & 0 deletions Model/Method/Sdd.php
Expand Up @@ -108,6 +108,10 @@ public function validate()
parent::validate();
$info = $this->getInfoInstance();

if(!$info->getCcType()){
return $this;
}

$errorMsg = '';

// Get iso code from order or quote ( Validate is called twice per magento core )
Expand Down
11 changes: 10 additions & 1 deletion Model/Request/Info/DeliveryInfo.php
Expand Up @@ -63,7 +63,8 @@ public function __construct(
CollectionFactory $mappingShippingCollectionFactory,
\HiPay\FullserviceMagento\Model\System\Config\Source\ShippingMethodsHipay $shippingMethodsHipay,
$params = []
) {
)
{
parent::__construct(
$logger,
$checkoutData,
Expand All @@ -89,8 +90,16 @@ public function __construct(
$collection = $this->_mappingShippingCollectionFactory->create()
->addFieldToFilter('magento_shipping_code', $this->_order->getShippingMethod())
->load();

if ($collection->getItems()) {
$this->_mappingDelivery = $collection->getFirstItem();
} else {
$collectionCustom = $this->_mappingShippingCollectionFactory->create()
->addFieldToFilter('magento_shipping_code_custom', $this->_order->getShippingMethod())
->load();
if ($collectionCustom->getItems()) {
$this->_mappingDelivery = $collectionCustom->getFirstItem();
}
}
}
}
Expand Down
24 changes: 19 additions & 5 deletions Model/Request/Order.php
Expand Up @@ -53,7 +53,11 @@ class Order extends CommonRequest
'VI' => 'visa',
'AE' => 'american-express',
'MC' => 'mastercard',
'MI' => 'maestro'
'MI' => 'maestro',
'visa' => 'visa',
'american-express' => 'american-express',
'mastercard' => 'mastercard',
'maestro' => 'maestro'
);

protected $_cardPaymentMethod = array(
Expand Down Expand Up @@ -116,6 +120,11 @@ class Order extends CommonRequest
*/
protected $frontendUrlBuilder;

/**
* @var \Magento\Framework\HTTP\Header
*/
protected $_httpHeader;

/**
* {@inheritDoc}
* @see \HiPay\FullserviceMagento\Model\Request\AbstractRequest::__construct()
Expand All @@ -138,6 +147,7 @@ public function __construct(
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface,
\Magento\Customer\Api\GroupRepositoryInterface $groupRepositoryInterface,
\Magento\Framework\App\State $appState,
\Magento\Framework\HTTP\Header $httpHeader,
$params = []
) {
parent::__construct(
Expand All @@ -164,6 +174,7 @@ public function __construct(
$this->_productRepositoryInterface = $productRepositoryInterface;
$this->_customerRepositoryInterface = $customerRepositoryInterface;
$this->_groupRepositoryInterface = $groupRepositoryInterface;
$this->_httpHeader = $httpHeader;

if (isset($params['order']) && $params['order'] instanceof \Magento\Sales\Model\Order) {
$this->_order = $params['order'];
Expand All @@ -188,11 +199,12 @@ public function __construct(

protected function getCcTypeHipay($mageCcType)
{
$hipayCcType = $mageCcType;

if (in_array($mageCcType, array_keys($this->_ccTypes))) {
$hipayCcType = $this->_ccTypes[$mageCcType];
return $this->_ccTypes[$mageCcType];
}
return $hipayCcType;

return false;
}

/**
Expand Down Expand Up @@ -334,6 +346,8 @@ public function mapRequest()
);
}

$orderRequest->http_user_agent = $this->_httpHeader->getHttpUserAgent();

return $orderRequest;
}

Expand Down Expand Up @@ -453,7 +467,7 @@ private function processExtraInformations(OrderRequest &$orderRequest, $useOrder
*/
if ($orderRequest->payment_product == 'bnpp-3xcb' || $orderRequest->payment_product == 'bnpp-4xcb') {
$orderRequest->customerBillingInfo->phone = preg_replace(
'/^(\+33)|(33)/',
'/^\+?33/',
'0',
$orderRequest->customerBillingInfo->phone
);
Expand Down
25 changes: 25 additions & 0 deletions Model/System/Config/Source/ShippingMethodsMagento.php
Expand Up @@ -83,6 +83,31 @@ public function toOptionArray()
}
}
}

$options[] = array(
'value' => 'hipay_shipping_custom',
'label' => __('Custom shipping code')
);

return $options;
}

public function getCarriers()
{
$carriersArray = [];
$carriers = $this->_config_shipping->getActiveCarriers();
foreach ($carriers as $carrier) {
$carrierTitle = $this->_scopeConfig->getValue(
'carriers/' . $carrier->getId() . '/title',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

$carriersArray[] = array(
'label' => $carrierTitle,
'code' => $carrier->getId()
);
}

return $carriersArray;
}
}

0 comments on commit da6af84

Please sign in to comment.