Skip to content

Instantly share code, notes, and snippets.

@grachov
Created June 4, 2014 13:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save grachov/5340aab7f43bb166231a to your computer and use it in GitHub Desktop.
Save grachov/5340aab7f43bb166231a to your computer and use it in GitHub Desktop.
Покупка товара в один клик для 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
Copy link

chayteam commented Jul 6, 2016

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

@EMDM45
Copy link

EMDM45 commented May 22, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment