Version Notes
1. Выгрузка товаров: System -> Import/Export -> Yandex Market
2. Для выборочной выгрузки выбрать "Export only marked"
3. products.xml будет сгенерирован в корневой директории
Download this release
Release Info
| Developer | Gurusmart.ru |
| Extension | YMLExportYandexMarket |
| Version | 1.0.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0.0
- app/code/local/Gurusmart/YandexMarket/Block/Adminhtml/Export.php +41 -0
- app/code/local/Gurusmart/YandexMarket/Helper/Data.php +13 -0
- app/code/local/Gurusmart/YandexMarket/controllers/Adminhtml/IndexController.php +167 -0
- app/code/local/Gurusmart/YandexMarket/etc/config.xml +56 -0
- app/code/local/Gurusmart/YandexMarket/sql/gmyandexmarket_setup/install-0.0.1.php +33 -0
- app/etc/modules/Gurusmart_YandexMarket.xml +9 -0
- package.xml +20 -0
app/code/local/Gurusmart/YandexMarket/Block/Adminhtml/Export.php
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Gurusmart_YandexMarket_Block_Adminhtml_Export extends Mage_Adminhtml_Block_Abstract
|
| 4 |
+
{
|
| 5 |
+
protected function _toHtml()
|
| 6 |
+
{
|
| 7 |
+
$helper = Mage::helper('Gurusmart_YandexMarket');
|
| 8 |
+
$actionUrl = Mage::helper('adminhtml')->getUrl('*/*/export');
|
| 9 |
+
|
| 10 |
+
$formCode = <<<HTML
|
| 11 |
+
<style type="text/css">
|
| 12 |
+
div.form-row {
|
| 13 |
+
padding-bottom: 4px;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
div.form-row div.label {
|
| 17 |
+
float: left;
|
| 18 |
+
width: 10%;
|
| 19 |
+
}
|
| 20 |
+
</style>
|
| 21 |
+
<form id="export" action="{$actionUrl}">
|
| 22 |
+
<div class="form-row">
|
| 23 |
+
<div class="label">
|
| 24 |
+
<label for="export-marked">{$helper->__('Export only marked')}</label>
|
| 25 |
+
</div>
|
| 26 |
+
<div class="input">
|
| 27 |
+
<input id="export-marked" type="checkbox" name="export-marked">
|
| 28 |
+
</div>
|
| 29 |
+
</div>
|
| 30 |
+
<div class="form-row">
|
| 31 |
+
<div class="label"> </div>
|
| 32 |
+
<div class="input">
|
| 33 |
+
<input type="submit" value="{$helper->__('Submit')}">
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
</form>
|
| 37 |
+
HTML;
|
| 38 |
+
|
| 39 |
+
return $formCode;
|
| 40 |
+
}
|
| 41 |
+
}
|
app/code/local/Gurusmart/YandexMarket/Helper/Data.php
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Class Gurusmart_YandexMarket_Helper_Data
|
| 5 |
+
*
|
| 6 |
+
* Helper dummy
|
| 7 |
+
*
|
| 8 |
+
* @author Yegor Chuperka <ychuperka@gmail.com>
|
| 9 |
+
*/
|
| 10 |
+
class Gurusmart_YandexMarket_Helper_Data extends Mage_Core_Helper_Abstract
|
| 11 |
+
{
|
| 12 |
+
|
| 13 |
+
}
|
app/code/local/Gurusmart/YandexMarket/controllers/Adminhtml/IndexController.php
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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| 7 |
+
$this->loadLayout();
|
| 8 |
+
|
| 9 |
+
$formExportBlock = $this->getLayout()
|
| 10 |
+
->createBlock('Gurusmart_YandexMarket/adminhtml_export');
|
| 11 |
+
$this->_addContent($formExportBlock);
|
| 12 |
+
|
| 13 |
+
$this->renderLayout();
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
public function exportAction()
|
| 18 |
+
{
|
| 19 |
+
// Check request
|
| 20 |
+
$exportOnlyMarked = $this->getRequest()->getParam('export-marked', null) === 'on';
|
| 21 |
+
|
| 22 |
+
// Result array
|
| 23 |
+
$result = array(
|
| 24 |
+
'shop_data' => array(
|
| 25 |
+
'name' => Mage::getModel('core/store')->load(1)->getName(),
|
| 26 |
+
'url' => Mage::app()->getStore()->getUrl(),
|
| 27 |
+
)
|
| 28 |
+
);
|
| 29 |
+
|
| 30 |
+
// Attributes to select (for products collection)
|
| 31 |
+
$attributesToSelect = array(
|
| 32 |
+
'sku',
|
| 33 |
+
'price',
|
| 34 |
+
'name',
|
| 35 |
+
'manufacturer',
|
| 36 |
+
'url_key',
|
| 37 |
+
'short_description',
|
| 38 |
+
'image',
|
| 39 |
+
'country_of_manufacture'
|
| 40 |
+
);
|
| 41 |
+
|
| 42 |
+
// Get current currency code
|
| 43 |
+
$currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
|
| 44 |
+
|
| 45 |
+
// Get categories collection
|
| 46 |
+
$categories = Mage::getModel('catalog/category')
|
| 47 |
+
->getCollection()
|
| 48 |
+
->setOrder('entity_id', 'DESC')
|
| 49 |
+
->addAttributeToSelect('name');
|
| 50 |
+
|
| 51 |
+
// Array of product ids to control uniq
|
| 52 |
+
$productIds = array();
|
| 53 |
+
|
| 54 |
+
// For each category do
|
| 55 |
+
foreach ($categories as $_category) {
|
| 56 |
+
|
| 57 |
+
// Put category data into result array
|
| 58 |
+
$result['categories'][] = array(
|
| 59 |
+
'id' => $_category->getId(),
|
| 60 |
+
'parent_id' => $_category->getParentId(),
|
| 61 |
+
'name' => $_category->getName()
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
// Get products collection and add attributes to select
|
| 65 |
+
$products = $_category->getProductCollection()
|
| 66 |
+
->joinField(
|
| 67 |
+
'qty',
|
| 68 |
+
'cataloginventory/stock_item',
|
| 69 |
+
'qty',
|
| 70 |
+
'product_id=entity_id',
|
| 71 |
+
'{{table}}.stock_id=1',
|
| 72 |
+
'left'
|
| 73 |
+
);
|
| 74 |
+
foreach ($attributesToSelect as $ats) {
|
| 75 |
+
$products->addAttributeToSelect($ats);
|
| 76 |
+
}
|
| 77 |
+
if ($exportOnlyMarked) {
|
| 78 |
+
$products->addAttributeToFilter('xml_export', array('Yes' => true));
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
// For each product do
|
| 82 |
+
foreach ($products as $_product) {
|
| 83 |
+
|
| 84 |
+
// Check uniq
|
| 85 |
+
if (in_array($_product->getId(), $productIds)) {
|
| 86 |
+
continue;
|
| 87 |
+
} else {
|
| 88 |
+
$productIds[] = $_product->getId();
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// Try to get picture path
|
| 92 |
+
$image = $_product->getImage();
|
| 93 |
+
if ($image === 'no_selection') {
|
| 94 |
+
$picUrl = null;
|
| 95 |
+
} else {
|
| 96 |
+
$picUrl = (string)Mage::helper('catalog/image')->init($_product, 'image')->resize(210);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
// Save product data into result array
|
| 100 |
+
$result['products'][] = array(
|
| 101 |
+
'id' => $_product->getId(),
|
| 102 |
+
'qty' => $_product->getQty(),
|
| 103 |
+
'url' => str_replace('/index.php', null, $result['shop_data']['url']) . $_product->getUrlKey(),
|
| 104 |
+
'price' => $_product->getPrice(),
|
| 105 |
+
'currencyId' => $currencyCode,
|
| 106 |
+
'categoryId' => $_category->getId(),
|
| 107 |
+
'picture' => $picUrl,
|
| 108 |
+
'name' => $_product->getName(),
|
| 109 |
+
'vendor' => trim($_product->getAttributeText('manufacturer')),
|
| 110 |
+
'vendorCode' => $_product->getSku(),
|
| 111 |
+
'description' => trim(strip_tags($_product->getShortDescription())),
|
| 112 |
+
'country_of_origin' => trim($_product->getAttributeText('country_of_manufacture')),
|
| 113 |
+
);
|
| 114 |
+
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
// Process data on remote server
|
| 120 |
+
if (($response = $this->_processOnRemoteServer($result))) {
|
| 121 |
+
|
| 122 |
+
// Success
|
| 123 |
+
$this->_getSession()->addSuccess($this->__('Data successfully exported'));
|
| 124 |
+
|
| 125 |
+
// Write response into file
|
| 126 |
+
$path = Mage::getBaseDir('base') . DS . 'products.xml';
|
| 127 |
+
if (!file_put_contents($path, $response)) {
|
| 128 |
+
|
| 129 |
+
$this->_getSession()->addError(
|
| 130 |
+
$this->__('Can`t write to products.xml')
|
| 131 |
+
);
|
| 132 |
+
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
} else {
|
| 136 |
+
|
| 137 |
+
// Error occured
|
| 138 |
+
$this->_getSession()->addError($this->__('Can`t process data on remote server'));
|
| 139 |
+
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
$this->_redirect('*/*');
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
private function _processOnRemoteServer(array $result)
|
| 146 |
+
{
|
| 147 |
+
$context = stream_context_create(
|
| 148 |
+
array(
|
| 149 |
+
'http' => array(
|
| 150 |
+
'method' => 'POST',
|
| 151 |
+
'header' => 'Content-Type: application/x-www-form-urlencoded' . PHP_EOL,
|
| 152 |
+
'content' => http_build_query(
|
| 153 |
+
array(
|
| 154 |
+
'data' => base64_encode(gzencode(serialize($result), $level = 6))
|
| 155 |
+
)
|
| 156 |
+
)
|
| 157 |
+
)
|
| 158 |
+
)
|
| 159 |
+
);
|
| 160 |
+
|
| 161 |
+
return file_get_contents(
|
| 162 |
+
$file = 'http://gurusmart.ru/converter/convert.php',
|
| 163 |
+
$use_include_path = false,
|
| 164 |
+
$context
|
| 165 |
+
);
|
| 166 |
+
}
|
| 167 |
+
}
|
app/code/local/Gurusmart/YandexMarket/etc/config.xml
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" ?>
|
| 2 |
+
<config>
|
| 3 |
+
<global>
|
| 4 |
+
<helpers>
|
| 5 |
+
<Gurusmart_YandexMarket>
|
| 6 |
+
<class>Gurusmart_YandexMarket_Helper</class>
|
| 7 |
+
</Gurusmart_YandexMarket>
|
| 8 |
+
</helpers>
|
| 9 |
+
<blocks>
|
| 10 |
+
<Gurusmart_YandexMarket>
|
| 11 |
+
<class>Gurusmart_YandexMarket_Block</class>
|
| 12 |
+
</Gurusmart_YandexMarket>
|
| 13 |
+
</blocks>
|
| 14 |
+
<resources>
|
| 15 |
+
<gmyandexmarket_setup>
|
| 16 |
+
<setup>
|
| 17 |
+
<module>Gurusmart_YandexMarket</module>
|
| 18 |
+
<class>Mage_Catalog_Model_Resource_Setup</class>
|
| 19 |
+
</setup>
|
| 20 |
+
</gmyandexmarket_setup>
|
| 21 |
+
</resources>
|
| 22 |
+
</global>
|
| 23 |
+
<modules>
|
| 24 |
+
<Gurusmart_YandexMarket>
|
| 25 |
+
<version>0.0.1</version>
|
| 26 |
+
</Gurusmart_YandexMarket>
|
| 27 |
+
</modules>
|
| 28 |
+
<admin>
|
| 29 |
+
<routers>
|
| 30 |
+
<gmyandexmarket>
|
| 31 |
+
<use>admin</use>
|
| 32 |
+
<args>
|
| 33 |
+
<module>Gurusmart_YandexMarket</module>
|
| 34 |
+
<frontName>yandexmarket_admin</frontName>
|
| 35 |
+
</args>
|
| 36 |
+
</gmyandexmarket>
|
| 37 |
+
</routers>
|
| 38 |
+
</admin>
|
| 39 |
+
<adminhtml>
|
| 40 |
+
<menu>
|
| 41 |
+
<system>
|
| 42 |
+
<children>
|
| 43 |
+
<convert>
|
| 44 |
+
<children>
|
| 45 |
+
<gmyandexmarket module="Gurusmart_YandexMarket">
|
| 46 |
+
<title>Yandex Market</title>
|
| 47 |
+
<sort_order>65</sort_order>
|
| 48 |
+
<action>yandexmarket_admin/adminhtml_index</action>
|
| 49 |
+
</gmyandexmarket>
|
| 50 |
+
</children>
|
| 51 |
+
</convert>
|
| 52 |
+
</children>
|
| 53 |
+
</system>
|
| 54 |
+
</menu>
|
| 55 |
+
</adminhtml>
|
| 56 |
+
</config>
|
app/code/local/Gurusmart/YandexMarket/sql/gmyandexmarket_setup/install-0.0.1.php
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
$installer = $this;
|
| 4 |
+
|
| 5 |
+
$installer->startSetup();
|
| 6 |
+
|
| 7 |
+
$installer->addAttribute(
|
| 8 |
+
'catalog_product',
|
| 9 |
+
'xml_export',
|
| 10 |
+
array(
|
| 11 |
+
'group' => 'General',
|
| 12 |
+
'backend' => '',
|
| 13 |
+
'frontend' => '',
|
| 14 |
+
'class' => '',
|
| 15 |
+
'default' => '',
|
| 16 |
+
'label' => 'Yandex Market',
|
| 17 |
+
'type' => 'int',
|
| 18 |
+
'input' => 'boolean',
|
| 19 |
+
'source' => '',
|
| 20 |
+
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
|
| 21 |
+
'visible' => 1,
|
| 22 |
+
'required' => 0,
|
| 23 |
+
'searchable' => 0,
|
| 24 |
+
'filterable' => 1,
|
| 25 |
+
'unique' => 0,
|
| 26 |
+
'comparable' => 0,
|
| 27 |
+
'visible_on_front' => 0,
|
| 28 |
+
'is_html_allowed_on_front' => 0,
|
| 29 |
+
'user_defined' => 1,
|
| 30 |
+
)
|
| 31 |
+
);
|
| 32 |
+
|
| 33 |
+
$installer->endSetup();
|
app/etc/modules/Gurusmart_YandexMarket.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" ?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Gurusmart_YandexMarket>
|
| 5 |
+
<active>true</active>
|
| 6 |
+
<codePool>local</codePool>
|
| 7 |
+
</Gurusmart_YandexMarket>
|
| 8 |
+
</modules>
|
| 9 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>YMLExportYandexMarket</name>
|
| 4 |
+
<version>1.0.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license>GPL</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>Magento extension to generate Yandex.Market YML feed</summary>
|
| 10 |
+
<description>Magento extension to generate Yandex.Market YML feed</description>
|
| 11 |
+
<notes>1. Выгрузка товаров: System -> Import/Export -> Yandex Market
|
| 12 |
+
2. Для выборочной выгрузки выбрать "Export only marked"
|
| 13 |
+
3. products.xml будет сгенерирован в корневой директории</notes>
|
| 14 |
+
<authors><author><name>Gurusmart.ru</name><user>mit686</user><email>info@gurusmart.ru</email></author></authors>
|
| 15 |
+
<date>2014-05-23</date>
|
| 16 |
+
<time>17:29:30</time>
|
| 17 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Gurusmart_YandexMarket.xml" hash="8a3364501cd3951d9c13c1fcdf063a7b"/></dir></target><target name="magelocal"><dir name="Gurusmart"><dir name="YandexMarket"><dir name="Block"><dir name="Adminhtml"><file name="Export.php" hash="3736651ce4b019bb8b3ea8d6027c97dd"/></dir></dir><dir name="Helper"><file name="Data.php" hash="b38d0589ad412de64813106ec15a243f"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="df6d3a6c0fa592158833776601e09d6d"/></dir></dir><dir name="etc"><file name="config.xml" hash="f4b1fdf4ebaf6e736cdb222cb04f61fa"/></dir><dir name="sql"><dir name="gmyandexmarket_setup"><file name="install-0.0.1.php" hash="b6a62bd3e463263cc7dac76347c25ac7"/></dir></dir></dir></dir></target></contents>
|
| 18 |
+
<compatible/>
|
| 19 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
| 20 |
+
</package>
|
