/**
  * Add the given Items to the given order
  */
 public function addAction()
 {
     $orderId = $this->Request()->getParam("orderId");
     $insertedIds = json_decode($this->Request()->getParam("insertedIds"));
     $subOperation = $this->Request()->getParam("suboperation");
     $order = Shopware()->Db()->fetchRow("SELECT * FROM `s_order` WHERE `id`=?", array($orderId));
     $orderItems = Shopware()->Db()->fetchAll("SELECT *, (`quantity` - `delivered` - `cancelled`) AS `quantityDeliver` FROM `s_order_details` " . "INNER JOIN `rpay_ratepay_order_positions` ON `s_order_details`.`id` = `rpay_ratepay_order_positions`.`s_order_details_id` " . "WHERE `orderID`=?", array($orderId));
     $basketItems = array();
     foreach ($orderItems as $row) {
         if ($row['quantityDeliver'] == 0) {
             continue;
         }
         $basketItem = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_item();
         $basketItem->setArticleName($row['name']);
         $basketItem->setArticleNumber($row['articleordernumber']);
         $basketItem->setQuantity($row['quantityDeliver']);
         $basketItem->setTaxRate($row['tax_rate']);
         $basketItem->setUnitPriceGross($row['price']);
         $basketItems[] = $basketItem;
     }
     $shippingRow = $this->getShippingFromDBAsItem($orderId);
     if (!is_null($shippingRow) && $shippingRow['quantityDeliver'] != 0) {
         $basketItem = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_item();
         $basketItem->setArticleName($shippingRow['name']);
         $basketItem->setArticleNumber($shippingRow['articleordernumber']);
         $basketItem->setQuantity($shippingRow['quantityDeliver']);
         $basketItem->setTaxRate($shippingRow['tax_rate']);
         $basketItem->setUnitPriceGross($shippingRow['price']);
         $basketItems[] = $basketItem;
     }
     $basket = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_ShoppingBasket();
     $basket->setAmount($this->getRecalculatedAmount($basketItems));
     $basket->setCurrency($order['currency']);
     $basket->setItems($basketItems);
     $this->_modelFactory->setTransactionId($order['transactionID']);
     $paymentChange = $this->_modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentChange(), $orderId);
     $head = $paymentChange->getHead();
     $head->setOperationSubstring($subOperation);
     $paymentChange->setHead($head);
     $paymentChange->setShoppingBasket($basket);
     $response = $this->_service->xmlRequest($paymentChange->toArray());
     $result = Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PAYMENT_CHANGE', $response);
     if ($result) {
         $event = $subOperation === 'credit' ? 'Nachlass wurde hinzugefügt' : 'Artikel wurde hinzugefügt';
         foreach ($insertedIds as $id) {
             $newItems = Shopware()->Db()->fetchRow("SELECT * FROM `s_order_details` WHERE `id`=?", array($id));
             if ($newItems['quantity'] <= 0) {
                 continue;
             }
             $this->_history->logHistory($orderId, $event, $newItems['name'], $newItems['articleordernumber'], $newItems['quantity']);
         }
     }
     $this->setNewOrderState($orderId);
     $this->View()->assign(array("result" => $result, "success" => true));
 }
예제 #2
0
 /**
  * Fills an object of the class Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentRequest
  *
  * @param Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentRequest $paymentRequestModel
  */
 private function fillPaymentRequest(Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentRequest &$paymentRequestModel)
 {
     $method = Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::getPaymentMethod(Shopware()->Session()->sOrderVariables['sUserData']['additional']['payment']['name']);
     $shopUser = Shopware()->Models()->find('Shopware\\Models\\Customer\\Customer', Shopware()->Session()->sUserId);
     // Checkout address ids are set in RP session from shopware version >=5.2.0
     if (isset(Shopware()->Session()->RatePAY['checkoutBillingAddressId']) && Shopware()->Session()->RatePAY['checkoutBillingAddressId'] > 0) {
         $addressModel = Shopware()->Models()->getRepository('Shopware\\Models\\Customer\\Address');
         $checkoutAddressBilling = $addressModel->findOneBy(array('id' => Shopware()->Session()->RatePAY['checkoutBillingAddressId']));
         $checkoutAddressShipping = $addressModel->findOneBy(array('id' => Shopware()->Session()->RatePAY['checkoutShippingAddressId'] ? Shopware()->Session()->RatePAY['checkoutShippingAddressId'] : Shopware()->Session()->RatePAY['checkoutBillingAddressId']));
         $countryCodeBilling = $checkoutAddressBilling->getCountry()->getIso();
         $countryCodeShipping = $checkoutAddressShipping->getCountry()->getIso();
         $company = $checkoutAddressBilling->getCompany();
         if (empty($company)) {
             $dateOfBirth = $shopUser->getBirthday()->format("Y-m-d");
             // From Shopware 5.2 date of birth has moved to customer object
         }
         $merchantCustomerId = $shopUser->getNumber();
         // From Shopware 5.2 billing number has moved to customer object
     } else {
         $checkoutAddressBilling = $shopUser->getBilling();
         $checkoutAddressShipping = $shopUser->getShipping() !== null ? $shopUser->getShipping() : $shopUser->getBilling();
         $countryBilling = Shopware()->Models()->find('Shopware\\Models\\Country\\Country', $checkoutAddressBilling->getCountryId());
         $countryCodeBilling = $countryBilling->getIso();
         $countryShipping = Shopware()->Models()->find('Shopware\\Models\\Country\\Country', $checkoutAddressShipping->getCountryId());
         $countryCodeShipping = $countryShipping->getIso();
         $company = $checkoutAddressBilling->getCompany();
         if (!empty($company)) {
             $dateOfBirth = $shopUser->getBilling()->getBirthday()->format("Y-m-d");
         }
         $merchantCustomerId = $shopUser->getBilling()->getNumber();
     }
     $head = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_Head();
     $head->setTransactionId(Shopware()->Session()->RatePAY['transactionId']);
     $head->setOperation('PAYMENT_REQUEST');
     $head->setProfileId($this->getProfileId());
     $head->setSecurityCode($this->getSecurityCode());
     $head->setSystemId(Shopware()->Shop()->getHost() ?: $_SERVER['SERVER_ADDR']);
     $head->setSystemVersion($this->_getVersion());
     $head->setOrderId($this->_getOrderIdFromTransactionId());
     $head->setMerchantConsumerId($merchantCustomerId);
     //set device ident token if available
     if (Shopware()->Session()->RatePAY['dfpToken']) {
         $head->setDeviceToken(Shopware()->Session()->RatePAY['dfpToken']);
     }
     $customer = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_Customer();
     // only for elv and sepa elv
     if ($method === 'ELV') {
         $bankAccount = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_BankAccount();
         $bankAccount->setBankAccount(Shopware()->Session()->RatePAY['bankdata']['account']);
         $bankAccount->setBankCode(Shopware()->Session()->RatePAY['bankdata']['bankcode']);
         $bankAccount->setOwner(Shopware()->Session()->RatePAY['bankdata']['bankholder']);
         $customer->setBankAccount($bankAccount);
     }
     $customer->setFirstName($checkoutAddressBilling->getFirstName());
     $customer->setLastName($checkoutAddressBilling->getLastName());
     $customer->setEmail($shopUser->getEmail());
     if (!empty($company)) {
         $customer->setCompanyName($checkoutAddressBilling->getCompany());
         $customer->setVatId($checkoutAddressBilling->getVatId());
     } else {
         $customer->setDateOfBirth($dateOfBirth);
     }
     /**
      * set gender and salutation based on the given billingaddress salutation
      */
     $gender = 'U';
     if ($checkoutAddressBilling->getSalutation() === 'mr') {
         $gender = 'M';
         $customer->setSalutation('Herr');
     } elseif ($checkoutAddressBilling->getSalutation() === 'ms') {
         $gender = 'F';
         $customer->setSalutation('Frau');
     } else {
         $customer->setSalutation($checkoutAddressBilling->getSalutation());
     }
     $customer->setGender($gender);
     $customer->setPhone($checkoutAddressBilling->getPhone());
     $customer->setNationality($this->_countryCode);
     $customer->setIpAddress($this->_getCustomerIP());
     $customer->setBillingAddresses($this->_getCheckoutAddress($checkoutAddressBilling, 'BILLING', $countryCodeBilling));
     $customer->setShippingAddresses($this->_getCheckoutAddress($checkoutAddressShipping, 'DELIVERY', $countryCodeShipping));
     $payment = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_Payment();
     $payment->setAmount($this->getAmount());
     $payment->setCurrency(Shopware()->Currency()->getShortName());
     $payment->setMethod($method);
     if ($method === 'INSTALLMENT') {
         $payment->setAmount(Shopware()->Session()->RatePAY['ratenrechner']['total_amount']);
         $payment->setDirectPayType('BANK-TRANSFER');
         $payment->setInstallmentAmount(Shopware()->Session()->RatePAY['ratenrechner']['rate']);
         $payment->setInstallmentNumber(Shopware()->Session()->RatePAY['ratenrechner']['number_of_rates']);
         $payment->setInterestRate(Shopware()->Session()->RatePAY['ratenrechner']['interest_rate']);
         $payment->setLastInstallmentAmount(Shopware()->Session()->RatePAY['ratenrechner']['last_rate']);
     }
     $basket = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_ShoppingBasket();
     $basket->setAmount($this->getAmount());
     $basket->setCurrency(Shopware()->Currency()->getShortName());
     $shopItems = Shopware()->Session()->sOrderVariables['sBasket']['content'];
     $items = array();
     foreach ($shopItems as $shopItem) {
         $item = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_item();
         $item->setArticleName($shopItem['articlename']);
         $item->setArticleNumber($shopItem['ordernumber']);
         $item->setQuantity($shopItem['quantity']);
         $item->setTaxRate($shopItem['tax_rate']);
         $item->setUnitPriceGross($shopItem['priceNumeric']);
         $items[] = $item;
     }
     if (Shopware()->Session()->sOrderVariables['sBasket']['sShippingcosts'] > 0) {
         $items[] = $this->getShippingAsItem(Shopware()->Session()->sOrderVariables['sBasket']['sShippingcosts'], Shopware()->Session()->sOrderVariables['sBasket']['sShippingcostsTax']);
     }
     $basket->setItems($items);
     $paymentRequestModel->setHead($head);
     $paymentRequestModel->setCustomer($customer);
     $paymentRequestModel->setPayment($payment);
     $paymentRequestModel->setShoppingBasket($basket);
 }
예제 #3
0
 /**
  * Stops Orderdeletation, when any article has been send
  *
  * @param Enlight_Hook_HookArgs $arguments
  */
 public function beforeDeleteOrder(Enlight_Hook_HookArgs $arguments)
 {
     $request = $arguments->getSubject()->Request();
     $parameter = $request->getParams();
     if (!in_array($parameter['payment'][0]['name'], array("rpayratepayinvoice", "rpayratepayrate", "rpayratepaydebit"))) {
         return false;
     }
     $sql = "SELECT COUNT(*) FROM `s_order_details` AS `detail` " . "INNER JOIN `rpay_ratepay_order_positions` AS `position` " . "ON `position`.`s_order_details_id` = `detail`.`id` " . "WHERE `detail`.`orderID`=? AND " . "(`position`.`delivered` > 0 OR `position`.`cancelled` > 0 OR `position`.`returned` > 0)";
     $count = Shopware()->Db()->fetchOne($sql, array($parameter['id']));
     if ($count > 0) {
         Shopware()->Pluginlogger()->warning('RatePAY-Bestellung k&ouml;nnen nicht gelöscht werden, wenn sie bereits bearbeitet worden sind.');
         $arguments->stop();
     } else {
         $config = Shopware()->Plugins()->Frontend()->RpayRatePay()->Config();
         $request = new Shopware_Plugins_Frontend_RpayRatePay_Component_Service_RequestService($config->get('RatePaySandbox'));
         $modelFactory = new Shopware_Plugins_Frontend_RpayRatePay_Component_Mapper_ModelFactory();
         $modelFactory->setTransactionId($parameter['transactionId']);
         $paymentChange = $modelFactory->getModel(new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_PaymentChange());
         $head = $paymentChange->getHead();
         $head->setOperationSubstring('full-cancellation');
         $paymentChange->setHead($head);
         $basket = new Shopware_Plugins_Frontend_RpayRatePay_Component_Model_SubModel_ShoppingBasket();
         $basket->setAmount(0);
         $basket->setCurrency($parameter['currency']);
         $paymentChange->setShoppingBasket($basket);
         $response = $request->xmlRequest($paymentChange->toArray());
         $result = Shopware_Plugins_Frontend_RpayRatePay_Component_Service_Util::validateResponse('PAYMENT_CHANGE', $response);
         if (!$result) {
             Shopware()->Pluginlogger()->warning('Bestellung k&ouml;nnte nicht gelöscht werden, da die Stornierung bei RatePAY fehlgeschlagen ist.');
             $arguments->stop();
         }
     }
 }