-
-
Save TrywaR/62ed1c462cb344f1a4fa9beb0290fbfb to your computer and use it in GitHub Desktop.
Покупка товара в один клик для miniShop2
This file contains hidden or 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'))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment