Created
July 3, 2017 10:24
-
-
Save vgrish/caf5fbe7f4230883419bb4763ec1e3d0 to your computer and use it in GitHub Desktop.
AMOCRM///
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 getProductOptions($options = array()) | |
{ | |
$this->modx->lexicon->load('minishop2:product'); | |
if (is_array($options)) { | |
unset($options['modification']); | |
unset($options['modifications']); | |
unset($options['msal']); | |
foreach ($options as $k => $v) { | |
/** @var msOption $msOption */ | |
if ($msOption = $this->modx->getObject('msOption', array('key' => $k))) { | |
$caption = $msOption->get('caption'); | |
} else { | |
$caption = $this->modx->lexicon('ms2_product_' . $k); | |
} | |
if (is_array($v)) { | |
$v = implode('; ', $v); | |
} | |
$options[$k] = $caption . ' - ' . $v; | |
} | |
$options = implode(PHP_EOL, $options); | |
} | |
return $options; | |
} | |
public function addOrder(msOrder & $order) | |
{ | |
if (!$this->config['pipeline']) { | |
if (!$this->addMiniShopPipeline()) { | |
$this->log('Error adding MS2 pipeline to AmoCRM'); | |
return false; | |
} | |
} | |
$goods = array(); | |
$i = 1; | |
/** @var msOrderProduct[] $products */ | |
$products = $order->getMany('Products'); | |
foreach ($products as $product) { | |
$goods[] = $this->modx->lexicon('amocrm_order_product_row', array( | |
'idx' => $i, | |
'name' => $product->get('name'), | |
'price' => $product->get('price'), | |
'count' => $product->get('count'), | |
'cost' => $product->get('cost'), | |
'options' => $this->getProductOptions($product->get('options')), | |
'currency' => $this->modx->lexicon('ms2_frontend_currency'), | |
'unit' => $this->modx->lexicon('ms2_frontend_count_unit'), | |
)); | |
$i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment