17 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
18 require_once SQ_PACKAGES_PATH.
'/ecommerce/lib/ecommerce_cart_processor.inc';
19 require_once SQ_PACKAGES_PATH.
'/ecommerce/ecommerce_order/ecommerce_order.inc';
51 var $insufficient_quantities = FALSE;
65 if (!isset($_SESSION[
'sq_local_cart_contents'])) {
66 $_SESSION[
'sq_local_cart_contents'] = Array();
69 $this->_ser_attrs = TRUE;
71 parent::__construct($assetid);
85 'checkout' =>
'Checkout',
86 'confirmation' =>
'Confirmation',
87 'failure' =>
'Failure',
88 'receipt' =>
'Receipt',
109 $allowed_links = parent::_getAllowedLinks();
110 $allowed_links[SQ_LINK_NOTICE][
'ecommerce_delivery_method'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
111 $allowed_links[SQ_LINK_NOTICE][
'ecommerce_order'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
113 return $allowed_links;
128 protected function _getName($short_name=FALSE, $contextid=NULL)
131 if ($contextid === NULL) {
132 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
136 $attr = ($short_name) ?
'short_name' :
'name';
137 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName($attr, $this->
type(), Array($this->
id), $contextid);
138 if (empty($values) === TRUE) {
139 return parent::_getName($short_name, $contextid);
141 return $values[$this->id];
157 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
163 if (empty($this->print_context)) {
164 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
170 if (array_get_index($this->_tmp,
'delete_all_orders_after_printing', FALSE)) {
172 if (!isset($_SESSION[
'sq_local_cart_contents'][
'editing_order'])) {
180 $_SESSION[
'sq_local_cart_contents'] = Array();
183 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
196 $order_id = array_get_index($_SESSION[
'sq_local_cart_contents'],
'pending_order_id', FALSE);
197 if (!$order_id && isset($_SESSION[
'sq_local_cart_contents'][
'editing_order']) && $_SESSION[
'sq_local_cart_contents'][
'editing_order']) {
199 $order_id = array_get_index($_SESSION[
'sq_local_cart_contents'],
'order_id', FALSE);
202 if (isset($order_id) && $order_id) {
203 return $GLOBALS[
'SQ_SYSTEM']->am->getAsset($order_id);
222 if (is_null($order)) {
224 if (is_null($order)) {
229 $order_history = $order->attr(
'order_history');
231 while (isset($order_history[$index])) {
234 $order_history[$index] = $action;
235 $order->setAttrValue(
'order_history', $order_history);
237 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
238 $order->saveAttributes();
239 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
259 $order_id = array_get_index($_REQUEST,
'edit_order_id', 0);
261 if (!empty($order_id)) {
262 $order = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($order_id);
264 $this->
_logOrderAction(translate(
'ecom_order_history_existing_order_provided'), $order);
267 if (!empty($order) && $order->writeAccess()) {
269 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($order->id,
'attribute')) {
270 $_SESSION[
'sq_local_cart_contents'][
'order_id'] = $order->id;
271 $_SESSION[
'sq_local_cart_contents'][
'delivery_id'] = $order->attr(
'delivery_id');
272 $_SESSION[
'sq_local_cart_contents'][
'delivery_state'] = $order->attr(
'delivery_state');
273 $_SESSION[
'sq_local_cart_contents'][
'cart_contents'] = $order->attr(
'products');
275 $this->print_context =
'checkout';
276 $_SESSION[
'sq_local_cart_contents'][
'delivery_state'][
'last_context'] =
'checkout';
279 $_SESSION[
'sq_local_cart_contents'][
'editing_order'] = TRUE;
282 echo
'This order is currently being edited';
286 echo
'You cannot edit this order';
293 $this->print_context =
'checkout';
295 $request_action = array_get_index($_REQUEST, $this->
getPrefix().
'_action');
299 if (empty($request_action)) {
300 if ($this->print_context ===
'checkout') {
304 unset($_SESSION[
'sq_local_cart_contents'][
'order_id']);
305 unset($_SESSION[
'sq_local_cart_contents'][
'delivery_id']);
306 unset($_SESSION[
'sq_local_cart_contents'][
'delivery_state']);
307 unset($_SESSION[
'sq_local_cart_contents'][
'editing_order']);
308 unset($_SESSION[
'sq_local_cart_contents'][
'success_order_id']);
310 $local_cart_empty = empty($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
312 $need_update = FALSE;
313 if ($local_cart_empty) {
315 if ($global_cart->getCount() != 0) {
321 $local_cart->setCartContainer($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
323 if (strcmp($global_cart->hashCart(), $local_cart->hashCart()) != 0) {
330 $_SESSION[
'sq_local_cart_contents'][
'cart_contents'] = $global_cart->getCart();
337 if (is_array($request_action)) {
338 $action = key($request_action);
341 $action = $request_action;
346 $this->
_logOrderAction(translate(
'ecom_order_history_action', ucwords(str_replace(
'_',
' ', $action))));
349 case 'go_to_confirmation':
350 $delivery_method_id = array_get_index($_REQUEST,
'sq_delivery_method_id');
353 if (isset($_SESSION[
'sq_local_cart_contents'][
'delivery_state'])) {
354 if ($_SESSION[
'sq_local_cart_contents'][
'delivery_state'][
'last_context'] ==
'confirmation') {
355 $this->print_context =
'confirmation';
360 if (!empty($delivery_method_id) && !empty($_SESSION[
'sq_local_cart_contents'][
'cart_contents'])) {
362 $delivery_method = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($delivery_method_id);
363 if (empty($delivery_method)) {
364 $this->print_context =
'checkout';
369 $_SESSION[
'sq_local_cart_contents'][
'delivery_state'][
'cart_contents'] = $_SESSION[
'sq_local_cart_contents'][
'cart_contents'];
370 $delivery_method->setState($_SESSION[
'sq_local_cart_contents'][
'delivery_state']);
374 $form_answers = $delivery_method->processInputInterface();
375 if ($form_answers === FALSE) {
376 $this->_tmp[
'delivery_method_errors'] = $delivery_method->getErrors();
381 $country_question = $this->
attr(
'country_question');
382 $taxable_countries = $this->
attr(
'taxable_countries');
385 if (isset($form_answers[$country_question])) {
386 $country_code = $form_answers[$country_question][
'value'];
387 if (is_array($country_code)) {
389 $country_code = $country_code[0];
394 $has_country_code = isset($country_code);
395 if ($has_country_code || $this->
attr(
'accept_empty_country_question')) {
397 $_SESSION[
'sq_region_specific'] = Array();
399 if ($has_country_code) {
400 if (!in_array($country_code, $taxable_countries)) {
401 $_SESSION[
'sq_region_specific'][
'remove_tax'] = TRUE;
403 $_SESSION[
'sq_region_specific'][
'remove_tax'] = FALSE;
408 if ($has_country_code) {
409 $delivery_weight_fees = $this->
attr(
'delivery_weight_fee_mapping');
410 foreach ($delivery_weight_fees as $key => $data) {
411 if (in_array($country_code, $data[
'countries'])) {
413 $_SESSION[
'sq_region_specific'][
'delivery_weight_fee'][
'fee'] = $data[
'price'];
421 $selector_type = $this->
attr(
'item_weight_selector');
422 switch ($selector_type) {
424 $fieldid = $this->
attr(
'item_weight_metadata_source');
425 if (!empty($fieldid)) {
426 $_SESSION[
'sq_region_specific'][
'delivery_weight_fee'][
'metadata_fieldid'] = $fieldid;
431 $attribute_name = $this->
attr(
'item_weight_attribute_source');
432 if (!empty($attribute_name)) {
433 $_SESSION[
'sq_region_specific'][
'delivery_weight_fee'][
'attribute_name'] = $attribute_name;
439 if (!isset($_SESSION[
'sq_region_specific'][
'delivery_weight_fee'][
'fee'])) {
441 $default_price_weight = $this->
attr(
'default_delivery_weight_fee');
442 $_SESSION[
'sq_region_specific'][
'delivery_weight_fee'][
'fee'] = $default_price_weight;
446 $default_max_product_quantity = $this->
attr(
'default_max_product_quantity');
447 if (!empty($default_max_product_quantity)) {
448 $_SESSION[
'sq_region_specific'][
'delivery_weight_fee'][
'max_quantity'] = $default_max_product_quantity;
452 if ($has_country_code) {
453 $exempt_countries = $this->
attr(
'international_delivery_fee_exempt_countries');
454 if (!in_array($country_code, $exempt_countries)) {
456 $international_fee = $this->
attr(
'international_delivery_fee');
457 if (!empty($international_fee)) {
458 $_SESSION[
'sq_region_specific'][
'international_delivery_fee'] = $international_fee;
464 if ($has_country_code) {
465 $conditional_fees = $this->
attr(
'conditional_delivery_fees');
466 $comparison_data = Array();
467 if (!empty($conditional_fees)) {
468 foreach ($conditional_fees as $key => $data) {
469 if (in_array($country_code, $data[
'countries'])) {
470 unset($data[
'countries']);
471 $comparison_data[] = $data;
474 if (!empty($comparison_data)) {
475 $_SESSION[
'sq_region_specific'][
'conditions'] = $comparison_data;
481 $max_delivery_fee = $this->
attr(
'max_delivery_fee');
482 if ($max_delivery_fee != 0) {
483 $_SESSION[
'sq_region_specific'][
'max_delivery_fee'] = $max_delivery_fee;
486 }
else if (isset($_SESSION[
'sq_region_specific'])) {
487 unset($_SESSION[
'sq_region_specific']);
491 $_SESSION[
'sq_local_cart_contents'][
'delivery_id'] = $delivery_method_id;
492 $_SESSION[
'sq_local_cart_contents'][
'delivery_state'] = $delivery_method->getState();
493 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($delivery_method);
497 if ($success && empty($_SESSION[
'sq_local_cart_contents'][
'cart_contents'])) {
498 $this->_tmp[
'delivery_method_errors'][] =
'The cart is empty. We cannot perform a checkout.';
502 $this->print_context =
'confirmation';
504 $this->print_context =
'checkout';
507 if (isset($_SESSION[
'sq_local_cart_contents'][
'editing_order'])) {
508 $_SESSION[
'sq_local_cart_contents'][
'editing_order'] = TRUE;
513 case 'return_to_checkout':
515 $country_question = $this->
attr(
'country_question');
516 if (!empty($country_question)) {
517 $question = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
attr(
'country_question'));
518 $default_value = $question->attr(
'default');
519 if (isset($default_value[0]) && in_array($default_value[0], $this->
attr(
'taxable_countries'))) {
520 $_SESSION[
'sq_region_specific'][
'remove_tax'] = FALSE;
522 $_SESSION[
'sq_region_specific'][
'remove_tax'] = TRUE;
525 $_SESSION[
'sq_region_specific'][
'remove_tax'] = FALSE;
528 $this->print_context =
'checkout';
531 case 'payment_gateway_successful':
532 case 'confirm_order':
536 if (empty($delivery_method)) {
537 $this->_tmp[
'delivery_method_errors'][] =
'Delivery method not found during the confirmation';
538 $this->print_context =
'failure';
543 if ((!isset($_SESSION[
'sq_local_cart_contents'][
'pending_order_id']) || !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($_SESSION[
'sq_local_cart_contents'][
'pending_order_id']))) {
545 if (!(isset($_SESSION[
'sq_local_cart_contents'][
'editing_order']) && $_SESSION[
'sq_local_cart_contents'][
'editing_order'])) {
547 $order_asset = $this->
_createOrder($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
550 $_SESSION[
'sq_local_cart_contents'][
'pending_order_id'] = $order_asset->id;
558 $this->_saveOrderSummary($order_asset, $delivery_method);
559 $this->
_logOrderAction(translate(
'ecom_order_history_customer_details_saved'), $order_asset);
572 if (isset($delivery_method)) {
573 $delivery_method->setState($_SESSION[
'sq_local_cart_contents'][
'delivery_state']);
592 if (isset($_SESSION[
'sq_local_cart_contents'][
'order_id'])) {
593 $order_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($_SESSION[
'sq_local_cart_contents'][
'order_id']);
595 $this->
_logOrderAction(translate(
'ecom_order_history_commence_process_existing'), $order_asset);
599 $payment_gateway_xml =
'';
602 $review_order = FALSE;
604 if (empty($order_asset)) {
606 $payment_response = array_get_index($_SESSION,
'SQ_ECOM_RESPONSE', FALSE);
610 if (!$payment_response && $this->
attr(
'enforce_quantities')) {
613 $this->print_context =
'failure';
616 $this->insufficient_quantities = FALSE;
620 if (!$payment_response) {
622 $payment_gateway_attr =& $delivery_method->getAttribute(
'payment_gateway', TRUE);
623 $payment_gateway_id = NULL;
625 if (!is_null($payment_gateway_attr)) {
626 $payment_gateway_id = $delivery_method->attr(
'payment_gateway');
628 if (!empty($payment_gateway_id)) {
631 $cart->setCartContainer($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
633 $remove_tax = isset($_SESSION[
'sq_region_specific'][
'remove_tax']) ? $_SESSION[
'sq_region_specific'][
'remove_tax'] : FALSE;
634 $total_cost = $cart->getGrandTotalExDelivery($this->
attr(
'taxation_rate')/100, $remove_tax, $this->
getFlatCharges());
635 $delivery_cost = $cart->getTotalDeliveryCosts($total_cost);
638 $this->
_logOrderAction(translate(
'ecom_order_history_payment_gateway'));
639 $delivery_method->processPaymentGateway(round($total_cost + $delivery_cost, $this->
attr(
'float_precision')));
642 }
else if ($delivery_method->attr(
'gateway_required')){
643 $this->_tmp[
'delivery_method_errors'][] = translate(
'ecom_checkout_error_no_payment_gateway_specified');
644 $this->print_context =
'failure';
655 unset($_SESSION[
'SQ_ECOM_RESPONSE']);
658 if ($this->
attr(
'enforce_quantities')) {
663 foreach ($this->insufficient_quantity_assets as $quantity => $asset_name) {
664 echo $asset_name.
":\t -> \t".abs($quantity).
"\n";
666 $neg_quantity_list = ob_get_clean();
667 $review_order = TRUE;
669 $this->print_context =
'receipt';
671 $this->
_logOrderAction(translate(
'ecom_order_history_review_insufficient_quantities'));
676 $pending_order_id = array_get_index($_SESSION[
'sq_local_cart_contents'],
'pending_order_id', NULL);
677 $dest_folder_name = $review_order ?
'Orders To Review' :
'Completed Orders';
678 if (!is_null($pending_order_id)) {
679 $order_asset = $this->
_moveOrder($pending_order_id, $review_order);
681 $this->
_logOrderAction(translate(
'ecom_order_history_order_moved', $dest_folder_name), $order_asset);
684 if (isset($_SESSION[
'SQ_ECOM_REF_NO']) && !empty($_SESSION[
'SQ_ECOM_REF_NO'])) {
685 $order_asset->setAttrValue(
'ecom_ref_no', $_SESSION[
'SQ_ECOM_REF_NO']);
686 $this->
_logOrderAction(translate(
'ecom_order_history_ecom_ref_recorded'), $order_asset);
688 $this->
_logOrderAction(translate(
'ecom_order_history_ecom_ref_not_recorded'), $order_asset);
692 if ($payment_response) {
694 $order_asset->setAttrValue(
'transaction_id', array_get_index($payment_response,
'TRANSACTION',
''));
695 $order_asset->setAttrValue(
'billing_name', array_get_index($payment_response,
'BILLING_NAME',
''));
696 $order_asset->setAttrValue(
'billing_addr', array_get_index($payment_response,
'BILLING_ADDR',
''));
697 $order_asset->setAttrValue(
'delivery_name', array_get_index($payment_response,
'DELIVERY_NAME',
''));
698 $order_asset->setAttrValue(
'delivery_addr', array_get_index($payment_response,
'DELIVERY_ADDR',
''));
699 $payment_gateway_xml = array_get_index($payment_response,
'PAYMENT_GATEWAY_XML',
'');
704 if (!isset($order_asset) || is_null($order_asset)) {
705 $this->_tmp[
'delivery_method_errors'][] = translate(
'ecom_checkout_error_unable_to_move_order', $dest_folder_name);
706 $this->print_context =
'failure';
710 unset($_SESSION[
'sq_local_cart_contents'][
'pending_order_id']);
713 }
else if ($_SESSION[
'sq_local_cart_contents'][
'editing_order']) {
715 $this->
_logOrderAction(translate(
'ecom_order_history_skip_payment_gateway'), $order_asset);
718 $delivery_method->setState($_SESSION[
'sq_local_cart_contents'][
'delivery_state']);
721 $format_bodycopy = NULL;
722 $contents_bodycopy = NULL;
723 if ($this->
attr(
'customise_receipt')) {
724 $format_bodycopy = $this->
getBodycopy(
'receipt_format', TRUE);
725 $contents_bodycopy = $this->
getBodycopy(
'receipt_contents', TRUE);
728 $this->
_logOrderAction(translate(
'ecom_order_history_commence_delivery_method'), $order_asset);
731 $delivery_processing_status = $delivery_method->processDelivery($order_asset, $contents_bodycopy, $format_bodycopy, $this->
attr(
'currency_symbol'), $this->
attr(
'float_precision'), $this->
attr(
'taxation_name'), $this->
attr(
'taxation_rate')/100.0, $this->
getFlatCharges(), isset($neg_quantity_list) ? $neg_quantity_list :
'', isset($neg_quantity_list) ? $delivery_method->attr(
'negative_quantity_message') :
'');
733 $this->
_logOrderAction(translate(
'ecom_order_history_end_delivery_method'), $order_asset);
735 $_SESSION[
'sq_local_cart_contents'][
'delivery_state'] = $delivery_method->getState();
737 $this->_saveOrderSummary($order_asset, $delivery_method, $payment_gateway_xml);
740 if (!$delivery_processing_status) {
741 $order_asset->setAttrValue(
'status', SQ_ECOM_ORDER_STATUS_FAILED);
742 $order_asset->setAttrValue(
'status_message', translate(
'ecom_order_status_failed'));
744 $this->_tmp[
'failure_summary'] = $delivery_method->getFailureSummary();
745 $this->print_context =
'failure';
748 if ($this->
attr(
'enforce_quantities')) {
751 $this->
_logOrderAction(translate(
'ecom_order_history_quantities_updated'), $order_asset);
756 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
757 if (!$order_asset->saveAttributes()) {
758 $this->print_context =
'failure';
760 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
761 if ($this->print_context !==
'failure') {
764 $this->print_context =
'receipt';
765 $_SESSION[
'sq_local_cart_contents'][
'success_order_id'] = $order_asset->id;
766 $this->_tmp[
'delete_all_orders_after_printing'] = TRUE;
767 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_ecommerce_order_submitted', $order_asset);
786 $local_cart_contents = $_SESSION[
'sq_local_cart_contents'][
'cart_contents'];
788 foreach ($local_cart_contents as $assetid => $info) {
789 if ($GLOBALS[
'SQ_SYSTEM']->am->assetExists($assetid)) {
791 $source = $this->
attr(
'quantity_selector');
794 $quantity_field = $this->
attr(
'quantity_field');
795 if (!empty($quantity_field)) {
796 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
797 $current_quantity = $mm->getMetadataValueByAssetid($assetid, $quantity_field);
798 $new_quantity = $current_quantity - $info[
'quantity'];
799 if ($new_quantity < 0) {
801 $this->insufficient_quantities = TRUE;
804 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
805 $this->insufficient_quantity_assets[$new_quantity] = $asset->name;
809 $quantity_field => Array(
811 'value' => $new_quantity,
815 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
816 if (!$mm->setMetadata($assetid, $metadata) || !$mm->generateContentFile($assetid)) {
817 trigger_localised_error(
'ECOM024', E_USER_WARNING, $assetid);
818 $this->print_context =
'failure';
820 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
826 $quantity_attribute = $this->
attr(
'quantity_attribute');
827 if (!empty($quantity_attribute)) {
828 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
829 $current_quantity = $asset->attr($quantity_attribute);
830 $new_quantity = $current_quantity - $info[
'quantity'];
831 if ($new_quantity < 0) {
833 $this->insufficient_quantities = TRUE;
836 $this->insufficient_quantity_assets[$new_quantity] = $asset->name;
839 $asset->setAttrValue($quantity_attribute, $new_quantity);
840 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
841 if (!$asset->saveAttributes()) {
842 trigger_localised_error(
'ECOM024', E_USER_WARNING, $assetid);
843 $this->print_context =
'failure';
845 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
869 $bodycopy_folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'bodycopies');
870 if (empty($bodycopy_folder_link)) {
871 trigger_localised_error(
'ECOM0017', E_USER_WARNING);
875 $content_bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($bodycopy_folder_link[
'minorid'], SQ_LINK_TYPE_2,
'bodycopy', TRUE, $this->print_context);
876 $content_bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($content_bodycopy_link[
'minorid'], $content_bodycopy_link[
'minor_type_code']);
877 if (is_null($content_bodycopy)) {
878 trigger_localised_error(
'ECOM0018', E_USER_WARNING);
882 require_once SQ_FUDGE_PATH.
'/general/text.inc';
883 $keywords = $content_bodycopy->getKeywords();
884 $replacements = Array();
885 foreach ($keywords as $keyword) {
895 if (is_null($active_delivery_method_id )) {
897 $active_delivery_method_id = array_shift($delivery_ids);
900 if ($active_delivery_method_id) {
901 $delivery_method = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($active_delivery_method_id);
902 $delivery_form = $delivery_method ? $delivery_method->getForm() : NULL;
904 $onsubmit = $delivery_form && $delivery_form->attr(
'client_side') ?
'onSubmit="return beforeSubmit_'.$delivery_form->getPrefix().
'(this)"' :
'';
909 echo
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post" '.$onsubmit.
'>';
912 $content_bodycopy->setKeywordReplacements($replacements);
913 $content_bodycopy->printBody();
915 if ($form_req) echo
'</form>';
932 if (!parent::_createAdditional($link))
return FALSE;
936 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'folder');
939 'bodycopies' =>
'folder',
940 'pending_orders' =>
'folder',
941 'completed_orders' =>
'folder',
942 'orders_to_review' =>
'folder',
945 $bodycopy_folder = NULL;
946 foreach ($sub_assets as $link_value => $type) {
947 $asset =
new $type();
950 'value' => $link_value,
951 'link_type' => SQ_LINK_TYPE_2,
956 $asset->setAttrValue(
'name', ucwords(str_replace(
'_',
' ', $link_value)));
957 if (!$asset->create($copy_link)) $success = FALSE;
959 if ($link_value ==
'bodycopies') {
960 $bodycopy_folder = $asset;
963 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
966 if (!$success)
break;
971 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
976 'asset' => &$bodycopy_folder,
977 'value' => $context_link_value,
978 'link_type' => SQ_LINK_TYPE_2,
983 $asset->setAttrValue(
'name', $context_bodycopy_name);
985 $success = $asset->create($copy_link);
987 if (!$success)
break;
1009 $am = $GLOBALS[
'SQ_SYSTEM']->am;
1012 $order_folder_link = $am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'pending_orders');
1013 if (empty($order_folder_link))
return NULL;
1014 $order_folder_id = $order_folder_link[
'minorid'];
1016 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1017 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1020 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
1022 $orders_folder = $am->getAsset($order_folder_id);
1025 $order_link = Array(
1026 'asset' => &$orders_folder,
1027 'link_type' => SQ_LINK_TYPE_2,
1030 if (!$ecommerce_order->create($order_link)) {
1035 if ($success && !empty($cart_items)) {
1036 $ecommerce_order->setAttrValue(
'products', $cart_items);
1038 $this->
_logOrderAction(translate(
'ecom_order_history_order_created'), $ecommerce_order);
1045 if ($success && ($am->createAssetLink($this, $ecommerce_order, SQ_LINK_NOTICE,
'checkout') == 0)) {
1051 $ecommerce_order->setAttrValue(
'status', SQ_ECOM_ORDER_STATUS_PROCESSING);
1052 $ecommerce_order->setAttrValue(
'status_message', translate(
'ecom_order_status_processing'));
1057 if (!$am->acquireLock($ecommerce_order->id,
'attributes')) {
1061 if (!$ecommerce_order->saveAttributes()) {
1065 $am->releaseLock($ecommerce_order->id,
'attributes');
1068 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1071 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1072 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1075 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1076 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1078 return $ecommerce_order;
1097 $am = $GLOBALS[
'SQ_SYSTEM']->am;
1099 if (empty($order_id))
return NULL;
1100 $ecommerce_order = $am->getAsset($order_id);
1102 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1103 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1106 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
1109 $pending_orders_link = $am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'pending_orders');
1110 $order_link_info = $am->getLinkByAsset($pending_orders_link[
'minorid'], $order_id);
1113 $dest_link_value = $review ?
'orders_to_review' :
'completed_orders';
1114 $order_folder_link = $am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE, $dest_link_value);
1117 if (!$am->moveLink($order_link_info[
'linkid'], $order_folder_link[
'minorid'], SQ_LINK_TYPE_2, 0)) {
1122 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1125 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1126 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1130 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1131 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1133 return $ecommerce_order;
1146 if (!isset($this->_tmp[
'delivery_ids'])) {
1147 $this->_tmp[
'delivery_ids'] = Array();
1149 $delivery_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE,
'', FALSE,
'major',
'delivery_method');
1150 foreach ($delivery_links as $one_link) {
1151 $this->_tmp[
'delivery_ids'][] = $one_link[
'minorid'];
1155 return $this->_tmp[
'delivery_ids'];
1172 if (!empty($field_name)) {
1173 $this->_tmp[
'registered_form_fields'][] = $field_name;
1190 $this->_tmp[
'form_required'] = TRUE;
1206 return array_get_index($this->_tmp,
'form_required', FALSE);
1221 $delivery_method = NULL;
1224 if (!is_null($delivery_method_id)) {
1225 $delivery_method = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($delivery_method_id);
1226 $delivery_method_state = array_get_index($_SESSION[
'sq_local_cart_contents'],
'delivery_state', Array());
1227 $delivery_method->setState($delivery_method_state);
1230 return $delivery_method;
1245 return array_get_index($_SESSION[
'sq_local_cart_contents'],
'delivery_id');
1271 $flat_charges = $this->
attr(
'flat_charge_assetid');
1272 $flat_charge_array = Array();
1273 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
1275 foreach ($flat_charges as $charge_id) {
1276 $tmp_charge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($charge_id);
1277 $price = $tmp_charge->attr(
'price');
1278 if ($price <= 0) $price = 0;
1280 $flat_charge_array = array_merge($flat_charge_array, Array($tmp_charge->name => $price));
1283 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1284 return $flat_charge_array;
1300 $cart->setCartContainer($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
1303 if ($html) echo
'<pre>';
1306 $remove_tax = isset($_SESSION[
'sq_region_specific'][
'remove_tax']) ? $_SESSION[
'sq_region_specific'][
'remove_tax'] : FALSE;
1307 echo $cart->printReceipt($this->
attr(
'taxation_name'), ($this->
attr(
'taxation_rate')/100.0), $this->
getFlatCharges(), $remove_tax, $this->
attr(
'currency_symbol'), $this->
attr(
'float_precision'), $this->
attr(
'refund_info_text'));
1309 if ($html) echo
'</pre>';
1310 $cart_summary = ob_get_clean();
1312 return $cart_summary;
1326 $cart->setCartContainer($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
1329 $remove_tax = isset($_SESSION[
'sq_region_specific'][
'remove_tax']) ? $_SESSION[
'sq_region_specific'][
'remove_tax'] : FALSE;
1331 return $cart->getCartXml($this->
attr(
'taxation_name'), ($this->
attr(
'taxation_rate')/100.0), $this->
getFlatCharges(), $remove_tax, $this->
attr(
'currency_symbol'), $this->
attr(
'float_precision'));
1347 $cart->setCartContainer($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
1350 if ($html) echo
'<pre>';
1353 $remove_tax = isset($_SESSION[
'sq_region_specific'][
'remove_tax']) ? $_SESSION[
'sq_region_specific'][
'remove_tax'] : FALSE;
1354 echo $cart->getGrandTotalExDelivery($this->
attr(
'taxation_rate')/100, $remove_tax, $this->
getFlatCharges());
1356 if ($html) echo
'</pre>';
1357 $total_cost = ob_get_clean();
1383 $keyword_replaced = FALSE;
1385 if (isset($_SESSION[
'sq_local_cart_contents'][
'editing_order']) && !empty($_SESSION[
'sq_local_cart_contents'][
'editing_order'])) {
1386 $orderid = $_SESSION[
'sq_local_cart_contents'][
'order_id'];
1387 $order = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($orderid);
1389 if (!empty($order)) {
1390 if (strcmp(
'asset_assetid', $keyword) == 0) {
1391 $replacement = $order->id;
1392 $keyword_replaced = TRUE;
1393 }
else if (0 === strpos($keyword,
'asset_attribute_')) {
1394 $attr_name = substr($keyword, strlen(
'asset_attribute_'));
1395 if (array_key_exists($attr_name, $order->vars)) {
1396 $attr = $order->getAttribute($attr_name);
1397 if (!$attr->is_admin) {
1398 $replacement = $this->
attr($attr_name);
1399 $keyword_replaced = TRUE;
1403 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
1404 $dummy_array = Array($keyword);
1405 $mm_keyword = $mm->generateKeywordReplacements($order, $dummy_array, FALSE);
1406 if (isset($mm_keyword[$keyword])) {
1407 $replacement = $mm_keyword[$keyword];
1408 $keyword_replaced = TRUE;
1414 if (!$keyword_replaced) {
1415 $replacement = parent::getKeywordReplacement($keyword);
1418 return $replacement;
1434 $keywords = Array();
1436 if (!is_array($vars[
'keywords'])) {
1437 $vars[
'keywords'] = Array();
1440 $bodycopy_folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'bodycopies');
1442 if (empty($bodycopy_folder_link)) {
1445 $bodycopy_folder_id = $bodycopy_folder_link[
'minorid'];
1448 $customise_receipt = $this->
attr(
'customise_receipt');
1450 $broadcaster_parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id,
'bodycopy', TRUE);
1451 foreach (array_keys($broadcaster_parents) as $bodycopy_id) {
1453 $content_bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($bodycopy_folder_id, $bodycopy_id);
1454 if (!empty($content_bodycopy_link) && !empty($content_bodycopy_link[
'value'])) {
1455 $bodycopy_context = $content_bodycopy_link[
'value'];
1460 if ($customise_receipt) {
1461 $customised_receipt_folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($bodycopy_folder_id, SQ_LINK_TYPE_2,
'folder', TRUE,
'customised_receipt_folder');
1462 $content_bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($customised_receipt_folder_link[
'minorid'], $bodycopy_id);
1463 if (!empty($content_bodycopy_link) && !empty($content_bodycopy_link[
'value'])) {
1464 $bodycopy_context = $content_bodycopy_link[
'value'];
1471 $receipt_contexts = Array(
1477 if (empty($bodycopy_context) || !isset($contexts[$bodycopy_context]) && !in_array($bodycopy_context, $receipt_contexts)) {
1481 require_once SQ_FUDGE_PATH.
'/general/text.inc';
1483 $context_kw_fn =
'_get'.ucwords_no_space($bodycopy_context).
'ContextKeywords';
1484 if (method_exists($this, $context_kw_fn)) {
1485 $vars[
'keywords'] = array_merge($vars[
'keywords'], $this->$context_kw_fn());
1499 if ($this->
attr(
'customise_receipt')) {
1500 $keywords[
'customised_receipt'] = translate(
'ecom_checkout_keyword_customised_receipt');
1503 $keywords[
'cart_summary'] = translate(
'ecom_checkout_keyword_cart_summary');
1504 $keywords[
'delivery_selector'] = translate(
'ecom_checkout_keyword_delivery_selector');
1505 $keywords[
'delivery_interface'] = translate(
'ecom_checkout_keyword_delivery_interface');
1506 $keywords[
'error_messages'] = translate(
'ecom_checkout_keyword_error_messages');
1507 $keywords[
'go_to_confirmation_button'] = translate(
'ecom_checkout_keyword_go_to_confirmation_button');
1508 $keywords[
'items_count'] = translate(
'ecom_checkout_keyword_items_count');
1509 $keywords[
'items_total_count'] = translate(
'ecom_checkout_keyword_total_items_count');
1524 if ($this->
attr(
'customise_receipt')) {
1525 $keywords[
'customised_receipt'] = translate(
'ecom_checkout_keyword_customised_receipt');
1528 $keywords[
'cart_summary'] = translate(
'ecom_checkout_keyword_cart_summary');
1529 $keywords[
'confirmation_summary'] = translate(
'ecom_checkout_keyword_confirmation_summary');
1530 $keywords[
'confirm_order_button'] = translate(
'ecom_checkout_keyword_confirm_order_button');
1531 $keywords[
'return_to_checkout_button'] = translate(
'ecom_checkout_keyword_return_to_checkout_button');
1532 $keywords[
'items_count'] = translate(
'ecom_checkout_keyword_items_count');
1533 $keywords[
'items_total_count'] = translate(
'ecom_checkout_keyword_total_items_count');
1548 if ($this->
attr(
'customise_receipt')) {
1549 $keywords[
'customised_receipt'] = translate(
'ecom_checkout_keyword_customised_receipt');
1552 $keywords[
'receipt_summary'] = translate(
'ecom_checkout_keyword_receipt_summary');
1553 $keywords[
'cart_summary'] = translate(
'ecom_checkout_keyword_cart_summary');
1554 $keywords[
'order_xml'] = translate(
'ecom_checkout_keyword_order_xml');
1569 $keywords[
'failure_summary'] = translate(
'ecom_checkout_keyword_failure_summary');
1570 if ($this->
attr(
'enforce_quantities')) {
1571 $keywords[
'insufficient_quantity_message'] = translate(
'ecom_checkout_keyword_insufficient_quantity_message');
1573 $keywords[
'return_to_checkout_button'] = translate(
'ecom_checkout_keyword_return_to_checkout_button');
1588 $keywords[
'item_quantity_added'] = translate(
'ecom_checkout_keyword_item_quantity_added');
1589 $keywords[
'item_price_incl_tax'] = translate(
'ecom_checkout_keyword_item_price_incl_tax');
1590 $keywords[
'item_tax'] = translate(
'ecom_checkout_keyword_item_tax');
1592 $keywords[
'total_item_price'] = translate(
'ecom_checkout_keyword_total_item_price');
1593 $keywords[
'total_item_tax'] = translate(
'ecom_checkout_keyword_total_item_tax');
1608 $keywords[
'receipt_listing'] = translate(
'ecom_checkout_keyword_receipt_listing');
1610 $keywords[
'total_tax'] = translate(
'ecom_checkout_keyword_total_tax');
1611 $keyowrds[
'tax_name'] = translate(
'ecom_checkout_keyword_tax_name');
1613 $keywords[
'flat_fees_table'] = translate(
'ecom_checkout_keyword_flat_fees_table');
1614 $keywords[
'flat_fees_total'] = translate(
'ecom_checkout_keyword_flat_fees_total');
1615 $keywords[
'sub_total'] = translate(
'ecom_checkout_keyword_sub_total');
1616 $keywords[
'delivery_total'] = translate(
'ecom_checkout_keyword_delivery_total');
1617 $keywords[
'grand_total'] = translate(
'ecom_checkout_keyword_grant_total');
1636 $multiple_asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($delivery_ids);
1638 $selection_contents = Array();
1639 foreach ($multiple_asset_info as $assetid => $asset_info) {
1640 $selection_contents[$assetid] = $asset_info[
'name'];
1645 if (is_null($active_delivery_method_id )) {
1646 $active_delivery_method_id = array_shift($delivery_ids);
1652 <script
type=
"text/javascript">
1654 var current_method_id = <?php echo $active_delivery_method_id; ?> ;
1656 function handleDeliverySelectChange(field) {
1657 selected_id = field.options[field.selectedIndex].value;
1659 if ( current_method_id != null ) {
1660 document.getElementById(
'sq_delivery_method_' + current_method_id).style.display =
'none';
1662 current_method_id = selected_id;
1663 document.getElementById(
'sq_delivery_method_' + current_method_id).style.display =
'block';
1670 combo_box(
'sq_delivery_method_id', $selection_contents, FALSE, $active_delivery_method_id, 0,
'onchange="handleDeliverySelectChange(this)"');
1672 return ob_get_clean();
1689 if (is_null($active_delivery_method )) {
1690 $active_delivery_method_id = array_shift($delivery_ids);
1692 $active_delivery_method_id = $active_delivery_method->id;
1698 $delivery_method = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($one_assetid);
1700 if ($active_delivery_method_id == $one_assetid) {
1706 echo
"\n".
'<div id="sq_delivery_method_'.$one_assetid.
'" style="display:'.$display.
'" >'.
"\n".$delivery_method->getInputInterface().
"\n</div>\n";
1708 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($delivery_method);
1711 return ob_get_clean();
1724 $field_value = $this->
getPrefix().
'_action[confirm_order]';
1725 $field_id = $this->
getPrefix().
'_action_confirm_order';
1729 submit_button($field_value, $this->
attr(
'confirm_order_button_text'),
'',
' id="'.$field_id.
'"');
1730 return ob_get_clean();
1743 $field_value = $this->
getPrefix().
'_action[return_to_checkout]';
1744 $field_id = $this->
getPrefix().
'_action_return_to_checkout';
1747 submit_button($field_value, $this->
attr(
'return_to_checkout_button_text'),
'',
' id="'.$field_id.
'"');
1748 return ob_get_clean();
1761 $field_value = $this->
getPrefix().
'_action[go_to_confirmation]';
1762 $field_id = $this->
getPrefix().
'_action_go_to_confirmation';
1765 submit_button($field_value, $this->
attr(
'go_to_confirmation_button_text'),
'',
' id="'.$field_id.
'"');
1766 return ob_get_clean();
1783 if (!is_null($delivery_method)) {
1784 echo $delivery_method->getConfirmationSummary();
1786 return ob_get_clean();
1801 if (!is_null($delivery_method)) {
1802 echo $delivery_method->getReceiptSummary();
1804 return ob_get_clean();
1832 if (isset($_SESSION[
'sq_local_cart_contents'][
'success_order_id'])) {
1833 $order = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($_SESSION[
'sq_local_cart_contents'][
'success_order_id']);
1836 return is_null($order)?
'' : $order->attr(
'order_xml');
1850 if (!empty($this->_tmp[
'delivery_method_errors'])) {
1852 foreach ($this->_tmp[
'delivery_method_errors'] as $message) {
1853 echo
'<li>'.$message.
'</li>';
1857 return ob_get_clean();
1872 if (!is_null($delivery_method)) {
1873 echo $delivery_method->getFailureSummary();
1875 return ob_get_clean();
1888 if ($this->insufficient_quantities) {
1890 echo $this->
attr(
'quantity_message_checkout');
1892 foreach ($this->insufficient_quantity_assets as $asset_name) {
1898 return ob_get_clean();
1913 $cart->setCartContainer($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
1914 return $cart->getUniqueCount();
1928 $cart->setCartContainer($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
1929 return $cart->getCount();
1942 if ($this->
attr(
'customise_receipt')) {
1944 $cart->setCartContainer($_SESSION[
'sq_local_cart_contents'][
'cart_contents']);
1949 $remove_tax = isset($_SESSION[
'sq_region_specific'][
'remove_tax']) ? $_SESSION[
'sq_region_specific'][
'remove_tax'] : FALSE;
1951 $contents_bodycopy = $this->
getBodycopy(
'receipt_contents', TRUE);
1952 $format_bodycopy = $this->
getBodycopy(
'receipt_format', TRUE);
1953 echo $cart->printCustomisedReceipt($contents_bodycopy, $format_bodycopy, $this->
attr(
'taxation_name'), ($this->
attr(
'taxation_rate')/100.0), $this->
getFlatCharges(), $remove_tax, $this->
attr(
'currency_symbol'), $this->
attr(
'float_precision'));
1955 $customised_receipt = ob_get_clean();
1958 return $customised_receipt;
1977 if (!$name)
return $null;
1978 $am = $GLOBALS[
'SQ_SYSTEM']->am;
1980 $folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'bodycopies');
1981 if (empty($folder_link))
return $null;
1983 $folder = $am->getAsset($folder_link[
'minorid'], $folder_link[
'minor_type_code']);
1984 if (is_null($folder))
return $null;
1986 if ($receipt_folder) {
1987 $folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2,
'folder', TRUE,
'customised_receipt_folder');
1988 if (empty($folder_link))
return $null;
1989 $folder = $am->getAsset($folder_link[
'minorid'], $folder_link[
'minor_type_code']);
1990 if (is_null($folder))
return $null;
1993 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2,
'bodycopy', TRUE, $name);
1994 if (empty($bodycopy_link))
return $null;
1996 $bodycopy = $am->getAsset($bodycopy_link[
'minorid'], $bodycopy_link[
'minor_type_code']);
2015 if (!parent::saveAttributes($dont_run_updated)) {
2021 $customise_receipt = $this->
attr(
'customise_receipt');
2022 if ($customise_receipt) {
2023 $bodycopies_folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'bodycopies');
2024 $customised_receipt_folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($bodycopies_folder_link[
'minorid'], SQ_LINK_TYPE_2,
'folder', TRUE,
'customised_receipt_folder');
2026 if (empty($customised_receipt_folder_link)) {
2027 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'folder');
2029 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2030 $db = $GLOBALS[
'SQ_SYSTEM']->db;
2032 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2035 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'folder');
2037 $folder->setAttrValue(
'name',
'Customised Receipt Bodycopies');
2039 $bodycopies_folder = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bodycopies_folder_link[
'minorid']);
2041 $folder_link = Array(
'asset' => &$bodycopies_folder,
'link_type' => SQ_LINK_TYPE_2,
'value' =>
'customised_receipt_folder',
'is_dependant' => 1,
'is_exclusive' => 1);
2043 if (!$folder->create($folder_link)) {
2044 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2045 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2049 $bodycopies = Array(
2053 foreach ($bodycopies as $name) {
2055 $copy_link = Array(
'asset' => &$folder,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1,
'value' => strtolower(str_replace(
' ',
'_', $name)));
2057 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
2059 $bodycopy->setAttrValue(
'name', $name);
2061 if (!$bodycopy->create($copy_link)) {
2062 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2063 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2068 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2069 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2090 private function _saveOrderSummary(ECommerce_Order &$order_asset, ECommerce_Delivery_Method &$delivery_method, $payment_gateway_xml=
'')
2093 $order_summary =
'Order ID: '.$order_asset->id;
2098 $order_summary .= $delivery_method->getReceipt();
2100 $delivery_method_xml = $delivery_method->getDeliveryMethodXML();
2103 $default_char_set = SQ_CONF_DEFAULT_CHARACTER_SET;
2106 $order_xml =
'<'.
'?xml version="1.0" encoding="'.$default_char_set.
'"?'.
">\n".
2108 ' <id>'.$order_asset->id.
"</id>\n".
2110 $delivery_method_xml.$payment_gateway_xml.
"\n".
2114 if (isset($neg_quantity_list)) {
2115 $order_summary .=
'<br />'.$delivery_method->attr(
'negative_quantity_message');
2116 $order_summary .= $neg_quantity_list;
2121 $order_asset->setAttrValue(
'summary', $order_summary);
2122 $order_asset->setAttrValue(
'order_xml', $order_xml);
2123 $order_asset->setAttrValue(
'delivery_id', $_SESSION[
'sq_local_cart_contents'][
'delivery_id']);
2124 $order_asset->setAttrValue(
'delivery_state', $_SESSION[
'sq_local_cart_contents'][
'delivery_state']);
2125 $order_asset->setAttrValue(
'order_grand_total', $total_cost);
2141 $success = $this->_performCheckoutCompletionActions($order_asset);
2156 private function _performCheckoutCompletionActions(&$order_asset)
2158 $actions = $this->
attr(
'actions');
2160 foreach($actions as $action) {
2161 $action_type = $action[
'type_code'];
2162 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($action_type);
2164 if ($action[
'active'] && call_user_func(Array($action_type,
'isValid'), $this, $action[
'settings'])) {
2165 $success &= call_user_func(Array($action_type,
'execute'), $this, $order_asset, $action[
'settings']);