/** * {@inheritdoc} */ public function canView(\Magento\Sales\Model\Order $order) { $customerId = $this->customerSession->getCustomerId(); $availableStatuses = $this->orderConfig->getVisibleOnFrontStatuses(); if ($order->getId() && $order->getCustomerId() && $order->getCustomerId() == $customerId && in_array($order->getStatus(), $availableStatuses, true)) { return true; } return false; }
/** * Initialize creation data from existing order * * @param \Magento\Sales\Model\Order $order * @return $this * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function initFromOrder(\Magento\Sales\Model\Order $order) { $session = $this->getSession(); $session->setData($order->getReordered() ? 'reordered' : 'order_id', $order->getId()); $session->setCurrencyId($order->getOrderCurrencyCode()); /* Check if we edit guest order */ $session->setCustomerId($order->getCustomerId() ?: false); $session->setStoreId($order->getStoreId()); /* Initialize catalog rule data with new session values */ $this->initRuleData(); foreach ($order->getItemsCollection($this->_salesConfig->getAvailableProductTypes(), true) as $orderItem) { /* @var $orderItem \Magento\Sales\Model\Order\Item */ if (!$orderItem->getParentItem()) { $qty = $orderItem->getQtyOrdered(); if (!$order->getReordered()) { $qty -= max($orderItem->getQtyShipped(), $orderItem->getQtyInvoiced()); } if ($qty > 0) { $item = $this->initFromOrderItem($orderItem, $qty); if (is_string($item)) { throw new \Magento\Framework\Exception\LocalizedException(__($item)); } } } } $shippingAddress = $order->getShippingAddress(); if ($shippingAddress) { $addressDiff = array_diff_assoc($shippingAddress->getData(), $order->getBillingAddress()->getData()); unset($addressDiff['address_type'], $addressDiff['entity_id']); $shippingAddress->setSameAsBilling(empty($addressDiff)); } $this->_initBillingAddressFromOrder($order); $this->_initShippingAddressFromOrder($order); $quote = $this->getQuote(); if (!$quote->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) { $this->setShippingAsBilling(1); } $this->setShippingMethod($order->getShippingMethod()); $quote->getShippingAddress()->setShippingDescription($order->getShippingDescription()); $paymentData = $order->getPayment()->getData(); unset($paymentData['cc_type'], $paymentData['cc_last_4']); unset($paymentData['cc_exp_month'], $paymentData['cc_exp_year']); $quote->getPayment()->addData($paymentData); $orderCouponCode = $order->getCouponCode(); if ($orderCouponCode) { $quote->setCouponCode($orderCouponCode); } if ($quote->getCouponCode()) { $quote->collectTotals(); } $this->_objectCopyService->copyFieldsetToTarget('sales_copy_order', 'to_edit', $order, $quote); $this->_eventManager->dispatch('sales_convert_order_to_quote', ['order' => $order, 'quote' => $quote]); if (!$order->getCustomerId()) { $quote->setCustomerIsGuest(true); } if ($session->getUseOldShippingMethod(true)) { /* * if we are making reorder or editing old order * we need to show old shipping as preselected * so for this we need to collect shipping rates */ $this->collectShippingRates(); } else { /* * if we are creating new order then we don't need to collect * shipping rates before customer hit appropriate button */ $this->collectRates(); } $this->quoteRepository->save($quote); return $this; }
/** * @param \Magento\Sales\Model\Order $order * @return bool */ public function validateCustomer(\Magento\Sales\Model\Order $order) { return $order->getCustomerId() === $this->customerSession->getCustomerId(); }
/** Construct a user account blob * @param $order Order * @return UserAccount */ protected function makeUserAccount(Order $order) { /* @var $user \Signifyd\Models\UserAccount */ $user = SignifydModel::Make("\\Signifyd\\Models\\UserAccount"); $user->emailAddress = $order->getCustomerEmail(); $user->username = $order->getCustomerEmail(); $user->accountNumber = $order->getCustomerId(); $user->phone = $order->getBillingAddress()->getTelephone(); /* @var $customer \Magento\Customer\Model\Customer */ $customer = $this->_objectManager->get('Magento\\Customer\\Model\\Customer')->load($order->getCustomerId()); $this->_logger->debug("Customer data: " . json_encode($customer)); if (!is_null($customer) && !$customer->isEmpty()) { $user->createdDate = date('c', strtotime($customer->getCreatedAt())); } /** @var $orderFactory \Magento\Sales\Model\ResourceModel\Order\Collection */ $orders = $this->_objectManager->get('\\Magento\\Sales\\Model\\ResourceModel\\Order\\Collection'); $orders->addFieldToFilter('customer_id', $order->getCustomerId()); $orders->load(); $orderCount = 0; $orderTotal = 0.0; /** @var $o \Magento\Sales\Model\Order*/ foreach ($orders as $o) { $orderCount++; $orderTotal += floatval($o->getGrandTotal()); } $user->aggregateOrderCount = $orderCount; $user->aggregateOrderDollars = $orderTotal; return $user; }
/** * Checks if order is allowed for current customer * * @param \Magento\Sales\Model\Order $order * @return bool */ protected function isAllowed(\Magento\Sales\Model\Order $order) { return $this->userContext->getUserType() == UserContextInterface::USER_TYPE_CUSTOMER ? $order->getCustomerId() == $this->userContext->getUserId() : true; }
/** * Retrieve order status url key * * @param \Magento\Sales\Model\Order $order * @return string */ public function getStatusUrlKey($order) { $data = array('order_id' => $order->getId(), 'increment_id' => $order->getIncrementId(), 'customer_id' => $order->getCustomerId()); return base64_encode(json_encode($data)); }
/** Construct a user account blob * @param $order Order * @return array An array formatted for Signifyd */ private function makeUserAccount(Order $order) { return array("emailAddress" => $order->getCustomerEmail(), "accountNumber" => $order->getCustomerId(), "phone" => $order->getBillingAddress()->getTelephone()); }
/** * Retrieve order status url key * * @param \Magento\Sales\Model\Order $order * @return string */ protected function getUrlKey($order) { $data = ['order_id' => $order->getId(), 'increment_id' => $order->getIncrementId(), 'customer_id' => $order->getCustomerId()]; return base64_encode(json_encode($data)); }
/** * Returns customer ID * * @return int|null */ public function getCustomerId() { return $this->order->getCustomerId(); }
/** * @return array */ public function getFormFields() { $formFields = []; try { if ($this->_order->getPayment()) { $realOrderId = $this->_order->getRealOrderId(); $orderCurrencyCode = $this->_order->getOrderCurrencyCode(); $skinCode = trim($this->_adyenHelper->getAdyenHppConfigData('skin_code')); $amount = $this->_adyenHelper->formatAmount($this->_order->getGrandTotal(), $orderCurrencyCode); $merchantAccount = trim($this->_adyenHelper->getAdyenAbstractConfigData('merchant_account')); $shopperEmail = $this->_order->getCustomerEmail(); $customerId = $this->_order->getCustomerId(); $shopperIP = $this->_order->getRemoteIp(); $browserInfo = $_SERVER['HTTP_USER_AGENT']; $deliveryDays = $this->_adyenHelper->getAdyenHppConfigData('delivery_days'); $shopperLocale = trim($this->_adyenHelper->getAdyenHppConfigData('shopper_locale')); $shopperLocale = !empty($shopperLocale) ? $shopperLocale : $this->_resolver->getLocale(); $countryCode = trim($this->_adyenHelper->getAdyenHppConfigData('country_code')); $countryCode = !empty($countryCode) ? $countryCode : false; // if directory lookup is enabled use the billingadress as countrycode if ($countryCode == false) { if ($this->_order->getBillingAddress() && $this->_order->getBillingAddress()->getCountryId() != "") { $countryCode = $this->_order->getBillingAddress()->getCountryId(); } } $formFields = []; $formFields['merchantAccount'] = $merchantAccount; $formFields['merchantReference'] = $realOrderId; $formFields['paymentAmount'] = (int) $amount; $formFields['currencyCode'] = $orderCurrencyCode; $formFields['shipBeforeDate'] = date("Y-m-d", mktime(date("H"), date("i"), date("s"), date("m"), date("j") + $deliveryDays, date("Y"))); $formFields['skinCode'] = $skinCode; $formFields['shopperLocale'] = $shopperLocale; $formFields['countryCode'] = $countryCode; $formFields['shopperIP'] = $shopperIP; $formFields['browserInfo'] = $browserInfo; $formFields['sessionValidity'] = date(DATE_ATOM, mktime(date("H") + 1, date("i"), date("s"), date("m"), date("j"), date("Y"))); $formFields['shopperEmail'] = $shopperEmail; // recurring $recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData('recurring_type')); $brandCode = $this->_order->getPayment()->getAdditionalInformation("brand_code"); // Paypal does not allow ONECLICK,RECURRING only RECURRING if ($brandCode == "paypal" && $recurringType == 'ONECLICK,RECURRING') { $recurringType = "RECURRING"; } $formFields['recurringContract'] = $recurringType; $formFields['shopperReference'] = !empty($customerId) ? $customerId : self::GUEST_ID . $realOrderId; //blocked methods $formFields['blockedMethods'] = ""; $baseUrl = $this->_storeManager->getStore($this->getStore())->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK); $formFields['resURL'] = $baseUrl . 'adyen/process/result'; $hmacKey = $this->_adyenHelper->getHmac(); if ($brandCode) { $formFields['brandCode'] = $brandCode; } $issuerId = $this->_order->getPayment()->getAdditionalInformation("issuer_id"); if ($issuerId) { $formFields['issuerId'] = $issuerId; } $formFields = $this->setBillingAddressData($formFields); $formFields = $this->setShippingAddressData($formFields); $formFields = $this->setOpenInvoiceData($formFields); $formFields['shopper.gender'] = $this->getGenderText($this->_order->getCustomerGender()); $dob = $this->_order->getCustomerDob(); if ($dob) { $formFields['shopper.dateOfBirthDayOfMonth'] = trim($this->_getDate($dob, 'd')); $formFields['shopper.dateOfBirthMonth'] = trim($this->_getDate($dob, 'm')); $formFields['shopper.dateOfBirthYear'] = trim($this->_getDate($dob, 'Y')); } if ($this->_order->getPayment()->getAdditionalInformation(\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE) == "klarna") { // // needed for DE and AT $formFields['klarna.acceptPrivacyPolicy'] = 'true'; // don't allow editable shipping/delivery address $formFields['billingAddressType'] = "1"; $formFields['deliveryAddressType'] = "1"; // make setting to make this optional $adyFields['shopperType'] = "1"; } // Sort the array by key using SORT_STRING order ksort($formFields, SORT_STRING); // Generate the signing data string $signData = implode(":", array_map([$this, 'escapeString'], array_merge(array_keys($formFields), array_values($formFields)))); $merchantSig = base64_encode(hash_hmac('sha256', $signData, pack("H*", $hmacKey), true)); $formFields['merchantSig'] = $merchantSig; $this->_adyenLogger->addAdyenDebug(print_r($formFields, true)); } } catch (Exception $e) { // do nothing for now } return $formFields; }