Sends an email to admin after a customer created an order
@param array $order
@return array
519369
public function createdToAdmin($order)
    {
        $store = $this->store->get($order['store_id']);
        $store_name = $this->store->getTranslation('title', $this->translation->getLangcode(), $store);
        $options = array('from' => reset($store['data']['email']));

        $default = (array) $this->store->getDefault(true);
        $url = $this->store->getUrl($default);

        $vars = array(
            '@store' => $store_name,
            '@order_id' => $order['order_id'],
            '@order' => "$url/admin/sale/order/{$order['order_id']}",
            '@status' => $this->order->getStatusName($order['status']),
            '@total' => $this->price->format($order['total'], $order['currency']),
        );

        $subject = $this->translation->text('New order #@order_id on @store', $vars);
        $message = $this->translation->text("Order status: @status\r\nTotal: @total\r\nView: @order", $vars);

        return array($options['from'], $subject, $message, $options);
    }
1033226
public function add(array $order)
    {
        $result = null;
        $this->hook->attach('order.add.before', $order, $result, $this);

        if (isset($result)) {
            return (int) $result;
        }

        unset($order['order_id']); // In case the order is cloning
        $order['created'] = $order['modified'] = GC_TIME;
        $order += array('status' => $this->getDefaultStatus());

        $this->prepareComponents($order);

        $result = $this->db->insert('orders', $order);
        $this->hook->attach('order.add.after', $order, $result, $this);
        return (int) $result;
    }
1059842
public function sendStatusMail( $order, $user = null ) {

		$fromEmail 	= $this->mailProperties->getSenderEmail();
		$fromName 	= $this->mailProperties->getSenderName();
		$status		= $order->getStatusStr();
		$user		= isset( $user ) ? $user : $order->creator;
		$toEmail	= $user->email;

		$this->getMailer()->compose( self::MAIL_STATUS, [ 'coreProperties' => $this->coreProperties, 'order' => $order, 'user' => $user ] )
			->setTo( $toEmail )
			->setFrom( [ $fromEmail => $fromName ] )
			->setSubject( "Order $status | " . $this->coreProperties->getSiteName() )
			->send();
	}
1267584
protected function getItemListForOrder(Order $order): array
    {
        $items = [];

        $priceCheck = 0;
        $count = -1;

        /** @var LineItem $item */
        foreach ($order->lineItems as $item) {
            $price = Currency::round($item->salePrice);
            // Can not accept zero amount items. See item (4) here:
            // https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/#setting-order-details-on-the-paypal-review-page

            if ($price !== 0) {
                $count++;
                /** @var Purchasable $purchasable */
                $purchasable = $item->getPurchasable();
                $defaultDescription = Craft::t('commerce', 'Item ID').' '.$item->id;
                $purchasableDescription = $purchasable ? $purchasable->getDescription() : $defaultDescription;
                $description = isset($item->snapshot['description']) ? $item->snapshot['description'] : $purchasableDescription;
                $description = empty($description) ? 'Item '.$count : $description;
                $items[] = [
                    'name' => $description,
                    'description' => $description,
                    'quantity' => $item->qty,
                    'price' => $price,
                ];

                $priceCheck += ($item->qty * $item->salePrice);
            }
        }

        $count = -1;

        /** @var OrderAdjustment $adjustment */
        foreach ($order->adjustments as $adjustment) {
            $price = Currency::round($adjustment->amount);

            // Do not include the 'included' adjustments, and do not send zero value items
            // See item (4) https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/#setting-order-details-on-the-paypal-review-page
            if (($adjustment->included == 0 || $adjustment->included == false) && $price !== 0) {
                $count++;
                $items[] = [
                    'name' => empty($adjustment->name) ? $adjustment->type." ".$count : $adjustment->name,
                    'description' => empty($adjustment->description) ? $adjustment->type.' '.$count : $adjustment->description,
                    'quantity' => 1,
                    'price' => $price,
                ];
                $priceCheck += $adjustment->amount;
            }
        }

        $priceCheck = Currency::round($priceCheck);
        $totalPrice = Currency::round($order->totalPrice);
        $same = (bool)($priceCheck === $totalPrice);

        if (!$same) {
            Craft::error('Item bag total price does not equal the orders totalPrice, some payment gateways will complain.', __METHOD__);
        }

        return $items;
    }
99268
public function getCustomerByEmail(string $email) : array
    {
        Assert::that($email)->email();

        return (array)$this->master->doRequest(
            'GET',
            sprintf('/admin/WEBAPI/Endpoints/v1_0/CustomerService/{KEY}/GetCustomerByEmail?email=%s', rawurlencode($email))
        );
    }
218068
public function addOrders( $orders )
	{
		if( !is_array( $orders ) )
			throw new InvalidArgumentException( 'An Array should be given.' );
		foreach( $orders as $column => $direction )
			$this->addOrder( $column, $direction );
	}
1112359
public function releaseAction(Order $order)
    {
        $order->releaseToBuyer();

        $em = $this->getDoctrine()->getEntityManager();
        $em->persist($order);
        $em->flush();

        return $this->redirect($this->generateUrl('Order_show', array(
            'id' => $order->getNumberForPath()
        )));
    }
74404
public function all($order = null)
    {
        $query = $this->createBuilder();

        if ( ! empty($order) and is_string($order)) {
            return $this->prepareQuery($query)->orderBy($order)->get();
        }

        if ( ! empty($order) and is_array($order)) {
            $build = $this->prepareQuery($query);

            foreach ($order as $orderItem) {
                $build = $build->orderBy($orderItem);
            }

            return $build->with($this->withs)->get();
        }

        return $this->prepareQuery($query)->get();
    }
1212865
public function transform(Order $order)
    {
        foreach ($order->meta() as $key => $total) {
            $payload[$key] = $this->converter->convert($total);
        }

        $payload['products'] = [];

        foreach ($order->products() as $product) {
            $payload['products'][] = array_map(function ($value) {
                return $this->converter->convert($value);
            }, $product);
        }

        return json_encode($payload);
    }
1222385
public function sendEmailInvoice(Model $order)
    {
        $user = $order->user;
        $view = view('avored-ecommerce::mail.order-pdf')->with('order', $order);

        $folderPath = public_path('uploads/order/invoice');
        if (!File::exists($folderPath)) {
            File::makeDirectory($folderPath, '0775', true, true);
        }
        $path = $folderPath . DIRECTORY_SEPARATOR . $order->id . '.pdf';
        PDF::loadHTML($view->render())->save($path);

        Mail::to($user->email)->send(new OrderInvoicedMail($order, $path));

        return redirect()->back()->with('notificationText', 'Email Sent Successfully!!');
    }
95631
private function handleAddresses(OrderInterface $order)
    {
        // If invoice address is no set : use the user's default one.
        if (null === $order->getInvoiceAddress()) {
            $order->setInvoiceAddress(
                $this->getOrderUserDefaultAddress($order)
            );
        }

        // If delivery address is no set and not "same delivery address" : use the user's default one.
        if ((null === $order->getDeliveryAddress()) && !$order->getSameAddress()) {
            $order->setDeliveryAddress(
                $this->getOrderUserDefaultAddress($order)
            );
        }
        // Else if delivery address is set and "same delivery address"
        elseif ((null !== $deliveryAddress = $order->getDeliveryAddress()) && $order->getSameAddress()) {
            // Unset delivery address
            $order->setDeliveryAddress(null);
            // If the address is a clone (do not belong to a user)
            if (null === $deliveryAddress->getUser()) {
                // Delete the address
                $this->addressOperator->delete($deliveryAddress);
            }
        }

        // If type is order or quote, clone the addresses.
        if (in_array($order->getType(), [OrderTypes::TYPE_ORDER, OrderTypes::TYPE_QUOTE])) {
            // Clone invoice address if needed
            $invoiceAddress = $order->getInvoiceAddress();
            if (null !== $user = $invoiceAddress->getUser()) {
                $invoiceAddress = clone $invoiceAddress;
                $this->handleAddressIdentity($invoiceAddress, $user);
                $invoiceAddress->setUser(null);
                $order->setInvoiceAddress($invoiceAddress);
            }
            // Clone delivery address if needed
            if (!$order->getSameAddress()) {
                $deliveryAddress = $order->getDeliveryAddress();
                if (null !== $user = $deliveryAddress->getUser()) {
                    $deliveryAddress = clone $deliveryAddress;
                    $this->handleAddressIdentity($deliveryAddress, $user);
                    $deliveryAddress->setUser(null);
                    $order->setDeliveryAddress($deliveryAddress);
                }
            }
        }
    }
823338
public function confirm(array $order)
    {
        Datasheet::set($order);
        $result = Helper::request(Helper::GATEWAY_TRADECONFIRM, ['AuthCode']);
        if ($result['ReturnCode'] != 1) {
            throw new \Exception("交易确认失败：" . $data['ReturnMsg']);
        }
        return $result;
    }
636643
protected static function parseOrderParameters($order)
    {
        $parsedOrder = [];
        if (count($order) > 0) {
            foreach ($order as $key => $o) {
                // Check if $order array is already formatted properly
                if (!is_numeric($key) && is_numeric($o)) {
                    $parsedOrder[$key] = $o;
                    continue;
                }
                $o = self::str($o);
                if ($o->startsWith('-')) {
                    $parsedOrder[$o->subString(1, 0)->val()] = -1;
                } elseif ($o->startsWith('+')) {
                    $parsedOrder[$o->subString(1, 0)->val()] = 1;
                } else {
                    $parsedOrder[$o->val()] = 1;
                }
            }
        }

        return $parsedOrder;
    }
937288
public function parseOrderByField($order)
	{
		if(isset($order[0],$order[1]))
		{
			if(!is_array($order[1]))
			{
				$order[1] = explode(',', $order[1]);
			}
			$list = array();
			foreach($order[1] as $item)
			{
				$paramName = $this->getParamName();
				$this->operationOption['params'][$paramName] = $item;
				$list[] = ':' . $paramName;
			}
			return 'field(' . $this->parseKeyword($order[0]) . ',' . implode(',', $list) . ')';
		}
		else
		{
			return 1;
		}
	}
240232
protected function sortFiles($order)
    {
        $order = explode(',', $order);

        $new = [];
        $original = $this->original();

        foreach ($order as $item) {
            $new[] = Arr::get($original, $item);
        }

        return $new;
    }
1269071
public function query(array $order)
    {
        Datasheet::set($order);
        $result = Helper::request(Helper::GATEWAY_TRADEQUERY, ['AuthCode']);
        return $this->callback($result);
    }
1287373
protected function buildOrderJoin(string $order): array
    {
        list($column, $direction) = $this->formatOrderDirection($order);

        $lookupBuilder = $this->getLookupBuilder();

        $column = $lookupBuilder->fetchColumnName($column);
        $newOrder = $lookupBuilder->buildJoin($this, $column);
        if (false === $newOrder) {
            return [$column, $direction];
        }

        list($alias, $column) = $newOrder;

        return [
            $alias.'.'.$column,
            $direction,
        ];
    }