?> <dl class="dl-horizontal"> <dt><?php _e('Order number', 'jigoshop'); ?> </dt> <dd><?php echo $order->getNumber(); ?> </dd> <dt><?php _e('Status', 'jigoshop'); ?> </dt> <dd><?php echo Status::getName($order->getStatus()); ?> </dd> </dl> <div class="col-md-6"> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title"><?php _e('Billing address', 'jigoshop'); ?> </h3> </div> <div class="panel-body clearfix"> <?php Render::output('user/account/address', array('address' => $order->getCustomer()->getBillingAddress())); ?>
/** * Saves order to database. * * @param $object EntityInterface Order to save. * * @throws Exception */ public function save(EntityInterface $object) { if (!$object instanceof Order) { throw new Exception('Trying to save not an order!'); } $this->wp->doAction('jigoshop\\order\\before\\' . $object->getStatus(), $object); /** @var Order $object */ $object->setUpdatedAt(new \DateTime()); if (!$object->getNumber()) { $object->setNumber($this->getNextOrderNumber()); } //Recalculate shiping $shipping = $object->getShippingMethod(); if ($shipping && $shipping instanceof Method) { $object->setShippingMethod($object->getShippingMethod()); } $fields = $object->getStateToSave(); if (isset($fields['id'])) { unset($fields['id']); } $wpdb = $this->wp->getWPDB(); if (!$object->getId()) { $date = $this->wp->getHelpers()->currentTime('mysql'); $dateGmt = $this->wp->getHelpers()->currentTime('mysql', true); $wpdb->insert($wpdb->posts, array('post_author' => $object->getCustomer()->getId() ? $object->getCustomer()->getId() : 0, 'post_date' => $date, 'post_date_gmt' => $dateGmt, 'post_modified' => $date, 'post_modified_gmt' => $dateGmt, 'post_type' => Types::ORDER, 'post_title' => $object->getTitle(), 'post_excerpt' => $object->getCustomerNote(), 'post_status' => $object->getStatus(), 'post_name' => sanitize_title($object->getTitle()), 'comment_status' => 'open', 'ping_status' => 'closed')); $id = $wpdb->insert_id; if (!is_int($id) || $id === 0) { throw new Exception(__('Unable to save order. Please try again.', 'jigoshop')); } $object->setId($id); $this->wp->doAction('jigoshop\\service\\order\\new', $id, $object); unset($fields['status'], $fields['customer_note']); } if (!$object->getKey()) { $fields['key'] = $this->generateOrderKey($object); $object->setKey($fields['key']); } if (isset($fields['status']) || isset($fields['customer_note'])) { $wpdb->update($wpdb->posts, array('post_title' => $object->getTitle(), 'post_status' => $object->getStatus(), 'post_excerpt' => $object->getCustomerNote()), array('ID' => $object->getId())); unset($fields['customer_note'], $fields['status']); } if (isset($fields['update_messages']) && !empty($fields['update_messages'])) { foreach ($fields['update_messages'] as $messages) { if ($messages['old_status'] != Order\Status::COMPLETED && $messages['new_status'] == Order\Status::COMPLETED || $messages['old_status'] != Order\Status::REFUNDED && $messages['new_status'] == Order\Status::REFUNDED) { $this->wp->doAction('jigoshop\\order\\' . $messages['new_status'], $object); } $this->wp->doAction('jigoshop\\order\\' . $messages['old_status'] . '_to_' . $messages['new_status'], $object); $this->addNote($object, sprintf(__('%sOrder status changed from %s to %s.', 'jigoshop'), $messages['message'], Order\Status::getName($messages['old_status']), Order\Status::getName($messages['new_status']))); } unset($fields['update_messages']); } if (isset($fields['items'])) { // TODO: Check again if we have enough stock $existing = array_map(function ($item) { /** @var $item Order\Item */ return $item->getId(); }, $fields['items']); $this->removeAllExcept($object->getId(), $existing); foreach ($fields['items'] as $item) { /** @var $item Order\Item */ $data = array('order_id' => $object->getId(), 'product_id' => $item->getProduct() ? $item->getProduct()->getId() : null, 'product_type' => $item->getType(), 'title' => $item->getName(), 'price' => $item->getPrice(), 'tax' => $item->getTax(), 'quantity' => $item->getQuantity(), 'cost' => $item->getCost()); if ($item->getId() !== null) { $wpdb->update($wpdb->prefix . 'jigoshop_order_item', $data, array('id' => $item->getId())); } else { $wpdb->insert($wpdb->prefix . 'jigoshop_order_item', $data); $item->setId($wpdb->insert_id); } foreach ($item->getAllMeta() as $meta) { /** @var $meta Order\Item\Meta */ $this->saveItemMeta($item, $meta); } } $reduceStatus = $this->wp->applyFilters('jigoshop\\product\\reduce_stock_status', Order\Status::PROCESSING, $object); if ($object->getStatus() == $reduceStatus) { foreach ($object->getItems() as $item) { /** @var \Jigoshop\Entity\Order\Item $item */ $product = $item->getProduct(); if ($product instanceof Variable) { $product = $product->getVariation($item->getMeta('variation_id')->getValue())->getProduct(); } if ($product->getStock()->getManage()) { $this->wp->doAction('jigoshop\\product\\sold', $product, $item->getQuantity(), $item); } } } if ($object->getStatus() == Order\Status::COMPLETED) { $object->setCompletedAt(); } unset($fields['items']); } foreach ($fields as $field => $value) { $this->wp->updatePostMeta($object->getId(), $field, $this->wp->getHelpers()->escSql($value)); } $this->wp->doAction('jigoshop\\service\\order\\save', $object); $this->wp->doAction('jigoshop\\order\\after\\' . $object->getStatus(), $object); $notifyLowStock = $this->options->get('products.notify_low_stock'); $notifyOutOfStock = $this->options->get('products.notify_out_of_stock'); if ($notifyLowStock || $notifyOutOfStock) { $threshold = $this->options->get('products.low_stock_threshold'); foreach ($object->getItems() as $item) { $stock = $this->wp->applyFilters('jigoshop\\product\\get_stock', false, $item); $product = $item->getProduct(); if ($notifyOutOfStock && $stock !== false && $stock == 0) { $this->wp->doAction('jigoshop\\product\\out_of_stock', $product); continue; } if ($notifyLowStock && $stock !== false && $stock <= $threshold) { $this->wp->doAction('jigoshop\\product\\low_stock', $product); } } } /** * TODO: If configured - send emails on backorders * $this->wp->addAction('jigoshop\product\backorders', array($this, 'productBackorders')); */ }