Created
July 10, 2017 08:25
-
-
Save Burick/0cf2da1a4e1d64bd74f9cac8fe0c0ece to your computer and use it in GitHub Desktop.
плагин подарков к минишопу
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
case "msOnBeforeAddToCart": | |
if (is_array($options) && array_key_exists('gift', $options) && !empty($options['gift'])) { | |
$items = $cart->get(); | |
foreach ($items as $item) { | |
if ($item['options']['gift'] && $item['id'] == $product->get('id')) { | |
$response = array( | |
'success' => false | |
,'message' => 'Этот товар уже добавлен в качестве подарка.' | |
); | |
exit(json_encode($response)); | |
} | |
} | |
$status = $cart->status(); | |
$price = $product->get('price'); | |
if (!is_array($_SESSION['gifts'])) { | |
$response = array( | |
'success' => false | |
,'message' => 'Нет доступных для выбора подарков.' | |
); | |
exit(json_encode($response)); | |
} | |
$gifts = $_SESSION['gifts']; | |
foreach ($gifts as $key => $val) { | |
if ($status['total_cost'] < $key) continue; | |
if ($status['total_cost'] >= $key && $is_gift = in_array($product->get('id'), explode(',', $val))) { | |
$options['threshold'] = $key; | |
break; | |
} | |
} | |
if (!$is_gift) { | |
$response = array( | |
'success' => false | |
,'message' => 'Этот товар сейчас недоступен для выбора в качестве подарка.' | |
); | |
exit(json_encode($response)); | |
} | |
$options['real_price'] = $price; | |
$product->set('price', 0); | |
$modx->event->returnedValues['options'] = $options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment