當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Order::getCustomerLastname方法代碼示例

本文整理匯總了PHP中Magento\Sales\Model\Order::getCustomerLastname方法的典型用法代碼示例。如果您正苦於以下問題:PHP Order::getCustomerLastname方法的具體用法?PHP Order::getCustomerLastname怎麽用?PHP Order::getCustomerLastname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Sales\Model\Order的用法示例。


在下文中一共展示了Order::getCustomerLastname方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: df_order_customer_name

/**
 * 2016-03-09
 * @param O $order
 * @return string
 */
function df_order_customer_name(O $order)
{
    /** @var string $result */
    $result = df_cc_s($order->getCustomerFirstname(), $order->getCustomerMiddlename(), $order->getCustomerLastname());
    if (!$result) {
        /** @var C $customer */
        $customer = $order->getCustomer();
        if ($customer) {
            $result = $customer->getName();
        }
    }
    if (!$result) {
        /** @var OA|null $ba */
        $ba = $order->getBillingAddress();
        if ($ba) {
            $result = $ba->getName();
        }
    }
    if (!$result) {
        /** @var OA|null $ba */
        $sa = $order->getShippingAddress();
        if ($sa) {
            $result = $sa->getName();
        }
    }
    if (!$result) {
        /**
         * 2016-08-24
         * Имени в адресах может запросто не быть
         * (например, если покупатель заказывает цифровой товар и askForBillingAddress = false),
         * и вот тогда мы попадаем сюда.
         * В данном случае функция вернёт просто «Guest».
         */
        $result = $this->o()->getCustomerName();
    }
    return $result;
}
開發者ID:mage2pro,項目名稱:core,代碼行數:42,代碼來源:order.php

示例2: build

 /**
  * Loads the order info from a Magento order model.
  *
  * @param Order $order the order model.
  * @return \NostoOrder
  */
 public function build(Order $order)
 {
     $nostoOrder = new \NostoOrder();
     try {
         $nostoCurrency = new NostoCurrencyCode($order->getOrderCurrencyCode());
         $nostoOrder->setOrderNumber($order->getId());
         $nostoOrder->setExternalRef($order->getRealOrderId());
         $nostoOrder->setCreatedDate(new NostoDate(strtotime($order->getCreatedAt())));
         $nostoOrder->setPaymentProvider(new NostoOrderPaymentProvider($order->getPayment()->getMethod()));
         if ($order->getStatus()) {
             $nostoStatus = new NostoOrderStatus();
             $nostoStatus->setCode($order->getStatus());
             $nostoStatus->setLabel($order->getStatusLabel());
             $nostoOrder->setStatus($nostoStatus);
         }
         foreach ($order->getAllStatusHistory() as $item) {
             if ($item->getStatus()) {
                 $nostoStatus = new NostoOrderStatus();
                 $nostoStatus->setCode($item->getStatus());
                 $nostoStatus->setLabel($item->getStatusLabel());
                 $nostoStatus->setCreatedAt(new NostoDate(strtotime($item->getCreatedAt())));
                 $nostoOrder->addHistoryStatus($nostoStatus);
             }
         }
         // Set the buyer information
         $nostoBuyer = new NostoOrderBuyer();
         $nostoBuyer->setFirstName($order->getCustomerFirstname());
         $nostoBuyer->setLastName($order->getCustomerLastname());
         $nostoBuyer->setEmail($order->getCustomerEmail());
         $nostoOrder->setBuyer($nostoBuyer);
         // Add each ordered item as a line item
         /** @var Item $item */
         foreach ($order->getAllVisibleItems() as $item) {
             $nostoItem = new NostoOrderItem();
             $nostoItem->setItemId((int) $this->buildItemProductId($item));
             $nostoItem->setQuantity((int) $item->getQtyOrdered());
             $nostoItem->setName($this->buildItemName($item));
             try {
                 $nostoItem->setUnitPrice(new NostoPrice($this->_priceHelper->getItemFinalPriceInclTax($item)));
             } catch (\NostoInvalidArgumentException $E) {
                 $nostoItem->setUnitPrice(new NostoPrice(0));
             }
             $nostoItem->setCurrency($nostoCurrency);
             $nostoOrder->addItem($nostoItem);
         }
         // Add discounts as a pseudo line item
         if (($discount = $order->getDiscountAmount()) < 0) {
             $nostoItem = new NostoOrderItem();
             $nostoItem->setItemId(-1);
             $nostoItem->setQuantity(1);
             $nostoItem->setName($this->buildDiscountRuleDescription($order));
             $nostoItem->setUnitPrice(new NostoPrice($discount));
             $nostoItem->setCurrency($nostoCurrency);
             $nostoOrder->addItem($nostoItem);
         }
         // Add shipping and handling as a pseudo line item
         if (($shippingInclTax = $order->getShippingInclTax()) > 0) {
             $nostoItem = new NostoOrderItem();
             $nostoItem->setItemId(-1);
             $nostoItem->setQuantity(1);
             $nostoItem->setName('Shipping and handling');
             $nostoItem->setUnitPrice(new NostoPrice($shippingInclTax));
             $nostoItem->setCurrency($nostoCurrency);
             $nostoOrder->addItem($nostoItem);
         }
     } catch (Exception $e) {
         $this->_logger->error($e, ['exception' => $e]);
     }
     return $nostoOrder;
 }
開發者ID:Nosto,項目名稱:nosto-magento2,代碼行數:76,代碼來源:Builder.php


注:本文中的Magento\Sales\Model\Order::getCustomerLastname方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。