'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),
];
}
'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),
];
}
public static function createXMLFeed($productsInfo)
{
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><yml_catalog/>');
- $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', 'Ð\98нÑ\82еÑ\80неÑ\82 магазин Ð\91аза ЦвеÑ\82ов 24');
+ $shop->addChild('company', 'Ð\98нÑ\82еÑ\80неÑ\82 магазин Ð\91аза ЦвеÑ\82ов 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);
+ }
}
}
private static function getProductWeight($productId) {
return null;
}
+ private static function getProductCategory($productId) {
+ return 1;
+ }
private static function getProductMinOrder($productId) {
return 1;
}