Skip to content

Commit

Permalink
Merge pull request #12 in DEV-MO/shopware5-module from hotfix/ets-27-…
Browse files Browse the repository at this point in the history
…ratepay-plugin-prevents-customer-registration to release/5.2.3

* commit '18cb1e2a5e77a168d46b7e46ca2f71c8c3c13bfb':
  [ETS-27] fix missing method by using AddressWrapper
  hotfix/ets-27-ratepay-plugin-prevents-customer-registration more tests
  more tests
  tests
  add some tests
  hotfix/ets-27-ratepay-plugin-prevents-customer-registration add support for proxy classes
  hotfix/ets-27-ratepay-plugin-prevents-customer-registration
  • Loading branch information
rpWhittington committed Aug 27, 2018
2 parents 11c48da + 18cb1e2 commit 2967995
Show file tree
Hide file tree
Showing 18 changed files with 773 additions and 97 deletions.
46 changes: 20 additions & 26 deletions Bootstrapping/Events/PaymentFilterSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace RpayRatePay\Bootstrapping\Events;

use RatePAY\Service\Util;
use RpayRatePay\Component\Model\ShopwareCustomerWrapper;
use RpayRatePay\Component\Service\ConfigLoader;
use RpayRatePay\Component\Service\ValidationLib as ValidationService;

Expand All @@ -33,7 +34,7 @@ public static function getSubscribedEvents()
* - The Country must be germany or austria
* - The Currency must be EUR
*
* @param Enlight_Event_EventArgs $arguments
* @param \Enlight_Event_EventArgs $arguments
* @return array|void
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
Expand All @@ -44,45 +45,33 @@ public function filterPayments(\Enlight_Event_EventArgs $arguments)
$return = $arguments->getReturn();
$currency = Shopware()->Config()->get('currency');
$userId = Shopware()->Session()->sUserId;

if (empty($userId) || empty($currency)) {
return;
}

$user = Shopware()->Models()->find('Shopware\Models\Customer\Customer', Shopware()->Session()->sUserId);
/** @var Shopware\Models\Customer\Customer $user */
$user = Shopware()->Models()->find('Shopware\Models\Customer\Customer', $userId);
$wrappedUser = new ShopwareCustomerWrapper($user, Shopware()->Models());

//get country of order
if (Shopware()->Session()->checkoutBillingAddressId > 0) { // From Shopware 5.2 find current address information in default billing address
$addressModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Address');
$customerAddressBilling = $addressModel->findOneBy(array('id' => Shopware()->Session()->checkoutBillingAddressId));

if (Util::existsAndNotEmpty($customerAddressBilling,'getCountry')) {
$countryBilling = $customerAddressBilling->getCountry();
} else {
if (Util::existsAndNotEmpty($user->getBilling(),'getCountryId')) {
$countryBilling = Shopware()->Models()->find('Shopware\Models\Country\Country', $user->getBilling()->getCountryId());
}
}
$countryBilling = $customerAddressBilling->getCountry();

if (Shopware()->Session()->checkoutShippingAddressId > 0 && Shopware()->Session()->checkoutShippingAddressId != Shopware()->Session()->checkoutBillingAddressId) {
$customerAddressShipping = $addressModel->findOneBy(array('id' => Shopware()->Session()->checkoutShippingAddressId));

if (Util::existsAndNotEmpty($customerAddressShipping, 'getCountry')) {
$countryDelivery = $customerAddressShipping->getCountry();
} else {
if (Util::existsAndNotEmpty($user->getShipping(), 'getCountryId')) {
$countryDelivery = Shopware()->Models()->find('Shopware\Models\Country\Country', $user->getShipping()->getCountryId());
}
}

$countryDelivery = $customerAddressShipping->getCountry();
} else {
$countryDelivery = $countryBilling;
}
} else {
$countryBilling = Shopware()->Models()->find('Shopware\Models\Country\Country', $user->getBilling()->getCountryId());
if (!is_null($user->getShipping()) &&$user->getBilling()->getCountryId() != $user->getShipping()->getCountryId()) {
$countryDelivery = Shopware()->Models()->find('Shopware\Models\Country\Country', $user->getShipping()->getCountryId());
} else {

$countryBilling = $wrappedUser->getBillingCountry();
$countryDelivery = $wrappedUser->getShippingCountry();

if (is_null($countryDelivery)) {
$countryDelivery = $countryBilling;
}
}
Expand All @@ -95,7 +84,7 @@ public function filterPayments(\Enlight_Event_EventArgs $arguments)
foreach ($config AS $payment => $data) {
$show[$payment] = $data['status'] == 2 ? true : false;

$validation = new \Shopware_Plugins_Frontend_RpayRatePay_Component_Validation($user);
$validation = $this->getValidator($user);

$validation->setAllowedCurrencies($data['currency']);
$validation->setAllowedCountriesBilling($data['country-code-billing']);
Expand Down Expand Up @@ -180,11 +169,18 @@ public function filterPayments(\Enlight_Event_EventArgs $arguments)
return $payments;
}

private function getValidator($user)
{
return new \Shopware_Plugins_Frontend_RpayRatePay_Component_Validation($user);
}


/**
* Get ratepay plugin config from rpay_ratepay_config table
*
* @param $shopId
* @param $country
* @param bool $backend
* @return array
*/
private function getRatePayPluginConfigByCountry($shopId, $country, $backend = false) {
Expand All @@ -204,6 +200,4 @@ private function getRatePayPluginConfigByCountry($shopId, $country, $backend = f

return $paymentConfig;
}


}
15 changes: 6 additions & 9 deletions Bootstrapping/Events/TemplateExtensionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
namespace RpayRatePay\Bootstrapping\Events;

use RpayRatePay\Component\Model\ShopwareCustomerWrapper;

class TemplateExtensionSubscriber implements \Enlight\Event\SubscriberInterface
{
/**
Expand Down Expand Up @@ -38,7 +40,7 @@ public static function getSubscribedEvents()
*/
public function extendTemplates(\Enlight_Event_EventArgs $args)
{
/** @var $action Enlight_Controller_Action */
/** @var $action \Enlight_Controller_Action */
$action = $args->getSubject();
$request = $action->Request();
$response = $action->Response();
Expand Down Expand Up @@ -72,14 +74,9 @@ public function extendTemplates(\Enlight_Event_EventArgs $args)
'confirm' === $request->getActionName() &&
strstr($paymentMethod->getName(), 'rpayratepay')
) {
if (method_exists($user, 'getDefaultBillingAddress')) { // From Shopware 5.2 find current address information in default billing address
$view->assign('ratepayPhone', $user->getDefaultBillingAddress()->getPhone());
$country = $user->getDefaultBillingAddress()->getCountry()->getIso();
$countryCode = $user->getDefaultBillingAddress()->getCountry();
} else {
$country = Shopware()->Models()->find('Shopware\Models\Country\Country', $user->getBilling()->getCountryId())->getIso();
$countryCode = Shopware()->Models()->find('Shopware\Models\Country\Country', $user->getBilling()->getCountryId());
}
$userWrapped = new ShopwareCustomerWrapper($user, Shopware()->Models());
$phone = $userWrapped->getBilling('phone');
$view->assign('ratepayPhone', $phone);

$sandbox = true;
if ($configPlugin['sandbox'] == 0) {
Expand Down
2 changes: 1 addition & 1 deletion Component/Mapper/BasketArrayBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function addItem($item)
/**
* @param $item
*/
private function addItemFromArray($item)
public function addItemFromArray($item)
{
if (!$this->requestType && $item['quantity'] == 0) {
return;
Expand Down
4 changes: 3 additions & 1 deletion Component/Mapper/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use RpayRatePay\Component\Mapper\PaymentRequestData;
use RpayRatePay\Component\Mapper\BankData;
use RatePAY\Service\Util;
use RpayRatePay\Component\Model\ShopwareCustomerWrapper;
use RpayRatePay\Component\Service\SessionLoader;

/**
Expand Down Expand Up @@ -76,7 +77,8 @@ private function _getCountryCodesByBillingAddress()
return $checkoutAddressBilling->getCountry()->getIso();
} else {
$shopUser = Shopware()->Models()->find('Shopware\Models\Customer\Customer', $this->getSession()->sUserId);
$country = Shopware()->Models()->find('Shopware\Models\Country\Country', $shopUser->getBilling()->getCountryId());
$userWrapped = new ShopwareCustomerWrapper($shopUser, Shopware()->Models());
$country = $userWrapped->getBillingCountry();
return $country->getIso();
}
}
Expand Down
21 changes: 10 additions & 11 deletions Component/Mapper/PaymentRequestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace RpayRatePay\Component\Mapper;

use RatePAY\Service\Util;
use RpayRatePay\Component\Model\ShopwareAddressWrapper;
use RpayRatePay\Component\Model\ShopwareCustomerWrapper;

class PaymentRequestData
{
Expand Down Expand Up @@ -156,7 +158,9 @@ public function __construct($method,
public function getBirthday()
{
$dateOfBirth = '0000-00-00';
$customerBilling = $this->customer->getBilling();

$customerWrapped = new ShopwareCustomerWrapper($this->customer, Shopware()->Models());
$customerBilling = $customerWrapped->getBilling();

if (Util::existsAndNotEmpty($this->customer, 'getBirthday')) {
$dateOfBirth = $this->customer->getBirthday()->format("Y-m-d"); // From Shopware 5.2 date of birth has moved to customer object
Expand All @@ -170,19 +174,14 @@ public function getBirthday()
}

/**
* @param mixed
* @return string|null
* @param $addressObject
* @return string
* @throws \Exception
*/
public static function findCountryISO($addressObject)
{
$iso = null;
if (Util::existsAndNotEmpty($addressObject, "getCountry") &&
Util::existsAndNotEmpty($addressObject->getCountry(), "getIso")) {
$iso = $addressObject->getCountry()->getIso();
} elseif (Util::existsAndNotEmpty($addressObject, "getCountryId")) {
$country = Shopware()->Models()->find('Shopware\Models\Country\Country', $addressObject->getCountryId());
$iso = $country->getIso();
}
$addressWrapped = new ShopwareAddressWrapper($addressObject, Shopware()->Models());
$iso = $addressWrapped->getCountry()->getIso();
return $iso;
}
}
52 changes: 52 additions & 0 deletions Component/Model/ShopwareAddressWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace RpayRatePay\Component\Model;



/**
* Class ShopwareAddressWrapper
* @package RpayRatePay\Component\Model
*/
class ShopwareAddressWrapper
{
/** @var object */
private $address;

/** @var \Shopware\Components\Model\ModelManager */
private $em;

/** @var string */
private $addressClass;


/**
* ShopwareAddressWrapper constructor.
* @param object $address
* @param \Shopware\Components\Model\ModelManager $em
*/
public function __construct($address, $em)
{
$this->address = $address;
$this->em = $em;
$this->addressClass = get_class($address);
}

/**
* @return \Shopware\Models\Country\Country
* @throws \Exception
*/
public function getCountry()
{
if (method_exists($this->address, 'getCountry')) {
return $this->address->getCountry();
}

if (method_exists($this->address, 'getCountryId')) {
return $this->em->find('Shopware\Models\Country\Country', $this->address->getCountryId());
}

throw new \Exception('False object type sent to ShopwareAddressWrapper');
}

}
Loading

0 comments on commit 2967995

Please sign in to comment.