From 13105700863788ac289dd4b2e398e2b508fdf7f3 Mon Sep 17 00:00:00 2001 From: fomichev Date: Tue, 22 Oct 2024 13:39:42 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B0?= =?utf8?q?=D0=BB=20=D1=84=D0=B8=D0=B4=20=D0=BF=D0=BE=20=D0=BF=D1=80=D0=B8?= =?utf8?q?=D0=BC=D0=B5=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/MarketplaceService.php | 85 +++++++++++++++------------ 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/erp24/services/MarketplaceService.php b/erp24/services/MarketplaceService.php index f9087c73..d895b830 100644 --- a/erp24/services/MarketplaceService.php +++ b/erp24/services/MarketplaceService.php @@ -47,7 +47,8 @@ class MarketplaceService 'weight' => self::getProductWeight($product->id), 'minorder' => self::getProductMinOrder($product->id), 'composition' => $composition, - 'available' => self::getProductAvailability($product->id) + 'available' => self::getProductAvailability($product->id), + 'category_id' => self::getProductCategory($product->id), ]; } @@ -97,7 +98,8 @@ class MarketplaceService 'weight' => self::getProductWeight($product->id), 'minorder' => self::getProductMinOrder($product->id), 'composition' => $composition, - 'available' => self::getProductAvailability($product->id) + 'available' => self::getProductAvailability($product->id), + 'category_id' => self::getProductCategory($product->id), ]; } @@ -113,68 +115,70 @@ class MarketplaceService public static function createXMLFeed($productsInfo) { $xml = new \SimpleXMLElement(''); - $xml->addAttribute('date', date('Y-m-d\TH:i:sP')); + $xml->addAttribute('date', date('Y-m-d H:i')); $shop = $xml->addChild('shop'); - $shop->addChild('name', 'База Цветов 24'); - $shop->addChild('company', 'База Цветов 24'); + $shop->addChild('name', 'Интернет магазин База Цветов 24'); + $shop->addChild('company', 'Интернет магазин База Цветов 24'); $shop->addChild('url', 'https://bazacvetov24.ru'); + $shop->addChild('platform', 'BSM/Yandex/Market'); // Добавление валюты $currencies = $shop->addChild('currencies'); $currency = $currencies->addChild('currency'); - $currency->addAttribute('id', 'RUR'); + $currency->addAttribute('id', 'RUB'); $currency->addAttribute('rate', '1'); - // Добавление категорий + // Добавление категорий (пример добавления нескольких категорий) $categories = $shop->addChild('categories'); - $category = $categories->addChild('category', 'Букеты'); - $category->addAttribute('id', '1'); - - // Добавление информации о доставке??? - $deliveryOptions = $shop->addChild('delivery-options'); - $deliveryOption = $deliveryOptions->addChild('option'); - $deliveryOption->addAttribute('cost', '200'); - $deliveryOption->addAttribute('days', '1'); + $category1 = $categories->addChild('category', 'Букеты'); + $category1->addAttribute('id', '1'); + $category2 = $categories->addChild('category', 'Аксессуары'); + $category2->addAttribute('id', '2'); // Добавление офферов (продуктов) $offers = $shop->addChild('offers'); foreach ($productsInfo as $product) { $offer = $offers->addChild('offer'); $offer->addAttribute('id', $product['id']); - $offer->addAttribute('available', false); - $offer->addChild('name', htmlspecialchars($product['name'])); - //TODO добавить url на конкректный букет - $offer->addChild('url', 'https://bazacvetov24.ru/flowers/' . $product['id']); + $offer->addAttribute('available', $product['available'] ? 'true' : 'false'); + + // Добавление URL продукта + $offer->addChild('url', 'https://bazacvetov24.ru/product/' . $product['id']); + + // Добавление цены и валюты $offer->addChild('price', $product['price']); - $offer->addChild('currencyId', 'RUR'); - $offer->addChild('categoryId', '1'); + $offer->addChild('currencyId', 'RUB'); + $offer->addChild('categoryId', $product['category_id']); // Здесь нужно указать правильный ID категории для продукта + + // Добавление доступности доставки $offer->addChild('delivery', 'true'); - // Информация о доставке для каждого оффера - $offerDeliveryOptions = $offer->addChild('delivery-options'); - $offerDeliveryOption = $offerDeliveryOptions->addChild('option'); - $offerDeliveryOption->addAttribute('cost', '300'); - $offerDeliveryOption->addAttribute('days', '1'); - $offerDeliveryOption->addAttribute('order-before', '18'); + // Описание продукта + if (!empty($product['description'])) { + $offer->addChild('description', htmlspecialchars($product['description'])); + } - $offer->addChild('description', htmlspecialchars($product['description'])); + // Добавление веса и количества $offer->addChild('weight', $product['weight']); $offer->addChild('qty', $product['qty']); - $offer->addChild('minorder', $product['minorder']); - $offer->addChild('available', $product['available'] ? 'true' : 'false'); - if ($product['oldprice']) { - $offer->addChild('oldprice', $product['oldprice']); + // Добавление параметров + if (!empty($product['params'])) { + foreach ($product['params'] as $paramName => $paramValue) { + $param = $offer->addChild('param', htmlspecialchars($paramValue)); + $param->addAttribute('name', htmlspecialchars($paramName)); + } } - foreach ($product['composition'] as $component) { - $consist = $offer->addChild('consist', $component['quantity']); - $consist->addAttribute('name', htmlspecialchars($component['name'])); - $consist->addAttribute('unit', $component['unit']); - } - foreach ($product['pictures'] as $picture) { - $offer->addChild('picture', $picture); + // Название продукта + $offer->addChild('name', htmlspecialchars($product['name'])); + + // Добавление изображений продукта + if (!empty($product['pictures'])) { + foreach ($product['pictures'] as $picture) { + $offer->addChild('picture', $picture); + } } } @@ -203,6 +207,9 @@ class MarketplaceService private static function getProductWeight($productId) { return null; } + private static function getProductCategory($productId) { + return 1; + } private static function getProductMinOrder($productId) { return 1; } -- 2.39.5