Answer the question
In order to leave comments, you need to log in
Modx revo MiniShop2 remote order creation?
Tell me how to create an order in MiniShop2 not from a browser? For example, from under cUrl
there is such a code, it works only in the browser, if nothing happens when called remotely...
<?php
$output = array();
$output['success'] = true;
if($_GET["phone"]!='' && $_GET["email"]!='' && $_GET["name"]!='' && $_GET['product_id']){
// если проверка прошла успешно - оформляем заказ
if($output['success']){
// инициализируем miniShop2
$scriptProperties = array(
'json_response' => true,
'max_count' => 1000,
'allow_deleted' => false,
'allow_unpublished' => false
);
$miniShop2 = $modx->getService('minishop2','miniShop2', MODX_CORE_PATH . 'components/minishop2/model/minishop2/', $scriptProperties);
// опции товара, если они необходимы
$option = array();
/*$option = array(
"option1" => "value1",
"option2" => "value2",
);*/
// инициализируем miniShop2 в текущем контексте
$miniShop2->initialize($modx->context->key, $scriptProperties);
// чистим корзину
$miniShop2->cart->clean();
// добавляем товар в корзину
$arr = json_decode($miniShop2->cart->add($_GET["product_id"],$_GET["quantity"],$option), true);
$modx->log(E_ERROR, print_r($arr,1));
// формируем заказ
$miniShop2->order->add('receiver', $_GET['name']);
$miniShop2->order->add('email', $_GET["email"]);
$miniShop2->order->add('phone', $_GET["phone"]);
$miniShop2->order->add('comment', $_GET["comment"]);
$miniShop2->order->add('payment', 1);
$miniShop2->order->add('delivery', 1);
$orderfeed = $miniShop2->order->submit();
$arr = json_decode($orderfeed,true);
$modx->log(E_ERROR, print_r($arr,1));
$output['success'] = true;
$output['message'] = "Ваш заказ оформлен";
}
}else{
$output['success'] = false;
$output['message'] = "Данные не прошли проверку валидности или у вас не указан ID товара";
}
echo json_encode($output);
Answer the question
In order to leave comments, you need to log in
How exactly do you call remotely? The specified code - where is it, in the snippet / file?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question