Skip to content

Instantly share code, notes, and snippets.

@vgrish

vgrish/tmp.php

Created Jul 3, 2017
Embed
What would you like to do?
AMOCRM///
<?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