本文整理汇总了PHP中Magento\Sales\Model\OrderFactory::create方法的典型用法代码示例。如果您正苦于以下问题:PHP OrderFactory::create方法的具体用法?PHP OrderFactory::create怎么用?PHP OrderFactory::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Sales\Model\OrderFactory
的用法示例。
在下文中一共展示了OrderFactory::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* {@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;
}
示例2: _reorder
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');
}
示例3: afterGetOrders
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;
}
示例4: _getOrder
protected function _getOrder($incrementId = null)
{
if (!$this->_order) {
$incrementId = $incrementId ? $incrementId : $this->_getCheckout()->getLastRealOrderId();
$this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
}
return $this->_order;
}
示例5: _getOrder
/**
* 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;
}
示例6: execute
/**
* 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);
}
}
}
示例7: _getOrder
/**
* 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;
}
示例8: _getOrder
/**
* 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;
}
示例9: __construct
/**
* 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);
}
}
示例10: _getCustomerProductCollection
/**
* 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;
}
示例11: execute
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");
}
}
示例12: execute
/**
* 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);
}
}
}
}
示例13: prepareBlockData
/**
* 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()]);
}
示例14: _updateNewOrderDatafields
/**
* 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);
}
}
示例15: getOrder
/**
* @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;
}