-
-
Save webinmd/c4f875a3335ecc8cd93411b11772654b to your computer and use it in GitHub Desktop.
Изменение цены в зависимости от выбранных опций товара (miniShop2 + MODX Revolution).
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 | |
switch ($modx->event->name){ | |
case 'msOnBeforeAddToCart': | |
if (!is_array($options)) $options = json_decode($options, true); | |
//$modx->log(modX::LOG_LEVEL_ERROR, print_r($cart->get(), true)); | |
//$modx->log(modX::LOG_LEVEL_ERROR, print_r($product->toArray(), true)); | |
if(isset($options['size-price']) && !empty($options['size-price'])){ | |
$tvr = $modx->getObject('modTemplateVarResource', array( | |
'tmplvarid' => 53, | |
'contentid' => $product->id | |
)); | |
if ($tvr) { | |
$array = json_decode($tvr->get('value'), true); | |
$key = array_search($options['size-price'], array_column($array, 'size')); | |
$product->set('price', $array[$key]['price']); | |
} | |
} | |
if (isset($options['colors-price'])) { | |
$price = $product->get('price') + ($options['colors-price']); | |
$product->set('price', $price); | |
} | |
if (isset($options['colors-obivka-price'])) { | |
$price = $product->get('price') + ($options['colors-obivka-price']); | |
$product->set('price', $price); | |
} | |
if (isset($options['colors-legs-price'])) { | |
$price = $product->get('price') + ($options['colors-legs-price']); | |
$product->set('price', $price); | |
} | |
if (isset($options['complected-id'])) { | |
$items_complect = explode(',', $options['complected-id']); | |
$prices = 0; | |
foreach($items_complect as $item){ | |
$item = explode(':', $item); | |
$count = $item[1]; | |
$idgoods = $item[0]; | |
if($goods = $modx->getObject('msProduct', (int)$idgoods)){ | |
$data = $goods->getOne('Data'); | |
$price = $data->price * $count; | |
$prices = $prices + $price; | |
} | |
} | |
$price = $product->get('price') + $prices; | |
$product->set('price', $price); | |
} | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment