fix create orders (#7)

* [productId] replace to [offer][externalId]
* properties for items in order and in icml
This commit is contained in:
DmitryZagorulko 2017-03-21 12:46:37 +04:00 committed by Alex Lushpai
parent b61379cabc
commit 6eed3ad0e7
3 changed files with 44 additions and 4 deletions

View File

@ -143,7 +143,8 @@ $products = $orderInstance->getProducts();
foreach($products as $product) { foreach($products as $product) {
$item = array( $item = array(
'productId' => $product['product_id'], //'productId' => $product['product_id'],
'offer' => array('externalId' => $product['product_id']),
'productName' => $product['product_name'], 'productName' => $product['product_name'],
'quantity' => $product['product_quantity'], 'quantity' => $product['product_quantity'],
'initialPrice' => round($product['product_price'], 2), 'initialPrice' => round($product['product_price'], 2),

View File

@ -106,10 +106,25 @@ class RetailcrmCatalog
$size = null; $size = null;
} }
$productForCombination = new Product($product['id_product']);
$offers = Product::getProductAttributesIds($product['id_product']); $offers = Product::getProductAttributesIds($product['id_product']);
if(!empty($offers)) { if(!empty($offers)) {
foreach($offers as $offer) { foreach($offers as $offer) {
$combinations = $productForCombination->getAttributeCombinationsById($offer['id_product_attribute' ], $id_lang);
if (!empty($combinations)) {
foreach ($combinations as $combination) {
$arSet = array(
'group_name' => $combination['group_name'],
'attribute' => $combination['attribute_name'],
);
$arComb[] = $arSet;
}
}
$pictures = array(); $pictures = array();
$covers = Image::getImages($id_lang, $product['id_product'], $offer['id_product_attribute']); $covers = Image::getImages($id_lang, $product['id_product'], $offer['id_product_attribute']);
foreach($covers as $cover) { foreach($covers as $cover) {
@ -144,6 +159,12 @@ class RetailcrmCatalog
'size' => $size 'size' => $size
); );
if (!empty($combinations)) {
foreach ($arComb as $itemComb) {
$item[mb_strtolower($itemComb['group_name'])] = htmlspecialchars($itemComb['attribute']);
}
}
$items[] = $item; $items[] = $item;
} }
} else { } else {

View File

@ -351,15 +351,33 @@ class RetailCRM extends Module
$productId = $item['id_product']; $productId = $item['id_product'];
} }
if ($item['attributes']) {
$arProp = array();
$count = 0;
$arAttr = explode(",", $item['attributes']);
foreach ($arAttr as $valAttr) {
$arItem = explode(":", $valAttr);
$arProp[$count]['name'] = trim($arItem[0]);
$arProp[$count]['value'] = trim($arItem[1]);
$count++;
}
}
$order['items'][] = array( $order['items'][] = array(
'initialPrice' => !empty($item['rate']) 'initialPrice' => !empty($item['rate'])
? $item['price'] + ($item['price'] * $item['rate'] / 100) ? $item['price'] + ($item['price'] * $item['rate'] / 100)
: $item['price'] : $item['price']
, ,
'quantity' => $item['quantity'], 'quantity' => $item['quantity'],
'productId' => $productId, 'offer' => array('externalId' => $productId),
'productName' => $item['name'] 'productName' => $item['name'],
'properties' => $arProp
); );
unset($arAttr);
unset($count);
unset($arProp);
} }
$deliveryCode = $params['order']->id_carrier; $deliveryCode = $params['order']->id_carrier;