From ee33a5fb40dcd798aed92e80ba544d91513f9881 Mon Sep 17 00:00:00 2001 From: DmitryZagorulko Date: Wed, 9 Aug 2017 12:03:12 +0300 Subject: [PATCH] correct generate icml (#16) --- retailcrm/job/export.php | 2 +- retailcrm/lib/RetailcrmCatalog.php | 32 ++++++++++++++++++++---------- retailcrm/lib/RetailcrmIcml.php | 9 ++++++--- retailcrm/retailcrm.php | 15 ++++++-------- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/retailcrm/job/export.php b/retailcrm/job/export.php index bd349b4..8bacdf7 100644 --- a/retailcrm/job/export.php +++ b/retailcrm/job/export.php @@ -32,7 +32,7 @@ foreach ($customerRecords as $record) { $customers[$record['id_customer']] = array( 'externalId' => $record['id_customer'], 'firstName' => $record['firstname'], - 'lastname' => $record['lastname'], + 'lastName' => $record['lastname'], 'email' => $record['email'] ); } diff --git a/retailcrm/lib/RetailcrmCatalog.php b/retailcrm/lib/RetailcrmCatalog.php index 2414979..bc55518 100644 --- a/retailcrm/lib/RetailcrmCatalog.php +++ b/retailcrm/lib/RetailcrmCatalog.php @@ -26,7 +26,7 @@ class RetailcrmCatalog $currencies = Currency::getCurrencies(); - $types = Category::getCategories($id_lang, true, false); + $types = Category::getCategories($id_lang, false, false); foreach ($types AS $category) { $categories[] = array( 'id' => $category['id_category'], @@ -106,9 +106,9 @@ class RetailcrmCatalog } else { $size = null; } - - $productForCombination = new Product($product['id_product']); - + + $productForCombination = new Product($product['id_product']); + $offers = Product::getProductAttributesIds($product['id_product']); if(!empty($offers)) { @@ -116,7 +116,7 @@ class RetailcrmCatalog $combinations = $productForCombination->getAttributeCombinationsById($offer['id_product_attribute' ], $id_lang); if (!empty($combinations)) { - + foreach ($combinations as $combination) { $arSet = array( 'group_name' => $combination['group_name'], @@ -126,6 +126,11 @@ class RetailcrmCatalog } } + if (!empty($combinations[0]['reference'])) { + $articleCombination = $combinations[0]['reference']; + } else { + $articleCombination = null; + } $pictures = array(); $covers = Image::getImages($id_lang, $product['id_product'], $offer['id_product_attribute']); foreach($covers as $cover) { @@ -140,7 +145,8 @@ class RetailcrmCatalog } $offerPrice = Combination::getPrice($offer['id_product_attribute']); - $offerPrice = $offerPrice > 0 ? $offerPrice : $price; + //$offerPrice = $offerPrice > 0 ? $offerPrice : $price; + $offerPrice = $offerPrice != 0 ? $offerPrice + $price : $price; $item = array( 'id' => $product['id_product'] . '#' . $offer['id_product_attribute'], @@ -155,9 +161,12 @@ class RetailcrmCatalog 'purchasePrice' => $purchasePrice, 'price' => round($offerPrice, 2), 'vendor' => $vendor, - 'article' => $article, + 'article' => ($articleCombination) ? $articleCombination : $article, 'weight' => $weight, - 'size' => $size + 'size' => $size, + 'width' => $width, + 'height' => $height, + 'depth' => $depth ); if (!empty($combinations)) { @@ -165,7 +174,7 @@ class RetailcrmCatalog $item[mb_strtolower($itemComb['group_name'])] = htmlspecialchars($itemComb['attribute']); } } - + $items[] = $item; } } else { @@ -197,7 +206,10 @@ class RetailcrmCatalog 'vendor' => $vendor, 'article' => $article, 'weight' => $weight, - 'size' => $size + 'size' => $size, + 'width' => $width, + 'height' => $height, + 'depth' => $depth ); $items[] = $item; diff --git a/retailcrm/lib/RetailcrmIcml.php b/retailcrm/lib/RetailcrmIcml.php index 8c72447..7dd540c 100644 --- a/retailcrm/lib/RetailcrmIcml.php +++ b/retailcrm/lib/RetailcrmIcml.php @@ -33,7 +33,10 @@ class RetailcrmIcml 'color' => 'Цвет', 'weight' => 'Вес', 'size' => 'Размер', - 'tax' => 'Наценка' + 'tax' => 'Наценка', + 'width' => 'Ширина', + 'height' => 'Высота', + 'depth' => 'Глубина' ); } @@ -75,14 +78,14 @@ class RetailcrmIcml foreach ($categories as $category) { $e = $this->eCategories->appendChild( $this->dd->createElement( - 'category', $category['name'] + 'category', htmlspecialchars($category['name']) ) ); $e->setAttribute('id', $category['id']); if ($category['parentId'] > 0) { - $e->setAttribute('parentId', $category['parentId']); + $e->setAttribute('parentId', htmlspecialchars($category['parentId'])); } } } diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index b257828..60f58b6 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -20,8 +20,7 @@ class RetailCRM extends Module { $this->name = 'retailcrm'; $this->tab = 'export'; - $this->version = '2.1.1'; - $this->version = '2.1'; + $this->version = '2.2'; $this->author = 'Retail Driver LCC'; $this->displayName = $this->l('RetailCRM'); $this->description = $this->l('Integration module for RetailCRM'); @@ -346,7 +345,7 @@ class RetailCRM extends Module $orderdb = new Order($params['order']->id); foreach ($orderdb->getProducts() as $item) { - if(isset($item['product_attribute_id']) && $item['product_attribute_id'] > 0) { + if (isset($item['product_attribute_id']) && $item['product_attribute_id'] > 0) { $productId = $item['product_id'] . '#' . $item['product_attribute_id']; } else { $productId = $item['product_id']; @@ -425,7 +424,7 @@ class RetailCRM extends Module } foreach ($cart->getProducts() as $item) { - if(isset($item['id_product_attribute']) && $item['id_product_attribute'] > 0) { + if (isset($item['id_product_attribute']) && $item['id_product_attribute'] > 0) { $productId = $item['id_product'] . '#' . $item['id_product_attribute']; } else { $productId = $item['id_product']; @@ -454,9 +453,7 @@ class RetailCRM extends Module 'properties' => $arProp ); - unset($arAttr); - unset($count); - unset($arProp); + unset($arAttr, $count, $arProp); } $deliveryCode = $params['order']->id_carrier; @@ -492,7 +489,7 @@ class RetailCRM extends Module $order['customer']['externalId'] = $customer['externalId']; $this->api->ordersCreate($order); - } elseif (isset($params['newOrderStatus'])){ + } elseif (isset($params['newOrderStatus'])) { $statusCode = $params['newOrderStatus']->id; @@ -514,7 +511,7 @@ class RetailCRM extends Module } private function validateCrmAddress($address) { - if(preg_match("/https:\/\/(.*).retailcrm.ru/", $address) === 1) + if (preg_match("/https:\/\/(.*).retailcrm.ru/", $address) === 1) return true; return false;