Ejemplo n.º 1
0
 public function afterGetOrders(\Magento\Sales\Block\Order\History $subject, $result)
 {
     $old = $this->_oldCollectionFactory->create();
     $blank = $this->_blankCollectionFactory->create();
     //$this->_logger->debug(print_r($blank->getAllIds(), true));
     // add orders from new website to blank collection , first
     foreach ($result as $new) {
         $blank->addItem($new);
     }
     // add orders from old website to blank collection
     foreach ($old as $o) {
         //$this->_logger->debug(print_r($o->getData(), true));
         $clone = $this->orderFactory->create();
         $clone->setId($o->getOrderId());
         $clone->setStatus(trim($o->getStatus()));
         $clone->setState(trim($o->getState()));
         $clone->setOrderId($o->getOrderId());
         $clone->setRealOrderId($o->getIncrementId());
         $clone->setCustomerId($o->getCustomerId());
         $clone->setIsFromImport(1);
         $blank->addItem($clone);
     }
     foreach ($blank as $b) {
         //$this->_logger->debug(print_r($b->getData(), true));
     }
     //$this->_logger->debug(print_r($blank->getAllIds(), true));
     return $blank;
 }
 /**
  * {@inheritDoc}
  */
 public function save($orderId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage)
 {
     /** @var \Magento\Sales\Api\Data\OrderInterface $order */
     $order = $this->orderFactory->create()->load($orderId);
     if (!$order->getEntityId()) {
         throw new NoSuchEntityException(__('There is no order with provided id'));
     }
     if (0 == $order->getTotalItemCount()) {
         throw new InputException(__('Gift Messages is not applicable for empty order'));
     }
     if ($order->getIsVirtual()) {
         throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
     }
     if (!$this->helper->isMessagesAllowed('order', $order, $this->storeManager->getStore())) {
         throw new CouldNotSaveException(__('Gift Message is not available'));
     }
     $message = [];
     $message[$orderId] = ['type' => 'order', $giftMessage::CUSTOMER_ID => $giftMessage->getCustomerId(), $giftMessage::SENDER => $giftMessage->getSender(), $giftMessage::RECIPIENT => $giftMessage->getRecipient(), $giftMessage::MESSAGE => $giftMessage->getMessage()];
     $this->giftMessageSaveModel->setGiftmessages($message);
     try {
         $this->giftMessageSaveModel->saveAllInOrder();
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not add gift message to order: "%1"', $e->getMessage()), $e);
     }
     return true;
 }
Ejemplo n.º 3
0
 private function _reorder($orderId)
 {
     /** @var \Magento\Sales\Model\Order $order */
     $order = $this->_orderFactory->create()->loadByIncrementId($orderId);
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     /* @var $cart \Magento\Checkout\Model\Cart */
     $cart = $this->_objectManager->get('Magento\\Checkout\\Model\\Cart');
     $cart->truncate();
     $items = $order->getItemsCollection();
     foreach ($items as $item) {
         try {
             $cart->addOrderItem($item);
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             if ($this->_objectManager->get('Magento\\Checkout\\Model\\Session')->getUseNotice(true)) {
                 $this->messageManager->addNotice($e->getMessage());
             } else {
                 $this->messageManager->addError($e->getMessage());
             }
             return $resultRedirect->setPath('*/*/history');
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('We can\'t add this item to your shopping cart right now.'));
             return $resultRedirect->setPath('checkout/cart');
         }
     }
     $cart->save();
     return $resultRedirect->setPath('checkout/cart');
 }
Ejemplo n.º 4
0
 /**
  * Return order instance loaded by increment id
  *
  * @return Order
  */
 protected function _getOrder()
 {
     if (empty($this->_order)) {
         $orderId = $this->getRequest()->getParam('orderID');
         $this->_order = $this->_salesOrderFactory->create()->loadByIncrementId($orderId);
     }
     return $this->_order;
 }
Ejemplo n.º 5
0
 protected function _getOrder($incrementId = null)
 {
     if (!$this->_order) {
         $incrementId = $incrementId ? $incrementId : $this->_getCheckout()->getLastRealOrderId();
         $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
     }
     return $this->_order;
 }
Ejemplo n.º 6
0
 /**
  * Record order shipping information after order is placed
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if ($this->shipperDataHelper->getConfigValue('carriers/shipper/active')) {
         $order = $this->orderFactory->create()->loadByIncrementId($this->checkoutSession->getLastRealOrderId());
         if ($order->getIncrementId()) {
             $this->recordOrder($order);
         }
     }
 }
Ejemplo n.º 7
0
 public function testGetSuccessOrderUrl()
 {
     $order = $this->getMock('Magento\\Sales\\Model\\Order', array('loadByIncrementId', 'getId', '__wakeup'), array(), '', false);
     $order->expects($this->once())->method('loadByIncrementId')->with('invoice number')->will($this->returnSelf());
     $order->expects($this->once())->method('getId')->will($this->returnValue('order id'));
     $this->_orderFactory->expects($this->once())->method('create')->will($this->returnValue($order));
     $this->_urlBuilder->expects($this->once())->method('getUrl')->with($this->equalTo('sales/order/view'), $this->equalTo(array('order_id' => 'order id')))->will($this->returnValue('some value'));
     $this->assertEquals('some value', $this->_model->getSuccessOrderUrl(array('x_invoice_num' => 'invoice number', 'some param')));
 }
Ejemplo n.º 8
0
 /**
  * Get order object
  *
  * @return \Magento\Sales\Model\Order
  */
 protected function _getOrder()
 {
     if (!$this->_order) {
         $incrementId = $this->_getCheckout()->getLastRealOrderId();
         $this->_orderFactory = $this->_objectManager->get('Magento\\Sales\\Model\\OrderFactory');
         $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
     }
     return $this->_order;
 }
Ejemplo n.º 9
0
 public function testGetSuccessOrderUrl()
 {
     $orderMock = $this->getMock('Magento\\Sales\\Model\\Order', ['loadByIncrementId', 'getId', '__wakeup'], [], '', false);
     $orderMock->expects($this->once())->method('loadByIncrementId')->with('invoice number')->willReturnSelf();
     $orderMock->expects($this->once())->method('getId')->willReturn('order id');
     $this->orderFactoryMock->expects($this->once())->method('create')->willReturn($orderMock);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('sales/order/view', ['order_id' => 'order id'])->willReturn('some value');
     $this->assertEquals('some value', $this->dataHelper->getSuccessOrderUrl(['x_invoice_num' => 'invoice number', 'some param']));
 }
Ejemplo n.º 10
0
 /**
  * Return order instance with loaded information by increment id
  *
  * @return \Magento\Sales\Model\Order
  */
 protected function _getOrder()
 {
     if ($this->getOrder()) {
         $order = $this->getOrder();
     } elseif ($this->_checkoutSession->getLastRealOrderId()) {
         $order = $this->_salesOrderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
     } else {
         return null;
     }
     return $order;
 }
Ejemplo n.º 11
0
 public function setUp()
 {
     $objectManager = new ObjectManager($this);
     $this->order = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['load', '__wakeup'])->getMock();
     $this->orderFactory = $this->getMockBuilder('\\Magento\\Sales\\Model\\OrderFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->orderFactory->expects($this->once())->method('create')->will($this->returnValue($this->order));
     $this->orderItemTaxResource = $this->getMockBuilder('\\Magento\\Tax\\Model\\Resource\\Sales\\Order\\Tax\\Item')->disableOriginalConstructor()->setMethods(['getTaxItemsByOrderId', '__wakeup'])->getMock();
     $orderItemTaxFactory = $this->getMockBuilder('\\Magento\\Tax\\Model\\Resource\\Sales\\Order\\Tax\\ItemFactory')->disableOriginalConstructor()->setMethods(['create', '__wakeup'])->getMock();
     $orderItemTaxFactory->expects($this->once())->method('create')->will($this->returnValue($this->orderItemTaxResource));
     $this->ordertTaxService = $objectManager->getObject('Magento\\Tax\\Service\\V1\\OrderTaxService', ['orderFactory' => $this->orderFactory, 'orderItemTaxFactory' => $orderItemTaxFactory]);
 }
 /**
  * Get a collection of all products in the orders
  *
  * @param $ordersCollection
  * @return array
  */
 protected function _getCustomerProductCollection($ordersCollection)
 {
     $purchasedProducts = [];
     foreach ($ordersCollection as $order) {
         $order = $this->_orderFactory->create()->load($order['entity_id']);
         $itemCollection = $order->getItems();
         foreach ($itemCollection as $item) {
             $purchasedProducts[$order['customer_id']][] = $item->getProductId();
         }
     }
     $this->_productCollection = $purchasedProducts;
     return $purchasedProducts;
 }
Ejemplo n.º 13
0
 /**
  * Redirect constructor.
  *
  * @param \Magento\Framework\View\Element\Template\Context $context
  * @param array $data
  * @param \Magento\Sales\Model\OrderFactory $orderFactory
  * @param \Magento\Checkout\Model\Session $checkoutSession
  * @param \Adyen\Payment\Helper\Data $adyenHelper
  */
 public function __construct(\Magento\Framework\View\Element\Template\Context $context, array $data = [], \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Checkout\Model\Session $checkoutSession, \Adyen\Payment\Helper\Data $adyenHelper, \Magento\Framework\Locale\ResolverInterface $resolver, \Adyen\Payment\Logger\AdyenLogger $adyenLogger)
 {
     $this->_orderFactory = $orderFactory;
     $this->_checkoutSession = $checkoutSession;
     parent::__construct($context, $data);
     $this->_adyenHelper = $adyenHelper;
     $this->_resolver = $resolver;
     $this->_adyenLogger = $adyenLogger;
     if (!$this->_order) {
         $incrementId = $this->_getCheckout()->getLastRealOrderId();
         $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
     }
 }
Ejemplo n.º 14
0
 public function execute()
 {
     $skipFraudDetection = false;
     \Paynl\Config::setApiToken($this->_config->getApiToken());
     $params = $this->getRequest()->getParams();
     if (!isset($params['order_id'])) {
         $this->_logger->critical('Exchange: order_id is not set in the request', $params);
         return $this->_result->setContents('FALSE| order_id is not set in the request');
     }
     try {
         $transaction = \Paynl\Transaction::get($params['order_id']);
     } catch (\Exception $e) {
         $this->_logger->critical($e, $params);
         return $this->_result->setContents('FALSE| Error fetching transaction. ' . $e->getMessage());
     }
     if ($transaction->isPending()) {
         return $this->_result->setContents("TRUE| Ignoring pending");
     }
     $orderId = $transaction->getDescription();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderId);
     if (empty($order)) {
         $this->_logger->critical('Cannot load order: ' . $orderId);
         return $this->_result->setContents('FALSE| Cannot load order');
     }
     if ($order->getTotalDue() <= 0) {
         $this->_logger->debug('Total due <= 0, so iam not touching the status of the order: ' . $orderId);
         return $this->_result->setContents('TRUE| Total due <= 0, so iam not touching the status of the order');
     }
     if ($transaction->isPaid()) {
         $payment = $order->getPayment();
         $payment->setTransactionId($transaction->getId());
         $payment->setCurrencyCode($transaction->getPaidCurrency());
         $payment->setIsTransactionClosed(0);
         $payment->registerCaptureNotification($transaction->getPaidCurrencyAmount(), $skipFraudDetection);
         $order->save();
         // notify customer
         $invoice = $payment->getCreatedInvoice();
         if ($invoice && !$order->getEmailSent()) {
             $this->_orderSender->send($order);
             $order->addStatusHistoryComment(__('New order email sent'))->setIsCustomerNotified(true)->save();
         }
         if ($invoice && !$invoice->getEmailSent()) {
             $this->_invoiceSender->send($invoice);
             $order->addStatusHistoryComment(__('You notified customer about invoice #%1.', $invoice->getIncrementId()))->setIsCustomerNotified(true)->save();
         }
         return $this->_result->setContents("TRUE| PAID");
     } elseif ($transaction->isCanceled()) {
         $order->cancel()->save();
         return $this->_result->setContents("TRUE| CANCELED");
     }
 }
Ejemplo n.º 15
0
 /**
  * Record order shipping information after order is placed
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if ($this->shipperDataHelper->getConfigValue('carriers/shipper/active')) {
         $orderIds = $observer->getEvent()->getOrderIds();
         if (empty($orderIds) || !is_array($orderIds)) {
             return;
         }
         foreach ($orderIds as $orderId) {
             $order = $this->orderFactory->create()->loadByIncrementId($orderId);
             if ($order->getIncrementId()) {
                 $this->recordOrder($order);
             }
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * Prepares block data
  *
  * @return void
  */
 protected function prepareBlockData()
 {
     $s2p_transaction = $this->_s2pTransaction->create();
     $order = $this->_orderFactory->create();
     $module_settings = $this->_s2pModel->getFullConfigArray();
     $transaction_obj = false;
     $error_message = '';
     $merchant_transaction_id = 0;
     if (($status_code = $this->_helper->getParam('data', null)) === null) {
         $error_message = __('Transaction status not provided.');
     } elseif (!($merchant_transaction_id = $this->_helper->getParam('MerchantTransactionID', '')) or !($merchant_transaction_id = $this->_helper->convert_from_demo_merchant_transaction_id($merchant_transaction_id))) {
         $error_message = __('Couldn\'t extract transaction information.');
     } elseif (!$s2p_transaction->loadByMerchantTransactionId($merchant_transaction_id) or !$s2p_transaction->getID()) {
         $error_message = __('Transaction not found in database.');
     } elseif (!$order->loadByIncrementId($merchant_transaction_id) or !$order->getEntityId()) {
         $error_message = __('Order not found in database.');
     }
     $status_code = intval($status_code);
     if (empty($status_code)) {
         $status_code = Smart2Pay::S2P_STATUS_FAILED;
     }
     $transaction_extra_data = [];
     $transaction_details_titles = [];
     if (in_array($s2p_transaction->getMethodId(), [\Smart2Pay\GlobalPay\Model\Smart2Pay::PAYMENT_METHOD_BT, \Smart2Pay\GlobalPay\Model\Smart2Pay::PAYMENT_METHOD_SIBS])) {
         if ($transaction_details_titles = \Smart2Pay\GlobalPay\Helper\Smart2Pay::transaction_logger_params_to_title() and is_array($transaction_details_titles)) {
             if (!($all_params = $this->_helper->getParams())) {
                 $all_params = [];
             }
             foreach ($transaction_details_titles as $key => $title) {
                 if (!array_key_exists($key, $all_params)) {
                     continue;
                 }
                 $transaction_extra_data[$key] = $all_params[$key];
             }
         }
     }
     $result_message = __('Transaction status is unknown.');
     if (empty($error_message)) {
         //map all statuses to known Magento statuses (message_data_2, message_data_4, message_data_3 and message_data_7)
         $status_id_to_string = array(Smart2Pay::S2P_STATUS_OPEN => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_SUCCESS => Smart2Pay::S2P_STATUS_SUCCESS, Smart2Pay::S2P_STATUS_CANCELLED => Smart2Pay::S2P_STATUS_CANCELLED, Smart2Pay::S2P_STATUS_FAILED => Smart2Pay::S2P_STATUS_FAILED, Smart2Pay::S2P_STATUS_EXPIRED => Smart2Pay::S2P_STATUS_FAILED, Smart2Pay::S2P_STATUS_PENDING_CUSTOMER => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_PENDING_PROVIDER => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_SUBMITTED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_PROCESSING => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_AUTHORIZED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_APPROVED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_CAPTURED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_REJECTED => Smart2Pay::S2P_STATUS_FAILED, Smart2Pay::S2P_STATUS_PENDING_CAPTURE => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_EXCEPTION => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_PENDING_CANCEL => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_REVERSED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_COMPLETED => Smart2Pay::S2P_STATUS_SUCCESS, Smart2Pay::S2P_STATUS_PROCESSING => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_DISPUTED => Smart2Pay::S2P_STATUS_PENDING_PROVIDER, Smart2Pay::S2P_STATUS_CHARGEBACK => Smart2Pay::S2P_STATUS_PENDING_PROVIDER);
         if (isset($module_settings['message_data_' . $status_code])) {
             $result_message = $module_settings['message_data_' . $status_code];
         } elseif (!empty($status_id_to_string[$status_code]) and isset($module_settings['message_data_' . $status_id_to_string[$status_code]])) {
             $result_message = $module_settings['message_data_' . $status_id_to_string[$status_code]];
         }
     }
     $this->addData(['error_message' => $error_message, 'result_message' => $result_message, 'transaction_data' => $s2p_transaction->getData(), 'transaction_extra_data' => $transaction_extra_data, 'transaction_details_title' => $transaction_details_titles, 'is_order_visible' => $this->isVisible($order), 'view_order_url' => $this->getUrl('sales/order/view/', ['order_id' => $order->getEntityId()]), 'can_view_order' => $this->canViewOrder($order), 'order_id' => $order->getIncrementId()]);
 }
Ejemplo n.º 17
0
 /**
  * @param $incrementId
  * @return \Magento\Sales\Model\Order
  */
 protected function _getOrder($incrementId)
 {
     if (!$this->_order) {
         $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
     }
     return $this->_order;
 }
Ejemplo n.º 18
0
 private function initOrderMock($orderId, $state)
 {
     $this->orderFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->orderMock));
     $this->orderMock->expects($this->once())->method('loadByIncrementId')->with($orderId)->will($this->returnSelf());
     $this->orderMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($orderId));
     $this->orderMock->expects($this->once())->method('getState')->will($this->returnValue($state));
 }
 /**
  * Update new order default datafields.
  */
 public function _updateNewOrderDatafields()
 {
     $website = $this->storeManager->getWebsite($this->websiteId);
     $orderModel = $this->orderFactory->create()->load($this->typeId);
     //data fields
     if ($lastOrderId = $website->getConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_ID)) {
         $data[] = ['Key' => $lastOrderId, 'Value' => $orderModel->getId()];
     }
     if ($orderIncrementId = $website->getConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_INCREMENT_ID)) {
         $data[] = ['Key' => $orderIncrementId, 'Value' => $orderModel->getIncrementId()];
     }
     if ($storeName = $website->getConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CUSTOMER_STORE_NAME)) {
         $data[] = ['Key' => $storeName, 'Value' => $this->storeName];
     }
     if ($websiteName = $website->getConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CUSTOMER_WEBSITE_NAME)) {
         $data[] = ['Key' => $websiteName, 'Value' => $website->getName()];
     }
     if ($lastOrderDate = $website->getConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CUSTOMER_LAST_ORDER_DATE)) {
         $data[] = ['Key' => $lastOrderDate, 'Value' => $orderModel->getCreatedAt()];
     }
     if (($customerId = $website->getConfig(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CUSTOMER_ID)) && $orderModel->getCustomerId()) {
         $data[] = ['Key' => $customerId, 'Value' => $orderModel->getCustomerId()];
     }
     if (!empty($data)) {
         //update data fields
         $client = $this->helper->getWebsiteApiClient($website);
         $client->updateContactDatafieldsByEmail($orderModel->getCustomerEmail(), $data);
     }
 }
Ejemplo n.º 20
0
 /**
  * Return array with data to send to MP api
  *
  * @return array
  */
 public function makePreference()
 {
     $orderIncrementId = $this->_checkoutSession->getLastRealOrderId();
     $order = $this->_orderFactory->create()->loadByIncrementId($orderIncrementId);
     $customer = $this->_customerSession->getCustomer();
     $payment = $order->getPayment();
     $paramsShipment = new \Magento\Framework\DataObject();
     $paramsShipment->setParams([]);
     $this->_eventManager->dispatch('mercadopago_standard_make_preference_before', ['params' => $paramsShipment, 'order' => $order]);
     $arr = [];
     $arr['external_reference'] = $orderIncrementId;
     $arr['items'] = $this->getItems($order);
     $this->_calculateDiscountAmount($arr['items'], $order);
     $this->_calculateBaseTaxAmount($arr['items'], $order);
     $total_item = $this->getTotalItems($arr['items']);
     $total_item += (double) $order->getBaseShippingAmount();
     $order_amount = (double) $order->getBaseGrandTotal();
     if (!$order_amount) {
         $order_amount = (double) $order->getBasePrice() + $order->getBaseShippingAmount();
     }
     if ($total_item > $order_amount || $total_item < $order_amount) {
         $diff_price = $order_amount - $total_item;
         $arr['items'][] = ["title" => "Difference amount of the items with a total", "description" => "Difference amount of the items with a total", "category_id" => $this->_scopeConfig->getValue('payment/mercadopago/category_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), "quantity" => 1, "unit_price" => (double) $diff_price];
         $this->_helperData->log("Total itens: " . $total_item, 'mercadopago-standard.log');
         $this->_helperData->log("Total order: " . $order_amount, 'mercadopago-standard.log');
         $this->_helperData->log("Difference add itens: " . $diff_price, 'mercadopago-standard.log');
     }
     if ($order->canShip()) {
         $shippingAddress = $order->getShippingAddress();
         $shipping = $shippingAddress->getData();
         $arr['payer']['phone'] = ["area_code" => "-", "number" => $shipping['telephone']];
         $arr['shipments'] = $this->_getParamShipment($paramsShipment, $order, $shippingAddress);
     }
     $billing_address = $order->getBillingAddress()->getData();
     $arr['payer']['date_created'] = date('Y-m-d', $customer->getCreatedAtTimestamp()) . "T" . date('H:i:s', $customer->getCreatedAtTimestamp());
     $arr['payer']['email'] = htmlentities($customer->getEmail());
     $arr['payer']['first_name'] = htmlentities($customer->getFirstname());
     $arr['payer']['last_name'] = htmlentities($customer->getLastname());
     if (isset($payment['additional_information']['doc_number']) && $payment['additional_information']['doc_number'] != "") {
         $arr['payer']['identification'] = ["type" => "CPF", "number" => $payment['additional_information']['doc_number']];
     }
     $arr['payer']['address'] = ["zip_code" => $billing_address['postcode'], "street_name" => $billing_address['street'] . " - " . $billing_address['city'] . " - " . $billing_address['country_id'], "street_number" => ""];
     $url = $this->_helperData->getSuccessUrl();
     $arr['back_urls'] = ['success' => $this->_urlBuilder->getUrl($url), 'pending' => $this->_urlBuilder->getUrl($url), 'failure' => $this->_urlBuilder->getUrl('checkout/onepage/failure')];
     $arr['notification_url'] = $this->_urlBuilder->getUrl("mercadopago/notifications/standard");
     $arr['payment_methods']['excluded_payment_methods'] = $this->getExcludedPaymentsMethods();
     $installments = $this->getConfigData('installments');
     $arr['payment_methods']['installments'] = (int) $installments;
     $auto_return = $this->getConfigData('auto_return');
     if ($auto_return == 1) {
         $arr['auto_return'] = "approved";
     }
     $sponsor_id = $this->_scopeConfig->getValue('payment/mercadopago/sponsor_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     $this->_helperData->log("Sponsor_id", 'mercadopago-standard.log', $sponsor_id);
     if (!empty($sponsor_id)) {
         $this->_helperData->log("Sponsor_id identificado", 'mercadopago-standard.log', $sponsor_id);
         $arr['sponsor_id'] = (int) $sponsor_id;
     }
     return $arr;
 }
Ejemplo n.º 21
0
 /**
  * Get order
  *
  * @return \Magento\Sales\Model\Order
  */
 public function getOrder()
 {
     if (!$this->order) {
         $this->order = $this->orderFactory->create()->load($this->getParentId());
     }
     return $this->order;
 }
Ejemplo n.º 22
0
 /**
  * @return \Magento\Sales\Model\Order
  */
 protected function getOrder()
 {
     if ($this->order) {
         return $this->order;
     }
     $data = null;
     $json = base64_decode((string) $this->request->getParam('data'));
     if ($json) {
         $data = json_decode($json, true);
     }
     if (!is_array($data)) {
         return null;
     }
     if (!isset($data['order_id']) || !isset($data['increment_id']) || !isset($data['customer_id'])) {
         return null;
     }
     /** @var $order \Magento\Sales\Model\Order */
     $order = $this->orderFactory->create();
     $order->load($data['order_id']);
     if ($order->getIncrementId() != $data['increment_id'] || $order->getCustomerId() != $data['customer_id']) {
         $order = null;
     }
     $this->order = $order;
     return $this->order;
 }
Ejemplo n.º 23
0
 /**
  * Retrieve the order the invoice for created for
  *
  * @return \Magento\Sales\Model\Order
  */
 public function getOrder()
 {
     if (!$this->_order instanceof \Magento\Sales\Model\Order) {
         $this->_order = $this->_orderFactory->create()->load($this->getOrderId());
     }
     return $this->_order->setHistoryEntityName($this->entityType);
 }
Ejemplo n.º 24
0
 /**
  * Try to load valid order by $_POST or $_COOKIE
  *
  * @param App\RequestInterface $request
  * @param App\ResponseInterface $response
  * @return bool
  * 
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function loadValidOrder(App\RequestInterface $request, App\ResponseInterface $response)
 {
     if ($this->customerSession->isLoggedIn()) {
         $response->setRedirect($this->_urlBuilder->getUrl('sales/order/history'));
         return false;
     }
     $post = $request->getPost();
     $errors = false;
     /** @var $order \Magento\Sales\Model\Order */
     $order = $this->orderFactory->create();
     $fromCookie = $this->cookieManager->getCookie(self::COOKIE_NAME);
     if (empty($post) && !$fromCookie) {
         $response->setRedirect($this->_urlBuilder->getUrl('sales/guest/form'));
         return false;
     } elseif (!empty($post) && isset($post['oar_order_id']) && isset($post['oar_type'])) {
         $type = $post['oar_type'];
         $incrementId = $post['oar_order_id'];
         $lastName = $post['oar_billing_lastname'];
         $email = $post['oar_email'];
         $zip = $post['oar_zip'];
         if (empty($incrementId) || empty($lastName) || empty($type) || !in_array($type, array('email', 'zip')) || $type == 'email' && empty($email) || $type == 'zip' && empty($zip)) {
             $errors = true;
         }
         if (!$errors) {
             $order->loadByIncrementId($incrementId);
         }
         $errors = true;
         if ($order->getId()) {
             $billingAddress = $order->getBillingAddress();
             if (strtolower($lastName) == strtolower($billingAddress->getLastname()) && ($type == 'email' && strtolower($email) == strtolower($billingAddress->getEmail()) || $type == 'zip' && strtolower($zip) == strtolower($billingAddress->getPostcode()))) {
                 $errors = false;
             }
         }
         if (!$errors) {
             $toCookie = base64_encode($order->getProtectCode() . ':' . $incrementId);
             $this->setGuestViewCookie($toCookie);
         }
     } elseif ($fromCookie) {
         $cookieData = explode(':', base64_decode($fromCookie));
         $protectCode = isset($cookieData[0]) ? $cookieData[0] : null;
         $incrementId = isset($cookieData[1]) ? $cookieData[1] : null;
         $errors = true;
         if (!empty($protectCode) && !empty($incrementId)) {
             $order->loadByIncrementId($incrementId);
             if ($order->getProtectCode() == $protectCode) {
                 // renew cookie
                 $this->setGuestViewCookie($fromCookie);
                 $errors = false;
             }
         }
     }
     if (!$errors && $order->getId()) {
         $this->coreRegistry->register('current_order', $order);
         return true;
     }
     $this->messageManager->addError(__('You entered incorrect data. Please try again.'));
     $response->setRedirect($this->_urlBuilder->getUrl('sales/guest/form'));
     return false;
 }
Ejemplo n.º 25
0
 public function execute()
 {
     if (($json = $this->getRequest()->getParam('json')) && $json == 1) {
         return parent::execute();
     }
     $orderId = $this->getRequest()->getParam('orderID');
     $order = $this->_orderFactory->create();
     $order->load($orderId);
     if (!$order->getId()) {
         $resultForward = $this->_resultForwardFactory->create();
         return $resultForward->forward('noroute');
     }
     $this->_registry->register('order', $order);
     $resultPage = $this->_resultPageFactory->create();
     $resultPage->getConfig()->getTitle()->set(__('Order Info'));
     return $resultPage;
 }
 protected function _getOrder($vendorOrderId)
 {
     $this->_order = $this->_orderFactory->create()->loadByIncrementId($vendorOrderId);
     if (!$this->_order->getId()) {
         throw new Exception(sprintf('Wrong order ID: "%s".', $vendorOrderId));
     }
     return $this->_order;
 }
 /**
  * @return ShippingAssignmentInterface[]|null
  */
 public function create()
 {
     $shippingAssignments = null;
     if ($this->getOrderId()) {
         $order = $this->orderFactory->create()->load($this->getOrderId());
         /** @var ShippingAssignmentInterface $shippingAssignment */
         $shippingAssignment = $this->shippingAssignmentFactory->create();
         $shipping = $this->shippingBuilderFactory->create();
         $shipping->setOrderId($this->getOrderId());
         $shippingAssignment->setShipping($shipping->create());
         $shippingAssignment->setItems($order->getItems());
         $shippingAssignment->setStockId($order->getStockId());
         //for now order has only one shipping assignment
         $shippingAssignments = [$shippingAssignment];
     }
     return $shippingAssignments;
 }
 /**
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $order = $observer->getEvent()->getOrder();
     //order is new
     if (!$order->getId()) {
         $orderStatus = $order->getStatus();
     } else {
         // the reloaded status
         $reloaded = $this->orderFactory->create()->load($order->getId());
         $orderStatus = $reloaded->getStatus();
     }
     //register the order status before change
     if (!$this->registry->registry('sales_order_status_before')) {
         $this->registry->register('sales_order_status_before', $orderStatus);
     }
     return $this;
 }
Ejemplo n.º 29
0
 /**
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return bool
  */
 public function load(RequestInterface $request, ResponseInterface $response)
 {
     $orderId = (int) $request->getParam('order_id');
     if (!$orderId) {
         $request->initForward();
         $request->setActionName('noroute');
         $request->setDispatched(false);
         return false;
     }
     $order = $this->orderFactory->create()->load($orderId);
     if ($this->orderAuthorization->canView($order)) {
         $this->registry->register('current_order', $order);
         return true;
     }
     $response->setRedirect($this->url->getUrl('*/*/history'));
     return false;
 }
Ejemplo n.º 30
0
 /**
  * @param RequestInterface $request
  * @return bool|\Magento\Framework\Controller\Result\Forward|\Magento\Framework\Controller\Result\Redirect
  */
 public function load(RequestInterface $request)
 {
     $orderId = (int) $request->getParam('order_id');
     if (!$orderId) {
         /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
         $resultForward = $this->resultForwardFactory->create();
         return $resultForward->forward('noroute');
     }
     $order = $this->orderFactory->create()->load($orderId);
     if ($this->orderAuthorization->canView($order)) {
         $this->registry->register('current_order', $order);
         return true;
     }
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->redirectFactory->create();
     return $resultRedirect->setUrl($this->url->getUrl('*/*/history'));
 }