Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Покупка товара в один клик для miniShop2
<?php
$context = $modx->context->get('key');
if ($context == 'mgr' || empty($_POST['quick_order']) || empty($_POST['id']) || empty($_POST['customer'])) {
return;
}
/**
* @var miniShop2 $miniShop2
*/
$miniShop2 = $modx->getService('minishop2');
$miniShop2->initialize($context, array(
'json_response' => false,
));
if (!($miniShop2 instanceof miniShop2)) {
return;
}
$_POST['customer'] = array_merge(array(
'delivery' => 1,
'payment' => 1,
), $_POST['customer']);
foreach (array('email', 'phone', 'delivery', 'payment') as $field) {
$response = $miniShop2->order->add($field, $modx->getOption($field, $_POST['customer'], ''));
if (empty($response['success'])) {
return;
}
}
$response = $miniShop2->cart->clean();
if (empty($response['success'])) {
return;
}
$response = $miniShop2->cart->add($_POST['id'], $modx->getOption('count', $_POST, 1), $modx->getOption('options', $_POST, array()));
if (empty($response['success'])) {
return;
}
$miniShop2->order->submit();
$modx->sendRedirect($modx->makeUrl($modx->resource->get('id')));
@chayteam

This comment has been minimized.

Copy link

commented Jul 6, 2016

Здравствуйте. Не силён в ms2, подскажите пожалуйста, как пользоваться данным сниппетом?

@EMDM45

This comment has been minimized.

Copy link

commented May 22, 2018

Тоже интересно, как использовать данный код? Это обработчик формы? его нужно "навешивать" на action в форме "купить в 1 клик" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.