/** * Отрисовать наименование в заказе * @param order $order * @return Array */ public function renderOrderItems(order $order, $template = 'default') { $items_arr = array(); $objects = umiObjectsCollection::getInstance(); list($tpl_item, $tpl_options_block, $tpl_options_block_empty, $tpl_options_item) = def_module::loadTemplates("emarket/" . $template, 'order_item', 'options_block', 'options_block_empty', 'options_item'); $orderItems = $order->getItems(); foreach ($orderItems as $orderItem) { $orderItemId = $orderItem->getId(); $item_arr = array('attribute:id' => $orderItemId, 'attribute:name' => $orderItem->getName(), 'xlink:href' => 'uobject://' . $orderItemId, 'amount' => $orderItem->getAmount(), 'options' => null); $itemDiscount = $orderItem->getDiscount(); $plainPriceOriginal = $orderItem->getItemPrice(); $plainPriceActual = $itemDiscount ? $itemDiscount->recalcPrice($plainPriceOriginal) : $plainPriceOriginal; $totalPriceOriginal = $orderItem->getTotalOriginalPrice(); $totalPriceActual = $orderItem->getTotalActualPrice(); if ($plainPriceOriginal == $plainPriceActual) { $plainPriceOriginal = null; } if ($totalPriceOriginal == $totalPriceActual) { $totalPriceOriginal = null; } $item_arr['price'] = $this->formatCurrencyPrice(array('original' => $plainPriceOriginal, 'actual' => $plainPriceActual)); $item_arr['total-price'] = $this->formatCurrencyPrice(array('original' => $totalPriceOriginal, 'actual' => $totalPriceActual)); $item_arr['price'] = $this->parsePriceTpl($template, $item_arr['price']); $item_arr['total-price'] = $this->parsePriceTpl($template, $item_arr['total-price']); $element = false; $status = order::getCodeByStatus($order->getOrderStatus()); if (!$status || $status == 'basket') { $element = $orderItem->getItemElement(); } else { $symlink = $orderItem->getObject()->item_link; if (is_array($symlink) && sizeof($symlink)) { list($item) = $symlink; $element = $item; } else { $element = null; } } if ($element instanceof iUmiHierarchyElement) { $item_arr['page'] = $element; $item_arr['void:element_id'] = $element->id; $item_arr['void:link'] = $element->link; } $discountAmount = $totalPriceOriginal ? $totalPriceOriginal - $totalPriceActual : 0; $discount = $orderItem->getDiscount(); if ($discount instanceof itemDiscount) { $item_arr['discount'] = array('attribute:id' => $discount->id, 'attribute:name' => $discount->getName(), 'description' => $discount->getValue('description'), 'amount' => $discountAmount); $item_arr['void:discount_id'] = $discount->id; } if ($orderItem instanceof optionedOrderItem) { $options = $orderItem->getOptions(); $options_arr = array(); foreach ($options as $optionInfo) { $optionId = $optionInfo['option-id']; $price = $optionInfo['price']; $fieldName = $optionInfo['field-name']; $option = $objects->getObject($optionId); if ($option instanceof iUmiObject) { $option_arr = array('attribute:id' => $optionId, 'attribute:name' => $option->getName(), 'attribute:price' => $price, 'attribute:field-name' => $fieldName, 'attribute:element_id' => $element->id, 'xlink:href' => 'uobject://' . $optionId); $options_arr[] = def_module::parseTemplate($tpl_options_item, $option_arr, false, $optionId); } } $item_arr['options'] = def_module::parseTemplate($tpl_options_block, array('nodes:option' => $options_arr, 'void:items' => $options_arr)); } $items_arr[] = def_module::parseTemplate($tpl_item, $item_arr); } return $items_arr; }
/** * Получить id последнего заказа пользователя * * @param int $domainId id домена заказа * @return int $orderId | false */ public function getLastOrder($domainId) { if ($orderId = getSession('admin-editing-order')) return $orderId; if ($lastOrders = $this->last_order) { foreach($lastOrders as $lastOrder) { if (isset($lastOrder['float']) && $lastOrder['float'] == $domainId) { $orderId = $lastOrder['rel']; $order = order::get($orderId); if (!$order) return false; $status = order::getCodeByStatus($order->status_id); if (!$status || $status == 'executing' || ($status == 'payment' && order::getCodeByStatus($order->payment_status_id) == 'initialized') ) return $orderId; } } } return false; }
public function sendManagerNotification(order $order) { $regedit = regedit::getInstance(); $cmsController = cmsController::getInstance(); $domains = domainsCollection::getInstance(); $domainId = $cmsController->getCurrentDomain()->getId(); $defaultDomainId = $domains->getDefaultDomain()->getId(); if ($regedit->getVal("//modules/emarket/manager-email/{$domainId}")) { $emails = $regedit->getVal("//modules/emarket/manager-email/{$domainId}"); $fromMail = $regedit->getVal("//modules/emarket/from-email/{$domainId}"); $fromName = $regedit->getVal("//modules/emarket/from-name/{$domainId}"); } elseif ($regedit->getVal("//modules/emarket/manager-email/{$defaultDomainId}")) { $emails = $regedit->getVal("//modules/emarket/manager-email/{$defaultDomainId}"); $fromMail = $regedit->getVal("//modules/emarket/from-email/{$defaultDomainId}"); $fromName = $regedit->getVal("//modules/emarket/from-name/{$defaultDomainId}"); } else { $emails = $regedit->getVal('//modules/emarket/manager-email'); $fromMail = $regedit->getVal("//modules/emarket/from-email"); $fromName = $regedit->getVal("//modules/emarket/from-name"); } $letter = new umiMail(); $recpCount = 0; foreach (explode(',', $emails) as $recipient) { $recipient = trim($recipient); if (strlen($recipient)) { $letter->addRecipient($recipient); $recpCount++; } } if (!$recpCount) { return; } list($template) = def_module::loadTemplatesForMail("emarket/mail/default", "neworder_notification"); try { $payment = payment::get($order->payment_id); $paymentName = $payment->name; $paymentStatus = order::getCodeByStatus($order->getPaymentStatus()); } catch (coreException $e) { $paymentName = ""; $paymentStatus = ""; } $param = array(); $param["order_id"] = $order->id; $param["order_name"] = $order->name; $param["order_number"] = $order->number; $param["payment_type"] = $paymentName; $param["payment_status"] = $paymentStatus; $param["price"] = $order->getActualPrice(); $param["domain"] = cmsController::getInstance()->getCurrentDomain()->getHost(); $content = def_module::parseTemplateForMail($template, $param); $langs = cmsController::getInstance()->langs; $letter->setFrom($fromMail, $fromName); $letter->setSubject($langs['notification-neworder-subject'] . " (#{$order->number})"); $letter->setContent($content); $letter->commit(); $letter->send(); }