Esempio n. 1
0
    $saved = $order->save();
    //Сохраняем товары заказа
    if ($saved) {
        $purchasesData = $shopCart->getProductsData(true);
        foreach ($shopCart->data as $key => $p_data) {
            $options = !empty($p_data['options']) ? json_encode($p_data['options']) : '';
            $fields_data = !empty($purchasesData[$key]) ? $purchasesData[$key] : array();
            $fields_data['url'] = !empty($p_data['url']) ? $p_data['url'] : '';
            unset($fields_data['id']);
            $fields_data_str = json_encode($fields_data);
            $insert_data = array('p_id' => $p_data['id'], 'order_id' => $order->id, 'name' => $p_data['name'], 'price' => $p_data['price'], 'count' => $p_data['count'], 'class_name' => $p_data['className'], 'package_name' => $p_data['packageName'], 'data' => $fields_data_str, 'options' => $options);
            $purchase = $modx->newObject('shk_purchases');
            $purchase->fromArray($insert_data);
            $purchase->save();
        }
        $shopCart->setOrderDataSession($order->toArray());
    }
    $modx->invokeEvent('OnSHKChangeStatus', array('order_ids' => array($order->id), 'status' => $order->status));
    $orderOutputData = $shopCart->getOrderData($order->id);
    //OnSHKsaveOrder
    $evtOut = $modx->invokeEvent('OnSHKsaveOrder', array('order_id' => $order->get('id')));
    if (is_array($evtOut)) {
        $orderOutputData .= implode('', $evtOut);
    }
    $hook->setValues(array('orderID' => $order->get('id'), 'orderDate' => $order->get('date'), 'orderPrice' => $order->get('price'), 'orderCurrency' => $shopCart->config['currency'], 'orderOutputData' => $orderOutputData));
    $shopCart->request_empty(false);
    $output = true;
} else {
    $hook->addError('error_message', $modx->lexicon('shk.order_empty'));
    $output = false;
}