From: fomichev Date: Tue, 22 Oct 2024 10:39:42 +0000 (+0300) Subject: Переделал фид по примеру X-Git-Tag: 1.6~13^2~44 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=13105700863788ac289dd4b2e398e2b508fdf7f3;p=erp24_rep%2Fyii-erp24%2F.git Переделал фид по примеру --- 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; }