* @copyright 2007-2013 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class OrderHistoryCore extends ObjectModel { /** @var integer Order id */ public $id_order; /** @var integer Order state id */ public $id_order_state; /** @var integer Employee id for this history entry */ public $id_employee; /** @var string Object creation date */ public $date_add; /** @var string Object last modification date */ public $date_upd; /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'order_history', 'primary' => 'id_order_history', 'fields' => array( 'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_order_state' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_employee' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), ); /** * @see ObjectModel::$webserviceParameters */ protected $webserviceParameters = array( 'objectsNodeName' => 'order_histories', 'fields' => array( 'id_order_state' => array('required' => true, 'xlink_resource'=> 'order_states'), 'id_order' => array('xlink_resource' => 'orders'), ), ); /** * Sets the new state of the given order * * @param int $new_order_state * @param int/object $id_order * @param bool $use_existing_payment */ public function changeIdOrderState($new_order_state, $id_order, $use_existing_payment = false) { if (!$new_order_state || !$id_order) return; if (!is_object($id_order) && is_numeric($id_order)) $order = new Order((int)$id_order); elseif (is_object($id_order)) $order = $id_order; else return; ShopUrl::cacheMainDomainForShop($order->id_shop); $new_os = new OrderState((int)$new_order_state, $order->id_lang); $old_os = $order->getCurrentOrderState(); $is_validated = $this->isValidated(); // executes hook if (in_array($new_os->id, array(Configuration::get('PS_OS_PAYMENT'), Configuration::get('PS_OS_WS_PAYMENT')))) Hook::exec('actionPaymentConfirmation', array('id_order' => (int)$order->id)); // executes hook Hook::exec('actionOrderStatusUpdate', array( 'newOrderStatus' => $new_os, 'id_order' => (int)$order->id )); if (Validate::isLoadedObject($order) && ($new_os instanceof OrderState)) { // An email is sent the first time a virtual item is validated $virtual_products = $order->getVirtualProducts(); if ($virtual_products && (!$old_os || !$old_os->logable) && $new_os && $new_os->logable) { $context = Context::getContext(); $assign = array(); foreach ($virtual_products as $key => $virtual_product) { $id_product_download = ProductDownload::getIdFromIdProduct($virtual_product['product_id']); $product_download = new ProductDownload($id_product_download); // If this virtual item has an associated file, we'll provide the link to download the file in the email if ($product_download->display_filename != '') { $assign[$key]['name'] = $product_download->display_filename; $dl_link = $product_download->getTextLink(false, $virtual_product['download_hash']) .'&id_order='.(int)$order->id .'&secure_key='.$order->secure_key; $assign[$key]['link'] = $dl_link; if (isset($virtual_product['date_expiration']) && $virtual_product['date_expiration'] != '0000-00-00 00:00:00') $assign[$key]['deadline'] = Tools::displayDate($virtual_product['date_expiration ']); if ($product_download->nb_downloadable != 0) $assign[$key]['downloadable'] = (int)$product_download->nb_downloadable; } } $customer = new Customer((int)$order->id_customer); $links = '