Last active
September 8, 2016 17:06
-
-
Save vgrish/b43356ddb5c0cfc9bc288e5f209fb3dd to your computer and use it in GitHub Desktop.
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 | |
public function change($key, $count, $options, $comment) | |
{ | |
if (array_key_exists($key, $this->cart)) { | |
if (isset($count) && !is_null($count) && $count <= 0) | |
return $this->remove($key); | |
else if(isset($count) && !is_null($count) && $count > 0) | |
{ | |
if ($count > $this->config['max_count']) { | |
return $this->error('ms2_cart_add_err_count', $this->status(), array('count' => $count)); | |
} | |
$response = $this->ms2->invokeEvent('msOnBeforeChangeInCart', | |
array('key' => $key, 'count' => $count, 'options' => $options, 'comment' => $comment, 'cart' => $this)); | |
if (!$response['success']) { | |
return $this->error($response['message']); | |
} | |
$price = $response['data']['price']; | |
$count = $response['data']['count']; | |
$this->cart[$key]['price'] = $price; | |
$this->cart[$key]['count'] = $count; | |
$response = $this->ms2->invokeEvent('msOnChangeInCart', | |
array('key' => $key, 'count' => $count, 'options' => $options, 'cart' => $this)); | |
if (!$response['success']) { | |
return $this->error($response['message']); | |
} | |
return $this->success('ms2_cart_change_success', $this->status(array('key' => $key)), array('count' => $count)); | |
} else { | |
if ($count > $this->config['max_count']) { | |
return $this->error('ms2_cart_add_err_count', $this->status(), array('count' => $count)); | |
} | |
$response = $this->ms2->invokeEvent('msOnBeforeChangeInCart', | |
array('key' => $key, 'count' => $count, 'options' => $options, 'comment' => $comment, 'cart' => $this)); | |
if (!$response['success']) { | |
return $this->error($response['message']); | |
} | |
$price = $response['data']['price']; | |
$this->cart[$key]['price'] = $price; | |
if(is_array($options)) | |
$this->cart[$key]['options'] = array_merge($this->cart[$key]['options'], $options); | |
if($comment) | |
$this->cart[$key]['comment'] = filter_var($comment, FILTER_SANITIZE_STRING); | |
$response = $this->ms2->invokeEvent('msOnChangeInCart', | |
array('key' => $key, 'count' => $count, 'options' => $options, 'cart' => $this)); | |
if (!$response['success']) { | |
return $this->error($response['message']); | |
} | |
return $this->success('ms2_cart_change_options_success', $this->status(array('key' => $key)), array('options' => $options)); | |
} | |
} else { | |
return $this->error('ms2_cart_change_error', $this->status(array())); | |
} | |
} |
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 | |
class msOptionsPriceMsOnBeforeChangeInCart extends msOptionsPricePlugin | |
{ | |
public function run() | |
{ | |
if ($this->modx->context->key == 'mgr') { | |
return; | |
} | |
$cartObj = $this->modx->getOption('cart', $this->scriptProperties); | |
$key = $this->modx->getOption('key', $this->scriptProperties); | |
$cart = $cartObj->get(); //returned array | |
$rid = $cart[$key]['id']; | |
$returned = (array)$this->modx->getPlaceholder('_returned'); | |
$options = (array)$this->modx->getOption('options', $this->scriptProperties, array(), true); | |
if (empty($options) AND $returned['id'] == $rid) { | |
$options = (array)$this->modx->getOption('options', $returned, array(), true); | |
} | |
else if (empty($options)) { | |
$options = (array)$this->modx->getOption('options', $_REQUEST, array(), true); | |
} | |
$price = $cart[$key]['price']; | |
$this->modx->event->returnedValues['price'] = $price; | |
$modification = $this->msoptionsprice->getModificationByOptions($rid, $options); | |
$cost = $this->msoptionsprice->getCostByModification($rid, $price, $modification); | |
if ($cost !== false) { | |
$returned['id'] = $rid; | |
$returned['options'] = $options; | |
$this->modx->event->returnedValues['price'] = $returned['price'] = $cost; | |
$this->modx->setPlaceholder('_returned', $returned); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment