Created
June 4, 2014 13:10
-
-
Save grachov/5340aab7f43bb166231a to your computer and use it in GitHub Desktop.
Покупка товара в один клик для miniShop2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'))); |
Тоже интересно, как использовать данный код? Это обработчик формы? его нужно "навешивать" на action в форме "купить в 1 клик" ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Здравствуйте. Не силён в ms2, подскажите пожалуйста, как пользоваться данным сниппетом?