From e5bd5f6adc4b55d37e4dc4899750f58d7d39725e Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Tue, 25 Dec 2018 13:31:07 +0300 Subject: [PATCH] v2.2.8 --- CHANGELOG.md | 17 +++++++------ VERSION | 2 +- retailcrm/lib/RetailcrmCatalog.php | 38 ++++++++++++++++++----------- retailcrm/lib/RetailcrmHistory.php | 19 +++++++++------ retailcrm/lib/RetailcrmIcml.php | 25 +++++++++++-------- tests/helpers/RetailcrmTestCase.php | 2 +- tests/phpunit/bootstrap.php | 7 +++++- 7 files changed, 68 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a83da2..b8bd3fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,27 +1,30 @@ -## v.2.2.7 +## v2.2.8 +* Добавлена выгрузка картинок категорий товаров в ICML + +## v2.2.7 * Добавлена отправка адреса клиента при обновлении покупателя на стороне сайта * Добавлены методы получения адреса и телефона -## v.2.2.6 +## v2.2.6 * Добавлена активация модуля в маркетплейсе retailCRM -## v.2.2.5 +## v2.2.5 * Добавлена передача страны при создании заказа для пользователя и заказа * Добавлен метод сохранения сущностей с обработкой исключений -## v.2.2.4 +## v2.2.4 * Добавлена установка дефолтной валюты для оплаты при получении истории * Добавлено получение суммы оплаты из заказа в CMS, если она не передается по истории -## v.2.2.3 +## v2.2.3 * добавлена обработка исключений при обновлении пользователя на стороне CMS -## v.2.2.2 +## v2.2.2 * Добавлена передача комментария клиента при создании заказа * Добавлена передача дополнительного номера телефона в заказе и клиенте при создании заказа * Добавлен перевод на испанкий язык -## v.2.2.0 +## v2.2.0 * Добавлена выгрузка истории изменений по клиентам * Добавлена проверка имени и значения свойств товара перед отправкой заказа * Выгрузка изменений из СРМ теперь происходит по идетификатору истории diff --git a/VERSION b/VERSION index 5bc1cc4..23a63f5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.7 +2.2.8 diff --git a/retailcrm/lib/RetailcrmCatalog.php b/retailcrm/lib/RetailcrmCatalog.php index 15b9bbd..57952c9 100644 --- a/retailcrm/lib/RetailcrmCatalog.php +++ b/retailcrm/lib/RetailcrmCatalog.php @@ -28,18 +28,20 @@ class RetailcrmCatalog } $currencies = Currency::getCurrencies(); - + $link = new Link(); $types = Category::getCategories($id_lang, true, false); - foreach ($types AS $category) { + + foreach ($types as $category) { + $picture = $link->getCatImageLink($category['link_rewrite'], $category['id_category'], 'category_default'); + $categories[] = array( 'id' => $category['id_category'], 'parentId' => $category['id_parent'], - 'name' => $category['name'] + 'name' => $category['name'], + 'picture' => $picture ? $protocol . $picture : '' ); } - $link = new Link(); - $products = Product::getProducts($id_lang, 0, 0, 'name', 'asc'); foreach ($products AS $product) { @@ -59,6 +61,7 @@ class RetailcrmCatalog } $version = substr(_PS_VERSION_, 0, 3); + if ($version == "1.3") { $available_for_order = $product['active'] && $product['quantity']; } else { @@ -114,28 +117,35 @@ class RetailcrmCatalog $offers = Product::getProductAttributesIds($product['id_product']); - if(!empty($offers)) { + if (!empty($offers)) { foreach($offers as $offer) { - $combinations = $productForCombination->getAttributeCombinationsById($offer['id_product_attribute' ], $id_lang); - if (!empty($combinations)) { + if (!empty($combinations)) { foreach ($combinations as $combination) { - $arSet = array( - 'group_name' => $combination['group_name'], - 'attribute' => $combination['attribute_name'], - ); - $arComb[] = $arSet; + $arSet = array( + 'group_name' => $combination['group_name'], + 'attribute' => $combination['attribute_name'], + ); + + $arComb[] = $arSet; } } $pictures = array(); $covers = Image::getImages($id_lang, $product['id_product'], $offer['id_product_attribute']); - foreach($covers as $cover) { + + foreach ($covers as $cover) { $picture = $protocol . $link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $cover['id_image'], 'large_default'); $pictures[] = $picture; } + if (!$pictures) { + $image = Image::getCover($product['id_product']); + $picture = $protocol . $link->getImageLink($product['link_rewrite'], $image['id_image'], 'large_default'); + $pictures[] = $picture; + } + if ($version == "1.3") { $quantity = $product['quantity']; } else { diff --git a/retailcrm/lib/RetailcrmHistory.php b/retailcrm/lib/RetailcrmHistory.php index eec50a6..aa53a7d 100644 --- a/retailcrm/lib/RetailcrmHistory.php +++ b/retailcrm/lib/RetailcrmHistory.php @@ -50,10 +50,9 @@ class RetailcrmHistory $customer->email = $customerHistory['email']; } - if (self::loadInCMS($customer, 'update') === false){ + if (self::loadInCMS($customer, 'update') === false) { continue; } - } else { $customer = new Customer(); @@ -112,7 +111,6 @@ class RetailcrmHistory if (self::loadInCMS($customerAddress, 'add') === false) { continue; } - } $customerFix[] = array( @@ -466,7 +464,6 @@ class RetailcrmHistory $carrier->id_carrier = $deliveryType; $carrier->shipping_cost_tax_excl = $order['delivery']['cost']; $carrier->shipping_cost_tax_incl = $order['delivery']['cost']; - $carrier->date_add = isset($order['delivery']['date']) ? $order['delivery']['date'] : ''; $carrier->add(false, false); /* @@ -479,7 +476,6 @@ class RetailcrmHistory */ $orderDetail = new OrderDetail(); $orderDetail->createList($newOrder, $cart, $newOrder->current_state, $product_list); - $orderDetail->save(); if (!empty($customerFix)) { self::$api->customersFixExternalIds($customerFix); @@ -705,6 +701,7 @@ class RetailcrmHistory $productName = htmlspecialchars(strip_tags($product->name)); $productPrice = $product->price; } + // discount if ((isset($newItem['discount']) && $newItem['discount']) || (isset($newItem['discountPercent']) && $newItem['discountPercent']) @@ -715,6 +712,7 @@ class RetailcrmHistory $productPrice = $productPrice - ($prodPrice / 100 * $newItem['discountPercent']); $ItemDiscount = true; } + $orderDetail = new OrderDetail(); $orderDetail->id_order = $orderToUpdate->id; $orderDetail->id_order_invoice = $orderToUpdate->invoice_number; @@ -737,6 +735,12 @@ class RetailcrmHistory } } + $infoOrd = self::$api->ordersGet($order['externalId']); + $infoOrder = $infoOrd->order; + $totalPaid = $infoOrder['totalSumm']; + $orderToUpdate->total_paid = $totalPaid; + $orderToUpdate->update(); + /* * Fix prices & discounts * Discounts only for whole order @@ -747,17 +751,16 @@ class RetailcrmHistory || isset($order['discountTotal']) || $ItemDiscount ) { - $infoOrd = self::$api->ordersGet($order['externalId']); - $infoOrder = $infoOrd->order; $orderTotalProducts = $infoOrder['summ']; - $totalPaid = $infoOrder['totalSumm']; $deliveryCost = $infoOrder['delivery']['cost']; $totalDiscount = $deliveryCost + $orderTotalProducts - $totalPaid; $orderCartRules = $orderToUpdate->getCartRules(); + foreach ($orderCartRules as $valCartRules) { $order_cart_rule = new OrderCartRule($valCartRules['id_order_cart_rule']); $order_cart_rule->delete(); } + $orderToUpdate->total_discounts = $totalDiscount; $orderToUpdate->total_discounts_tax_incl = $totalDiscount; $orderToUpdate->total_discounts_tax_excl = $totalDiscount; diff --git a/retailcrm/lib/RetailcrmIcml.php b/retailcrm/lib/RetailcrmIcml.php index 930ab44..77b7f84 100644 --- a/retailcrm/lib/RetailcrmIcml.php +++ b/retailcrm/lib/RetailcrmIcml.php @@ -49,7 +49,7 @@ class RetailcrmIcml '; $xml = new SimpleXMLElement( - $string, LIBXML_NOENT | LIBXML_NOCDATA | LIBXML_COMPACT | LIBXML_PARSEHUGE + $string, LIBXML_NOENT | LIBXML_NOCDATA | LIBXML_COMPACT | LIBXML_PARSEHUGE ); $this->dd = new DOMDocument(); @@ -58,9 +58,9 @@ class RetailcrmIcml $this->dd->loadXML($xml->asXML()); $this->eCategories = $this->dd - ->getElementsByTagName('categories')->item(0); + ->getElementsByTagName('categories')->item(0); $this->eOffers = $this->dd - ->getElementsByTagName('offers')->item(0); + ->getElementsByTagName('offers')->item(0); $this->addCategories($categories); $this->addOffers($offers); @@ -73,12 +73,17 @@ class RetailcrmIcml { foreach ($categories as $category) { $e = $this->eCategories->appendChild( - $this->dd->createElement( - 'category', $category['name'] - ) + $this->dd->createElement( + 'category' + ) ); $e->setAttribute('id', $category['id']); + $e->appendChild($this->dd->createElement('name', $category['name'])); + + if ($category['picture']) { + $e->appendChild($this->dd->createElement('picture', $category['picture'])); + } if ($category['parentId'] > 0) { $e->setAttribute('parentId', $category['parentId']); @@ -91,7 +96,7 @@ class RetailcrmIcml foreach ($offers as $offer) { $e = $this->eOffers->appendChild( - $this->dd->createElement('offer') + $this->dd->createElement('offer') ); $e->setAttribute('id', $offer['id']); @@ -105,14 +110,14 @@ class RetailcrmIcml foreach ($offer['categoryId'] as $categoryId) { $e->appendChild( - $this->dd->createElement('categoryId', $categoryId) + $this->dd->createElement('categoryId', $categoryId) ); } $offerKeys = array_keys($offer); foreach ($offerKeys as $key) { - if($offer[$key] == null) continue; + if ($offer[$key] == null) continue; if (in_array($key, $this->properties)) { if(is_array($offer[$key])) { @@ -137,7 +142,7 @@ class RetailcrmIcml $param->setAttribute('code', $key); $param->setAttribute('name', $this->params[$key]); $param->appendChild( - $this->dd->createTextNode($offer[$key]) + $this->dd->createTextNode($offer[$key]) ); $e->appendChild($param); } diff --git a/tests/helpers/RetailcrmTestCase.php b/tests/helpers/RetailcrmTestCase.php index b244ad2..fd242bb 100644 --- a/tests/helpers/RetailcrmTestCase.php +++ b/tests/helpers/RetailcrmTestCase.php @@ -9,7 +9,7 @@ abstract class RetailcrmTestCase extends \PHPUnit\Framework\TestCase parent::setUp(); if (version_compare(_PS_VERSION_, '1.7', '>')) { - $contextMocker = new \Tests\Unit\ContextMocker(); + $contextMocker = new \LegacyTests\Unit\ContextMocker(); $this->contextMock = $contextMocker->mockContext(); } } diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index 56326c3..d96e7f1 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -1,6 +1,11 @@