diff --git a/Bootstrapping/Events/PaymentFilterSubscriber.php b/Bootstrapping/Events/PaymentFilterSubscriber.php
index 7fa4deca..80364495 100644
--- a/Bootstrapping/Events/PaymentFilterSubscriber.php
+++ b/Bootstrapping/Events/PaymentFilterSubscriber.php
@@ -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;
@@ -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
@@ -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;
}
}
@@ -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']);
@@ -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) {
@@ -204,6 +200,4 @@ private function getRatePayPluginConfigByCountry($shopId, $country, $backend = f
return $paymentConfig;
}
-
-
}
\ No newline at end of file
diff --git a/Bootstrapping/Events/TemplateExtensionSubscriber.php b/Bootstrapping/Events/TemplateExtensionSubscriber.php
index a673800e..4848fb37 100644
--- a/Bootstrapping/Events/TemplateExtensionSubscriber.php
+++ b/Bootstrapping/Events/TemplateExtensionSubscriber.php
@@ -7,6 +7,8 @@
*/
namespace RpayRatePay\Bootstrapping\Events;
+use RpayRatePay\Component\Model\ShopwareCustomerWrapper;
+
class TemplateExtensionSubscriber implements \Enlight\Event\SubscriberInterface
{
/**
@@ -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();
@@ -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) {
diff --git a/Component/Mapper/BasketArrayBuilder.php b/Component/Mapper/BasketArrayBuilder.php
index cc4e6c78..bc4835a1 100644
--- a/Component/Mapper/BasketArrayBuilder.php
+++ b/Component/Mapper/BasketArrayBuilder.php
@@ -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;
diff --git a/Component/Mapper/ModelFactory.php b/Component/Mapper/ModelFactory.php
index 00739245..298ef715 100755
--- a/Component/Mapper/ModelFactory.php
+++ b/Component/Mapper/ModelFactory.php
@@ -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;
/**
@@ -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();
}
}
diff --git a/Component/Mapper/PaymentRequestData.php b/Component/Mapper/PaymentRequestData.php
index a5b3a694..1a612bd8 100644
--- a/Component/Mapper/PaymentRequestData.php
+++ b/Component/Mapper/PaymentRequestData.php
@@ -9,6 +9,8 @@
namespace RpayRatePay\Component\Mapper;
use RatePAY\Service\Util;
+use RpayRatePay\Component\Model\ShopwareAddressWrapper;
+use RpayRatePay\Component\Model\ShopwareCustomerWrapper;
class PaymentRequestData
{
@@ -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
@@ -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;
}
}
diff --git a/Component/Model/ShopwareAddressWrapper.php b/Component/Model/ShopwareAddressWrapper.php
new file mode 100644
index 00000000..e4c12936
--- /dev/null
+++ b/Component/Model/ShopwareAddressWrapper.php
@@ -0,0 +1,52 @@
+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');
+ }
+
+}
\ No newline at end of file
diff --git a/Component/Model/ShopwareCustomerWrapper.php b/Component/Model/ShopwareCustomerWrapper.php
new file mode 100644
index 00000000..55e8e069
--- /dev/null
+++ b/Component/Model/ShopwareCustomerWrapper.php
@@ -0,0 +1,218 @@
+customer = $customer;
+ $this->em = $em;
+ }
+
+ /**
+ * @param $property
+ * @return null|mixed
+ */
+ public function getShipping($property = null)
+ {
+ if (is_null($property)) {
+ return $this->getShippingChaotic();
+ }
+
+ $getter = 'get' . ucfirst($property);
+
+ $shippingFresh = $this->getShippingFresh();
+
+ if (!is_null($shippingFresh)) {
+ if (Util::existsAndNotEmpty($shippingFresh, $getter)) {
+ return $shippingFresh->$getter();
+ }
+ }
+
+ $shippingRotten = $this->getShippingRotten();
+ if (!is_null($shippingRotten)) {
+ if (Util::existsAndNotEmpty($shippingRotten, $getter)) {
+ return $shippingRotten->$getter();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @param $property
+ * @return null|mixed
+ */
+ public function getBilling($property = null)
+ {
+ if (is_null($property)) {
+ return $this->getBillingChaotic();
+ }
+
+ $getter = 'get' . ucfirst($property);
+
+ $billingFresh = $this->getBillingFresh();
+
+ if (!is_null($billingFresh)) {
+ if (Util::existsAndNotEmpty($billingFresh, $getter)) {
+ return $billingFresh->$getter();
+ }
+ }
+
+ $billingRotten = $this->getBillingRotten();
+ if (!is_null($billingRotten)) {
+ if (Util::existsAndNotEmpty($billingRotten, $getter)) {
+ return $billingRotten->$getter();
+ }
+ }
+
+ return null;
+ }
+
+ private function getBillingChaotic()
+ {
+ $fresh = $this->getBillingFresh();
+ if (!is_null($fresh)) {
+ return $fresh;
+ }
+
+ $rotten = $this->getBillingRotten();
+ return $rotten;
+ }
+
+ private function getShippingChaotic()
+ {
+ $fresh = $this->getShippingFresh();
+ if (!is_null($fresh)) {
+ return $fresh;
+ }
+
+ $rotten = $this->getShippingRotten();
+ return $rotten;
+ }
+
+
+ /**
+ * @return null|object|\Shopware\Models\Country\Country
+ * @throws \Doctrine\ORM\ORMException
+ * @throws \Doctrine\ORM\OptimisticLockException
+ * @throws \Doctrine\ORM\TransactionRequiredException
+ */
+ public function getBillingCountry()
+ {
+ $billingFresh = $this->getBillingFresh();
+
+ if (!is_null($billingFresh)) {
+ return $billingFresh->getCountry();
+ }
+
+ $billingRotten = $this->getBillingRotten();
+
+ if (is_null($billingRotten)) {
+ return null;
+ }
+
+ $country = $this->em->find('Shopware\Models\Country\Country', $billingRotten->getCountryId());
+
+ return $country;
+ }
+
+ /**
+ * @return null|object|\Shopware\Models\Country\Country
+ * @throws \Doctrine\ORM\ORMException
+ * @throws \Doctrine\ORM\OptimisticLockException
+ * @throws \Doctrine\ORM\TransactionRequiredException
+ */
+ public function getShippingCountry()
+ {
+ $shippingFresh = $this->getShippingFresh();
+
+ if (!is_null($shippingFresh)) {
+ return $shippingFresh->getCountry();
+ }
+
+ $shippingRotten = $this->getShippingRotten();
+
+ if (is_null($shippingRotten)) {
+ return null;
+ }
+
+ $country = $this->em->find('Shopware\Models\Country\Country', $shippingRotten->getCountryId());
+
+ return $country;
+ }
+
+
+
+ /**
+ * @return null|\Shopware\Models\Customer\Address
+ */
+ private function getBillingFresh()
+ {
+ if (Util::existsAndNotEmpty($this->customer, 'getDefaultBillingAddress')) {
+ return $this->customer->getDefaultBillingAddress();
+ }
+
+ return null;
+ }
+
+ /**
+ * @return null|\Shopware\Models\Customer\Billing
+ */
+ private function getBillingRotten()
+ {
+ if (Util::existsAndNotEmpty($this->customer, 'getBilling')) {
+ return $this->customer->getBilling();
+ }
+
+ return null;
+ }
+
+ /**
+ * @return null|\Shopware\Models\Customer\Address
+ */
+ private function getShippingFresh()
+ {
+ if (Util::existsAndNotEmpty($this->customer, 'getDefaultShippingAddress')) {
+ return $this->customer->getDefaultShippingAddress();
+ }
+
+ return null;
+ }
+
+ /**
+ * @return null|\Shopware\Models\Customer\Shipping
+ */
+ private function getShippingRotten()
+ {
+ if (Util::existsAndNotEmpty($this->customer, 'getShipping')) {
+ return $this->customer->getShipping();
+ }
+
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/Component/Service/SessionLoader.php b/Component/Service/SessionLoader.php
index 52cfc946..b94404a8 100644
--- a/Component/Service/SessionLoader.php
+++ b/Component/Service/SessionLoader.php
@@ -9,6 +9,7 @@
use RpayRatePay\Component\Mapper\BankData;
use RpayRatePay\Component\Mapper\PaymentRequestData;
+use RpayRatePay\Component\Model\ShopwareCustomerWrapper;
class SessionLoader
{
@@ -71,11 +72,12 @@ public function getBankData($customerAddressBilling, $customerId)
*/
private function findAddressShipping($customer, $billing)
{
+ $customerWrapped = new ShopwareCustomerWrapper($customer, Shopware()->Models());
if (isset($this->session->RatePAY['checkoutShippingAddressId']) && $this->session->RatePAY['checkoutShippingAddressId'] > 0) {
$addressModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Address');
$checkoutAddressShipping = $addressModel->findOneBy(array('id' => $this->session->RatePAY['checkoutShippingAddressId'] ? $this->session->RatePAY['checkoutShippingAddressId'] : $this->session->RatePAY['checkoutBillingAddressId']));
} else {
- $checkoutAddressShipping = $customer->getShipping() !== null ? $customer->getShipping() : $billing;
+ $checkoutAddressShipping = $customerWrapped->getShipping() !== null ? $customerWrapped->getShipping() : $billing;
}
return $checkoutAddressShipping;
}
@@ -86,11 +88,13 @@ private function findAddressShipping($customer, $billing)
*/
private function findAddressBilling($customer)
{
+ $customerWrapped = new ShopwareCustomerWrapper($customer, Shopware()->Models());
+
if (isset($this->session->RatePAY['checkoutBillingAddressId']) && $this->session->RatePAY['checkoutBillingAddressId'] > 0) {
$addressModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Address');
$checkoutAddressBilling = $addressModel->findOneBy(array('id' => $this->session->RatePAY['checkoutBillingAddressId']));
} else {
- $checkoutAddressBilling = $customer->getBilling();
+ $checkoutAddressBilling = $customerWrapped->getBilling();
}
return $checkoutAddressBilling;
diff --git a/Component/Service/ValidationLib.php b/Component/Service/ValidationLib.php
index 59d609a2..2b5f0cea 100644
--- a/Component/Service/ValidationLib.php
+++ b/Component/Service/ValidationLib.php
@@ -7,6 +7,8 @@
*/
namespace RpayRatePay\Component\Service;
+use RpayRatePay\Component\Model\ShopwareCustomerWrapper;
+use Shopware\Models\Customer\Billing;
use Shopware\Models\Customer\Customer;
class ValidationLib
@@ -23,12 +25,10 @@ public static function isBirthdayValid(Customer $customer, $b2b = false)
$birthday = $customer->getBirthday();
- //throws exception, method not found
- //if necessary, we could check for it through reflection
- //TODO, ask Anni about this
- /*if (empty($birthday) || is_null($birthday)) {
- $birthday = $customer->getBilling()->getBirthday();
- }*/
+ if (empty($birthday) || is_null($birthday)) {
+ $customerWrapped = new ShopwareCustomerWrapper($customer, Shopware()->Models());
+ $birthday = $customerWrapped->getBilling('birthday');
+ }
$return = false;
if (!is_null($birthday)) {
@@ -51,7 +51,8 @@ public static function isBirthdayValid(Customer $customer, $b2b = false)
*/
public static function isTelephoneNumberSet(Customer $customer)
{
- $phone = $customer->getBilling()->getPhone();
+ $customerWrapped = new ShopwareCustomerWrapper($customer, Shopware()->Models());
+ $phone = $customerWrapped->getBilling('phone');
return !empty($phone);
}
@@ -60,8 +61,8 @@ public static function isTelephoneNumberSet(Customer $customer)
* Compares billing and shipping addresses.
* If shipping is null, returns true.
*
- * @param Shopware\Models\Customer\Address $billing
- * @param Shopware\Models\Customer\Address $shipping
+ * @param Shopware\Models\Customer\Address|Shopware\Models\Customer\Billing $billing
+ * @param Shopware\Models\Customer\Address|Shopware\Models\Customer\Shipping $shipping
*/
public static function areBillingAndShippingSame($billing, $shipping = null)
{
diff --git a/Component/Validation.php b/Component/Validation.php
index 22226b41..fac13925 100755
--- a/Component/Validation.php
+++ b/Component/Validation.php
@@ -1,5 +1,6 @@
_user = $user;
+ $this->userWrapped = new ShopwareCustomerWrapper($user, Shopware()->Models());
$this->_payment = $payment;
}
@@ -106,7 +115,7 @@ public function isRatePAYPayment()
/**
* Checks the Customers Age for RatePAY payments
*
- * TODO remove dupliacte code (see isBirthdayValid
+ * TODO remove duplicate code (see isBirthdayValid)
* @return boolean
*/
public function isAgeValid()
@@ -115,7 +124,7 @@ public function isAgeValid()
$birthday = $this->_user->getBirthday();
if (empty($birthday) || is_null($birthday)) {
- $birthday = $this->_user->getBilling()->getBirthday();
+ $birthday = $this->userWrapped->getBilling('birthday');
}
$return = false;
@@ -161,14 +170,15 @@ public function isCompanyNameSet()
$checkoutAddressBilling = $addressModel->findOneBy(array('id' => Shopware()->Session()->checkoutBillingAddressId));
$companyName = $checkoutAddressBilling->getCompany();
} else {
- $companyName = $this->_user->getBilling()->getCompany();
+
+ $companyName = $this->userWrapped->getBilling('company');
}
return !empty($companyName);
}
/**
- * Compares the Data of billing- and shippingaddress.
+ * Compares the Data of billing and shipping addresses.
*
* @return boolean
*/
@@ -178,14 +188,14 @@ public function isBillingAddressSameLikeShippingAddress()
$addressModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Address');
$billingAddress = $addressModel->findOneBy(array('id' => Shopware()->Session()->checkoutBillingAddressId));
} else {
- $billingAddress = $this->_user->getBilling();
+ $billingAddress = $this->userWrapped->getBilling();
}
if (Shopware()->Session()->checkoutShippingAddressId > 0) { // From Shopware 5.2 session contains current shipping address
$addressModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Address');
$shippingAddress = $addressModel->findOneBy(array('id' => Shopware()->Session()->checkoutShippingAddressId));
} else {
- $shippingAddress = $this->_user->getShipping();
+ $shippingAddress = $this->userWrapped->getShipping();
}
$return = ValidationService::areBillingAndShippingSame($billingAddress, $shippingAddress);
@@ -194,29 +204,29 @@ public function isBillingAddressSameLikeShippingAddress()
}
/**
- * Compares the Country of billing- and shippingaddress.
- *
- * @return boolean
+ * @return bool
+ * @throws \Doctrine\ORM\ORMException
+ * @throws \Doctrine\ORM\OptimisticLockException
+ * @throws \Doctrine\ORM\TransactionRequiredException
*/
public function isCountryEqual()
{
- $billingAddress = $this->_user->getBilling();
- $shippingAddress = $this->_user->getShipping();
- $return = true;
- if (!is_null($shippingAddress)) {
- if ($billingAddress->getCountryId() != $shippingAddress->getCountryId()) {
- $return = false;
+ $billingCountry = $this->userWrapped->getBillingCountry();
+ $shippingCountry = $this->userWrapped->getShippingCountry();
+
+ if (!is_null($shippingCountry)) {
+ if ($billingCountry->getId() != $shippingCountry->getId()) {
+ return false;
}
}
- return $return;
+ return true;
}
/**
- * Checks if the country is germany or austria
- *
- * @param Shopware\Models\Country\Country $country
- * @return boolean
+ * Searches allowedCurrencies
+ * @param $currency
+ * @return bool
*/
public function isCurrencyValid($currency)
{
@@ -246,13 +256,14 @@ public function isDeliveryCountryValid($country)
}
/**
- * Checks if payment methods are hidden by session. Methods will be hide just in live/production mode
- *
* @return bool
+ * @throws \Doctrine\ORM\ORMException
+ * @throws \Doctrine\ORM\OptimisticLockException
+ * @throws \Doctrine\ORM\TransactionRequiredException
*/
public function isRatepayHidden() {
$config = Shopware()->Plugins()->Frontend()->RpayRatePay()->Config();
- $country = Shopware()->Models()->find('Shopware\Models\Country\Country', $this->_user->getBilling()->getCountryId())->getIso();
+ $country = $this->userWrapped->getBillingCountry()->getIso();
if('DE' === $country || 'AT' === $country || 'CH' === $country) {
$sandbox = $config->get('RatePaySandbox' . $country);
diff --git a/Controller/frontend/RpayRatepay.php b/Controller/frontend/RpayRatepay.php
index a138a358..6a8dc9f1 100755
--- a/Controller/frontend/RpayRatepay.php
+++ b/Controller/frontend/RpayRatepay.php
@@ -18,10 +18,10 @@
* @copyright Copyright (c) 2013 RatePAY GmbH (http://www.ratepay.com)
*/
-use RatePAY\Service\Util;
use RpayRatePay\Component\Service\SessionLoader;
use Shopware\Components\CSRFWhitelistAware;
-use \RpayRatePay\Component\Service\PaymentProcessor;
+use RpayRatePay\Component\Service\PaymentProcessor;
+use RpayRatePay\Component\Model\ShopwareCustomerWrapper;
class Shopware_Controllers_Frontend_RpayRatepay extends Shopware_Controllers_Frontend_Payment implements CSRFWhitelistAware
{
@@ -119,7 +119,10 @@ public function saveUserDataAction()
$Parameter = $this->Request()->getParams();
$customerModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Customer');
+
+ /** @var Shopware\Models\Customer\Customer $userModel */
$userModel = $customerModel->findOneBy(array('id' => Shopware()->Session()->sUserId));
+ $userWrapped = new ShopwareCustomerWrapper($userModel);
if (isset($Parameter['checkoutBillingAddressId']) && !is_null($Parameter['checkoutBillingAddressId'])) { // From Shopware 5.2 current billing address is sent by parameter
$addressModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Address');
@@ -131,7 +134,7 @@ public function saveUserDataAction()
unset(Shopware()->Session()->RatePAY['checkoutShippingAddressId']);
}
} else {
- $customerAddressBilling = $userModel->getBilling();
+ $customerAddressBilling = $userWrapped->getBilling();
}
$return = 'OK';
@@ -277,7 +280,8 @@ private function _error()
$shopId = Shopware()->Shop()->getId();
$customerModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Customer');
$userModel = $customerModel->findOneBy(array('id' => Shopware()->Session()->sUserId));
- $countryBilling = Shopware()->Models()->find('Shopware\Models\Country\Country', $userModel->getBilling()->getCountryId());
+ $userModelWrapped = new ShopwareCustomerWrapper($userModel, Shopware()->Models());
+ $countryBilling = $userModelWrapped->getBillingCountry();
$config = $this->getRatePayPluginConfigByCountry($shopId, $countryBilling);
$this->View()->assign('rpCustomerMsg', $config['error-default']);
diff --git a/Tests/Functional/Component/Model/ShopwareAddressWrapperTest.php b/Tests/Functional/Component/Model/ShopwareAddressWrapperTest.php
new file mode 100644
index 00000000..94ebe3ec
--- /dev/null
+++ b/Tests/Functional/Component/Model/ShopwareAddressWrapperTest.php
@@ -0,0 +1,67 @@
+getAddressMock();
+ $wrapper = new ShopwareAddressWrapper($address, Shopware()->Models());
+ $country = $wrapper->getCountry();
+ $this->assertEquals($country->getIso(), 'DE');
+
+ if (class_exists('Shopware\Models\Customer\Billing')) {
+ $address = $this->getRottenMock(true);
+ $wrapper = new ShopwareAddressWrapper($address, Shopware()->Models());
+ $country = $wrapper->getCountry();
+ $this->assertEquals($country->getIso(), 'DE');
+ }
+
+ if (class_exists('Shopware\Models\Customer\Shipping')) {
+ $address = $this->getRottenMock(false);
+ $wrapper = new ShopwareAddressWrapper($address, Shopware()->Models());
+ $country = $wrapper->getCountry();
+ $this->assertEquals($country->getIso(), 'DE');
+ }
+
+ //test exception for worng object type
+ $this->expectException('\Exception');
+ $datetime = new \DateTime();
+ $wrapper = new ShopwareAddressWrapper($datetime);
+ $wrapper->getCountry();
+ }
+
+ private function getAddressMock()
+ {
+ $country = Shopware()->Models()->getRepository('Shopware\Models\Country\Country')
+ ->findOneBy(['iso' => 'DE']);
+
+
+ $stub = $this->createMock('Shopware\Models\Customer\Address');
+
+ $stub->method('getCountry')
+ ->willReturn($country);
+
+ return $stub;
+ }
+
+ private function getRottenMock($billing)
+ {
+ $country = Shopware()->Models()->getRepository('Shopware\Models\Country\Country')
+ ->findOneBy(['iso' => 'DE']);
+
+ $class = $billing ? 'Shopware\Models\Customer\Billing' : 'Shopware\Models\Customer\Shipping';
+
+ $stub = $this->createMock($class);
+
+ $stub->method('getCountryId')
+ ->willReturn($country->getId());
+
+ return $stub;
+ }
+}
\ No newline at end of file
diff --git a/Tests/Functional/Component/Model/ShopwareCustomerWrapperTest.php b/Tests/Functional/Component/Model/ShopwareCustomerWrapperTest.php
new file mode 100644
index 00000000..5068f308
--- /dev/null
+++ b/Tests/Functional/Component/Model/ShopwareCustomerWrapperTest.php
@@ -0,0 +1,197 @@
+_testGetBilling__fresh();
+ $this->_testGetBillingCountry__fresh();
+
+ if (!class_exists('Shopware\Models\Customer\Billing')) {
+ return;
+ }
+
+ $this->_testGetBilling__rotten();
+ $this->_testGetBillingCountry__rotten();
+ }
+
+ private function _testGetBilling__fresh()
+ {
+ $mock = $this->getCustomerFreshMock();
+ $wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());
+
+ $this->assertEquals(
+ $wrapper->getBilling('phone'),
+ '015106483257'
+ );
+
+ $billing = $wrapper->getBilling();
+
+ $this->assertEquals(
+ $billing->getCountry()->getIso(),
+ 'BC'
+ );
+ }
+
+ private function _testGetBillingCountry__fresh()
+ {
+ $mock = $this->getCustomerFreshMock();
+ $wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());
+
+ $country = $wrapper->getBillingCountry();
+
+ $this->assertEquals(
+ $country->getIso(),
+ 'BC'
+ );
+ }
+
+ private function _testGetBilling__rotten()
+ {
+ $mock = $this->getCustomerRottenMock();
+ $wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());
+
+ $this->assertEquals(
+ $wrapper->getBilling('phone'),
+ '1111111111'
+ );
+
+ $billing = $wrapper->getBilling();
+ $this->assertNotNull($billing->getCountryId());
+
+ }
+
+ private function _testGetBillingCountry__rotten()
+ {
+ return;
+ $mock = $this->getCustomerRottenMock();
+ $wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());
+
+ $country = $wrapper->getBillingCountry();
+
+ $this->assertEquals(
+ $country->getIso(),
+ 'DE'
+ );
+ }
+
+ public function _testGetShipping__fresh()
+ {
+ $mock = $this->getCustomerFreshMock(false);
+ $wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());
+
+ $this->assertEquals(
+ $wrapper->getShipping('phone'),
+ '015106483257'
+ );
+
+ $shipping = $wrapper->getShipping();
+
+ $this->assertEquals(
+ $shipping->getCountry()->getIso(),
+ 'BC'
+ );
+ }
+
+ public function _testGetShippingCountry__fresh()
+ {
+ $mock = $this->getCustomerFreshMock(false);
+ $wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());
+
+ $country = $wrapper->getShippingCountry();
+
+ $this->assertEquals(
+ $country->getIso(),
+ 'BC'
+ );
+ }
+
+ public function testGetShipping()
+ {
+ $this->_testGetShipping__fresh();
+ $this->_testGetShippingCountry__fresh();
+
+ if (!class_exists('Shopware\Models\Customer\Shipping')) {
+ return;
+ }
+
+ $this->_testGetShipping__rotten();
+ $this->_testGetShippingCountry__rotten();
+ }
+
+ private function _testGetShipping__rotten()
+ {
+ $mock = $this->getCustomerRottenMock(false);
+ $wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());
+
+ $this->assertEquals(
+ $wrapper->getShipping('phone'),
+ '1111111111'
+ );
+
+ $shipping = $wrapper->getShipping();
+ $this->assertNotNull($shipping->getCountryId());
+ }
+
+ private function _testGetShippingCountry__rotten()
+ {
+ $mock = $this->getCustomerRottenMock(false);
+ $wrapper = new ShopwareCustomerWrapper($mock, Shopware()->Models());
+
+ $country = $wrapper->getShippingCountry();
+
+ $this->assertEquals(
+ $country->getIso(),
+ 'DE'
+ );
+ }
+
+ private function getCustomerFreshMock($billingTest = true)
+ {
+ $country = new \Shopware\Models\Country\Country();
+ $country->setIso('BC');
+
+ $defaultBillingAddress = new \Shopware\Models\Customer\Address();
+ $defaultBillingAddress->setPhone('015106483257');
+ $defaultBillingAddress->setCountry($country);
+
+ $stub = $this->createMock('Shopware\Models\Customer\Customer');
+
+ $method = $billingTest ? 'getDefaultBillingAddress' : 'getDefaultShippingAddress';
+
+ $stub->method($method)
+ ->willReturn($defaultBillingAddress);
+
+ return $stub;
+ }
+
+ private function getCustomerRottenMock($billingTest = true)
+ {
+ $country = new \Shopware\Models\Country\Country();
+ $country->setIso('BC');
+
+ $defaultBilling = new \Shopware\Models\Customer\Billing();
+ $defaultBilling->setPhone('1111111111');
+
+
+ $country = Shopware()->Models()->getRepository('Shopware\Models\Country\Country')
+ ->findOneBy(['iso' => 'DE']);
+
+ $defaultBilling->setCountryId($country->getId());
+
+ $stub = $this->createMock('Shopware\Models\Customer\Customer');
+
+ $method = $billingTest ? 'getBilling' : 'getShipping';
+
+ $stub->method($method)
+ ->willReturn($defaultBilling);
+
+ return $stub;
+ }
+}
\ No newline at end of file
diff --git a/Tests/Functional/Events/PaymentFilterSubscriberTest.php b/Tests/Functional/Events/PaymentFilterSubscriberTest.php
new file mode 100644
index 00000000..f31f6a04
--- /dev/null
+++ b/Tests/Functional/Events/PaymentFilterSubscriberTest.php
@@ -0,0 +1,122 @@
+getRandomAddress();
+
+ unset(Shopware()->Session()->sUserId);
+
+ $paymentSubscriber = $this->getPaymentFilterSubscriberMock(null);
+
+ $eventArgs = $this->getEnlightEventEventArgsMock();
+
+ $returnNothing = $paymentSubscriber->filterPayments($eventArgs);
+
+ $this->assertNull($returnNothing);
+ }
+
+
+ public function testFilterPayments__allPaymentTypesTurnedOff()
+ {
+ Shopware()->Session()->sUserId = 1;
+
+ Shopware()->Config()->currency = '$';
+
+ $paymentSubscriber = $this->getPaymentFilterSubscriberMock([
+ 'installment' => ['status' => 1],
+ 'invoice' => ['status' => 1],
+ 'debit' => ['status' => 1],
+ 'installment0' => ['status' => 1]
+ ]);
+
+ $eventArgs = $this->getEnlightEventEventArgsMock();
+
+ $returnVal = $paymentSubscriber->filterPayments($eventArgs);
+
+ $this->assertEquals([
+ [
+ 'name' => 'paypal_payment_type'
+ ]
+ ], $returnVal);
+ }
+
+ public function testFilterPayments__allValid()
+ {
+ return; //work in progress
+
+ //TODO mock the following stuff or refactor PaymentFilterSubscriber
+ /*
+ Shopware()->Session()->sUserId = 1;
+
+ Shopware()->Config()->currency = 'EUR';
+
+ Shopware()->Modules()->Basket()->
+ */
+ }
+
+ private function getPaymentFilterSubscriberMock($configResults)
+ {
+ $mock = $this->getMockBuilder(
+ 'RpayRatePay\Bootstrapping\Events\PaymentFilterSubscriber'
+ )->setMethods(['getRatePayPluginConfigByCountry',' getValidator'])
+ ->getMock();
+
+ $mock->method('getRatePayPluginConfigByCountry')
+ ->willReturn($configResults);
+
+
+ $validatorStub = $this->createMock('Shopware_Plugins_Frontend_RpayRatePay_Component_Validation');
+
+ $validatorStub->method('isRatepayHidden')
+ ->willReturn(false);
+
+ $validatorStub->method('isCurrencyValid')
+ ->willReturn(true);
+
+ $validatorStub->method('isDeliveryCountryValid')
+ ->willReturn(true);
+
+ $validatorStub->method('isBillingAddressSameLikeShippingAddress')
+ ->willReturn(true);
+
+ return $mock;
+ }
+
+ private function getEnlightEventEventArgsMock()
+ {
+ $paymentTypes = [
+ [
+ 'name' => 'paypal_payment_type'
+ ]
+ ];
+
+ $stub = $this->createMock('\Enlight_Event_EventArgs');
+
+ $stub->method('getReturn')
+ ->willReturn($paymentTypes);
+
+ return $stub;
+ }
+
+ private function getRandomAddress()
+ {
+ $class = 'Shopware\Models\Customer\Address';
+ $ids = Shopware()->Models()->getRepository($class)
+ ->createQueryBuilder('c')
+ ->select('c.id')
+ ->getQuery()
+ ->getArrayResult();
+
+ shuffle($ids);
+
+ return Shopware()->Models()->getRepository($class)->find(array_shift($ids));
+ }
+}
\ No newline at end of file
diff --git a/Tests/Unit/Component/Mapper/BasketArrayBuilderTest.php b/Tests/Unit/Component/Mapper/BasketArrayBuilderTest.php
index b773df6c..2bca9bfc 100644
--- a/Tests/Unit/Component/Mapper/BasketArrayBuilderTest.php
+++ b/Tests/Unit/Component/Mapper/BasketArrayBuilderTest.php
@@ -6,6 +6,7 @@
* Time: 10:30
*/
use PHPUnit\Framework\TestCase;
+use Shopware_Plugins_Frontend_RpayRatePay_Component_Mapper_BasketArrayBuilder as BasketArrayBuilder;
class BasketArrayBuilderTest extends TestCase
{
@@ -31,7 +32,7 @@ public function provideArrayItems()
return [
[
- new Shopware_Plugins_Frontend_RpayRatePay_Component_Mapper_BasketArrayBuilder(false, null, false, false),
+ new BasketArrayBuilder(false, null, false, false),
$itemList,
[]
],
diff --git a/Views/responsive/frontend/installment/php/PiRatepayRateCalcData.php b/Views/responsive/frontend/installment/php/PiRatepayRateCalcData.php
index d7154233..19dfd71a 100755
--- a/Views/responsive/frontend/installment/php/PiRatepayRateCalcData.php
+++ b/Views/responsive/frontend/installment/php/PiRatepayRateCalcData.php
@@ -10,6 +10,9 @@
*/
require_once "PiRatepayRateCalcDataInterface.php";
+ //do i need a require here?
+ use RpayRatePay\Component\Model\ShopwareCustomerWrapper;
+
/**
* Developer needs to specify how the Calculator gets the Data
*/
@@ -26,8 +29,9 @@ public function getProfileId()
{
$customer = Shopware()->Models()->getRepository('Shopware\Models\Customer\Customer')
->findOneBy(array('id' => Shopware()->Session()->sUserId));
+ $customerWrapped = new ShopwareCustomerWrapper($customer, Shopware()->Models());
- $country = Shopware()->Models()->find('Shopware\Models\Country\Country', $customer->getBilling()->getCountryId());
+ $country = $customerWrapped->getBillingCountry();
$profileId = null;
if('DE' === $country->getIso())
@@ -66,7 +70,8 @@ public function getSecurityCodeHashed()
$customer = Shopware()->Models()->getRepository('Shopware\Models\Customer\Customer')
->findOneBy(array('id' => Shopware()->Session()->sUserId));
- $country = Shopware()->Models()->find('Shopware\Models\Country\Country', $customer->getBilling()->getCountryId());
+ $customerWrapped = new ShopwareCustomerWrapper($customer, Shopware()->Models());
+ $country = $customerWrapped->getBillingCountry();
$securityCode = null;
if('DE' === $country->getIso())
@@ -90,10 +95,12 @@ public function getSecurityCodeHashed()
*/
public function isLive()
{
+ /** @var Shopware\Models\Customer\Customer $customer */
$customer = Shopware()->Models()->getRepository('Shopware\Models\Customer\Customer')
->findOneBy(array('id' => Shopware()->Session()->sUserId));
- $country = Shopware()->Models()->find('Shopware\Models\Country\Country', $customer->getBilling()->getCountryId());
+ $customerWrapped = new ShopwareCustomerWrapper($customer, Shopware()->Models());
+ $country = $customerWrapped->getBillingCountry();
$modelFactory = new Shopware_Plugins_Frontend_RpayRatePay_Component_Mapper_ModelFactory();
$sandbox = $modelFactory->getSandboxMode($country->getIso());
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 44bcb083..66c7586a 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -21,12 +21,14 @@