Large diffs are not rendered by default.

@@ -114,7 +114,13 @@ public function isTelephoneNumberSet()
*/
public function isUSTSet()
{
$ust = $this->_user->getBilling()->getVatId();
if (Shopware()->Session()->checkoutBillingAddressId > 0) { // From Shopware 5.2 session contains current billing address
$addressModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Address');
$checkoutAddressBilling = $addressModel->findOneBy(array('id' => Shopware()->Session()->checkoutBillingAddressId));
$ust = $checkoutAddressBilling->getVatId();
} else {
$ust = $this->_user->getBilling()->getVatId();
}

return !empty($ust);
}
@@ -126,7 +132,13 @@ public function isUSTSet()
*/
public function isCompanyNameSet()
{
$companyName = $this->_user->getBilling()->getCompany();
if (Shopware()->Session()->checkoutBillingAddressId > 0) { // From Shopware 5.2 session contains current billing address
$addressModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Address');
$checkoutAddressBilling = $addressModel->findOneBy(array('id' => Shopware()->Session()->checkoutBillingAddressId));
$companyName = $checkoutAddressBilling->getCompany();
} else {
$companyName = $this->_user->getBilling()->getCompany();
}

return !empty($companyName);
}
@@ -138,19 +150,27 @@ public function isCompanyNameSet()
*/
public function isBillingAddressSameLikeShippingAddress()
{
$billingAddress = $this->_user->getBilling();
$shippingAddress = $this->_user->getShipping();
if (Shopware()->Session()->checkoutBillingAddressId > 0) { // From Shopware 5.2 session contains current billing address
$addressModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Address');
$billingAddress = $addressModel->findOneBy(array('id' => Shopware()->Session()->checkoutBillingAddressId));
if (Shopware()->Session()->checkoutShippingAddressId > 0) {
$shippingAddress = $addressModel->findOneBy(array('id' => Shopware()->Session()->checkoutShippingAddressId));
} else {
$shippingAddress = $billingAddress;
}
} else {
$billingAddress = $this->_user->getBilling();
$shippingAddress = $this->_user->getShipping();
}

$classFunctions = array(
'getCity',
'getCompany',
'getCountryId',
'getDepartment',
'getFirstname',
'getLastName',
'getSalutation',
'getStateId',
'getStreet',
'getZipCode'
'getZipCode',
'getCity',
);
$return = true;
if (!is_null($shippingAddress)) {
@@ -42,12 +42,12 @@ public function init()
//if shop id is not set then use main shop and set config
if(!$shopId) $shopId = 1;
$config = array();
$config['shop'] = Shopware()->Models()->find("Shopware\\Models\\Shop\\Shop", $shopId );
$config['shop'] = Shopware()->Models()->find('Shopware\Models\Shop\Shop', $shopId);
$config['db'] = Shopware()->Db();
$this->_config = new \Shopware_Components_Config($config);

//get user of current order and set sandbox mode
$orderUser = Shopware()->Models()->find('Shopware\Models\Customer\Customer', $order['userID']);
$orderUser = Shopware()->Models()->find('Shopware\Models\Customer\Customer', $order->getCustomer()->getId());
$orderCountry = Shopware()->Models()->find(
'Shopware\Models\Country\Country',
$orderUser->getBilling()->getCountryId()
@@ -284,7 +284,7 @@ public function cancelItemsAction()

$subtype = 'partial-cancellation';
$this->_modelFactory->setTransactionId($order['transactionID']);
$paymentChange = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentChange());
$paymentChange = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentChange(), $orderId);
$head = $paymentChange->getHead();
$head->setOperationSubstring($subtype);
$paymentChange->setHead($head);
@@ -361,7 +361,7 @@ public function returnItemsAction()
$subtype = 'partial-return';

$this->_modelFactory->setTransactionId($order['transactionID']);
$paymentChange = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentChange());
$paymentChange = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentChange(), $orderId);
$head = $paymentChange->getHead();
$head->setOperationSubstring($subtype);
$paymentChange->setHead($head);
@@ -28,7 +28,6 @@ class Shopware_Controllers_Frontend_RpayRatepay extends Shopware_Controllers_Fro
* @var Shopware\Models\Customer\Billing
*/
private $_config;
private $_user;
private $_service;
private $_modelFactory;
private $_logging;
@@ -42,26 +41,25 @@ public function init()

if (isset(Shopware()->Session()->sUserId)) {
$userId = Shopware()->Session()->sUserId;
} elseif ($Parameter['userid']) {
} elseif (isset($Parameter['userid'])) {
$userId = $Parameter['userid'];
} else { // return if no current user set. e.g. call by crawler
return "No user set";
return "RatePAY frontend controller: No user set";
}

$this->_config = Shopware()->Plugins()->Frontend()->RpayRatePay()->Config();

$this->_user = Shopware()->Models()->getRepository('Shopware\Models\Customer\Billing')->findOneBy(array('customerId' => $userId));

//get country of order
$country = Shopware()->Models()->find('Shopware\Models\Country\Country', $this->_user->getCountryId());
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');
$customerAddressBilling = $addressModel->findOneBy(array('id' => $Parameter['checkoutBillingAddressId']));
$country = $customerAddressBilling->getCountry();
} else {
$user = Shopware()->Models()->getRepository('Shopware\Models\Customer\Billing')->findOneBy(array('customerId' => $userId));
$country = Shopware()->Models()->find('Shopware\Models\Country\Country', $user->getCountryId());
}

//set sandbox mode based on config
$sandbox = false;
if('DE' === $country->getIso()) {
$sandbox = $this->_config->get('RatePaySandboxDE');
} elseif ('AT' === $country->getIso()) {
$sandbox = $this->_config->get('RatePaySandboxAT');
}
$sandbox = $this->_config->get('RatePaySandbox' . $country->getIso());

$this->_service = new Shopware_Plugins_Frontend_RpayRatePay_Component_Service_RequestService($sandbox);

@@ -115,33 +113,74 @@ public function saveUserDataAction()

$customerModel = Shopware()->Models()->getRepository('Shopware\Models\Customer\Customer');
$userModel = $customerModel->findOneBy(array('id' => Shopware()->Session()->sUserId));
$user = $userModel->getBilling();

$return = 'OK';
$updateData = array();

if (!is_null($user)) {
$updateData['phone'] = $Parameter['ratepay_phone'] ? : $user->getPhone();
if ($user->getCompany() !== "") {
$updateData['company'] = $Parameter['ratepay_company'] ? : $user->getCompany();
$updateData['ustid'] = $Parameter['ratepay_ustid'] ? : $user->getVatId();
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');
$customerAddressBilling = $addressModel->findOneBy(array('id' => $Parameter['checkoutBillingAddressId']));
Shopware()->Session()->RatePAY['checkoutBillingAddressId'] = $Parameter['checkoutBillingAddressId'];
if (isset($Parameter['checkoutShippingAddressId']) && !is_null($Parameter['checkoutShippingAddressId'])) {
Shopware()->Session()->RatePAY['checkoutShippingAddressId'] = $Parameter['checkoutShippingAddressId'];
} else {
$updateData['birthday'] = $Parameter['ratepay_dob'] ? : $user->getBirthday()->format("Y-m-d");
unset(Shopware()->Session()->RatePAY['checkoutShippingAddressId']);
}
} else {
$customerAddressBilling = $userModel->getBilling();
}

$return = 'OK';
$updateUserData = array();
$updateAddressData = array();

if (!is_null($customerAddressBilling)) {
if (method_exists($customerAddressBilling, 'getBirthday')) {
$updateAddressData['phone'] = $Parameter['ratepay_phone'] ? : $customerAddressBilling->getPhone();
if ($customerAddressBilling->getCompany() !== "") {
$updateAddressData['company'] = $Parameter['ratepay_company'] ? : $customerAddressBilling->getCompany();
$updateAddressData['ustid'] = $Parameter['ratepay_ustid'] ? : $customerAddressBilling->getVatId();
} else {
$updateAddressData['birthday'] = $Parameter['ratepay_dob'] ? : $customerAddressBilling->getBirthday()->format("Y-m-d");
}

try {
Shopware()->Db()->update('s_user_billingaddress', $updateAddressData, 'userID=' . $Parameter['userid']); // ToDo: Why parameter?
Shopware()->Pluginlogger()->info('Kundendaten aktualisiert.');
} catch (Exception $exception) {
Shopware()->Pluginlogger()->error('Fehler beim Updaten der Userdaten: ' . $exception->getMessage());
$return = 'NOK';
}

} elseif (method_exists($userModel, 'getBirthday')) { // From Shopware 5.2 birthday is moved to customer object
$updateAddressData['phone'] = $Parameter['ratepay_phone'] ? : $customerAddressBilling->getPhone();
if (!is_null($customerAddressBilling->getCompany())) {
$updateAddressData['company'] = $Parameter['ratepay_company'] ? : $customerAddressBilling->getCompany();
$updateAddressData['ustid'] = $Parameter['ratepay_ustid'] ? : $customerAddressBilling->getVatId();
} else {
$updateUserData['birthday'] = $Parameter['ratepay_dob'] ? : $userModel->getBirthday()->format("Y-m-d");
}

try {
Shopware()->Db()->update('s_user_billingaddress', $updateData, 'userID=' . $Parameter['userid']);
Shopware()->Pluginlogger()->info('Kundendaten aktualisiert.');
} catch (Exception $exception) {
Shopware()->Pluginlogger()->error('Fehler beim Updaten der Userdaten: ' . $exception->getMessage());
try {
if (count($updateUserData) > 0) {
Shopware()->Db()->update('s_user', $updateUserData, 'id=' . $Parameter['userid']); // ToDo: Why parameter?
}
if (count($updateAddressData) > 0) {
Shopware()->Db()->update('s_user_addresses', $updateAddressData, 'id=' . $Parameter['checkoutBillingAddressId']);
}
Shopware()->Pluginlogger()->info('Kundendaten aktualisiert.');
} catch (Exception $exception) {
Shopware()->Pluginlogger()->error('Fehler beim Updaten der User oder Address daten: ' . $exception->getMessage());
$return = 'NOK';
}
} else {
$return = 'NOK';
}


}

if ($Parameter['ratepay_debit_updatedebitdata']) {
Shopware()->Session()->RatePAY['bankdata']['account'] = $Parameter['ratepay_debit_accountnumber'];
Shopware()->Session()->RatePAY['bankdata']['bankcode'] = $Parameter['ratepay_debit_bankcode'];
Shopware()->Session()->RatePAY['bankdata']['bankholder'] = $user->getFirstname() . " " . $user->getLastname();
Shopware()->Session()->RatePAY['bankdata']['bankholder'] = $customerAddressBilling->getFirstname() . " " . $customerAddressBilling->getLastname();
}

echo $return;
@@ -24,6 +24,7 @@ Ext.define('Shopware.apps.Order.view.detail.ratepaydetailorder', {
if (me.isRatePAYOrder()) {
tabPanel = me.createRatePAYTabPanel();
}

return tabPanel;
},
isRatePAYOrder: function () {
@@ -169,8 +169,21 @@
errorMessage = errorMessageValidPhone;
}
}

if($('#ratepay_debit_accountnumber').length) { /* only do the check if bankdata form exists */

/* check for address editor, only shopware >=5.2.0 */
if($(".btn[data-address-editor]").length) {
if($(".btn[data-sessionkey='checkoutBillingAddressId,checkoutShippingAddressId']").length) {
requestParams += '&checkoutBillingAddressId=' + $(".btn[data-sessionkey='checkoutBillingAddressId,checkoutShippingAddressId']").attr("data-id");
differentAddress = false;
} else {
requestParams += '&checkoutBillingAddressId=' + $(".btn[data-sessionkey='checkoutBillingAddressId']").attr("data-id");
requestParams += '&checkoutShippingAddressId=' + $(".btn[data-sessionkey='checkoutShippingAddressId']").attr("data-id");
differentAddress = true;
}
}

/* only do the check if bankdata form exists */
if($('#ratepay_debit_accountnumber').length) {
if ($('#ratepay_debit_accountnumber').val() == '' || $('#ratepay_debit_accountholder').val() == '') {
error = true;
userUpdate = false;
@@ -25,7 +25,7 @@
<option value="">{s namespace=RatePAY name=dob_day}Tag{/s}</option>
{section name="birthdate" start=1 loop=32 step=1}
<option value="{if $smarty.section.birthdate.index < 10}0{$smarty.section.birthdate.index}{else}{$smarty.section.birthdate.index}{/if}"
{if $smarty.section.birthdate.index eq $sUserData.billingaddress.birthday|date_format:"%e"}selected{/if}>{$smarty.section.birthdate.index}</option>
{if $smarty.section.birthdate.index eq $sUserData.billingaddress.birthday|date_format:"%e" or $smarty.section.birthdate.index eq $sUserData.additional.user.birthday|date_format:"%e"}selected{/if}>{$smarty.section.birthdate.index}</option>
{/section}
</select>
</div>
@@ -35,7 +35,7 @@
<option value="">{s namespace=RatePAY name=dob_month}Monat{/s}</option>
{section name="birthmonth" start=1 loop=13 step=1}
<option value="{if $smarty.section.birthmonth.index < 10}0{$smarty.section.birthmonth.index}{else}{$smarty.section.birthmonth.index}{/if}"
{if $smarty.section.birthmonth.index eq $sUserData.billingaddress.birthday|date_format:"%m"}selected{/if}>{$smarty.section.birthmonth.index}</option>
{if $smarty.section.birthmonth.index eq $sUserData.billingaddress.birthday|date_format:"%m" or $smarty.section.birthmonth.index eq $sUserData.additional.user.birthday|date_format:"%m"}selected{/if}>{$smarty.section.birthmonth.index}</option>
{/section}
</select>
</div>
@@ -45,7 +45,7 @@
<option value="">{s namespace=RatePAY name=dob_year}Jahr{/s}</option>
{section name="birthyear" start=$smarty.now|date_format:"%Y"-18 loop=2000 max=100 step=-1}
<option value="{$smarty.section.birthyear.index}"
{if $smarty.section.birthyear.index eq $sUserData.billingaddress.birthday|date_format:"%Y"}selected{/if}>{$smarty.section.birthyear.index}</option>
{if $smarty.section.birthyear.index eq $sUserData.billingaddress.birthday|date_format:"%Y" or $smarty.section.birthyear.index eq $sUserData.additional.user.birthday|date_format:"%Y"}selected{/if}>{$smarty.section.birthyear.index}</option>
{/section}
</select>
</div>
@@ -58,6 +58,6 @@
{* Phone *}
{block name='ratepay_frontend_phone'}
<div class="register--phone">
<input id="ratepay_phone" name="ratepay_phone" class="register--field is--required" type="text" required="required" aria-required="true" placeholder="{s namespace=RatePAY name=phone}Telefonnummer{/s}*" value="{if $sUserData.billingaddress.phone}{$sUserData.billingaddress.phone|escape}{/if}">
<input id="ratepay_phone" name="ratepay_phone" class="register--field is--required" type="text" required="required" aria-required="true" placeholder="{s namespace=RatePAY name=phone}Telefonnummer{/s}*" value="{if $ratepayPhone}{$ratepayPhone}{else}{$sUserData.billingaddress.phone|escape}{/if}">
</div>
{/block}
{/block}