Экспорт товаров в XML Mail Torg Webasyst Shop-Script
Экспорт товаров Webasyst Shop-Script в XML файл для системы Mail.Torg Товары
Самый главный файл shopMailtorgPluginBackendRunAction.php в бэкэнде, настройки к нему можете сделать.
Это пример ( в конце статьи сможете скачать пример плагина для Webasyst Shop Script XML Export Mail Torg)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | <?php class shopMailtorgPluginBackendRunAction extends waViewAction { private function toxml() { $product_model = new shopProductModel(); $sql = 'SELECT * FROM shop_product sp WHERE sp.min_price!=0 AND sp.count!=0 AND status!=0 '; $skus = $product_model->query($sql)->fetchAll(); $ids = array(); if ($skus !== null) { $cfg_url = "https://адрес-ваше-сайта.ру"; $shopname = "Название сайта"; $company = "Описание сайта"; $xmltext = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; $xmltext .= "<torg_price date=\"" . date('Y-m-d H:i') . "\">\n"; $xmltext .= "<shop>\n"; $xmltext .= "<name>$shopname</name>\n"; $xmltext .= "<company>$company</company>\n"; $xmltext .= "<url>$cfg_url</url>\n"; $xmltext .= "<currencies> <currency id='RUB' rate='1'/> <currency id='USD' rate='CBRF'/> <currency id='EUR' rate='CBRF'/> </currencies>\n"; $xmltext .= "<offers>\n"; $ids = ""; foreach ($skus as $sku) { $url = $sku['url']; $stock = $sku['count']; $price = $sku['price']; $min_price = $sku['min_price']; $max_price = $sku['max_price']; $summary = $sku['summary']; $type_id = $sku['type_id']; if ($stock > 0) { $available = "true"; } else { $available = "false"; } $xmltext .= "<offer id=\"" . $sku['id'] . "\" available=\"$available\" cbid=\"10\">\n"; $xmltext .= "<url>" . $cfg_url . "/" . $url . ".html?utm_source=mailtorg</url>\n"; if ($min_price > 0) { $xmltext .= "<price>" . round($price, 0) . "</price>\n"; } else { $xmltext .= "<price>" . round($price, 0) . "</price>\n"; } $imageurl = $cfg_url . shopImage::getUrl( array( 'id' => $sku['image_id'], 'product_id' => $sku['id'], 'filename' => $sku['image_filename'], 'ext' => $sku['ext'], //расширение изображения (jpg, например) ), '600' ); $xmltext .= "<currencyId>RUB</currencyId>\n"; $xmltext .= "<categoryId></categoryId>\n"; $xmltext .= "<picture>$imageurl</picture>\n"; $xmltext .= "<typePrefix>$type</typePrefix>\n"; $xmltext .= "<name>" . $sku['name'] . "</name>\n"; $xmltext .= "<pickup>true</pickup>\n"; $xmltext .= "<store>true</store>\n"; $xmltext .= "<delivery>true</delivery>\n"; $xmltext .= "<local_delivery_cost>"; $xmltext .= "800"; $xmltext .= "</local_delivery_cost>\n"; $xmltext .= "<vendor></vendor>"; $xmltext .= "<sales_notes></sales_notes>\n"; $xmltext .= "<description>Цена . " . htmlspecialchars(strip_tags($summary)) . "</description>\n"; $xmltext .= ""; $xmltext .= "</offer>\n"; } $xmltext .= "</offers>\n"; $xmltext .= "</shop>\n"; $xmltext .= "</torg_price>\n"; } $xml = $xmltext; $xml_file = fopen('mailtorg.xml', 'w+'); if (!$xml_file) { echo 'Ошибка открытия файла'; } else { ftruncate($xml_file, 0); fputs($xml_file, $xml); } } public function execute() { $message = ''; $request = waRequest::post(); if ($request['options'] == 'toxml') { $this->toxml(); } $this->view->assign('message', empty($message) ? '{"status":"ok"}' : $message); } } |
Скачать плагин Webasyst XML Export Mail Torg (выгрузка товаров)
-> Download mailtorg export xml webasyst