├── manifest.php
├── composer.json
├── phing.xml
├── setup
├── WooMigrateAttributeTypes.php
├── WooMigrateCategories.php
├── WooMigrateAttributes.php
├── WooMigrateBrands.php
├── WooMigrateExtraProductsOptions.php
└── WooMigrateProducts.php
├── README.md
└── LICENSE
/manifest.php:
--------------------------------------------------------------------------------
1 | 'ai-woocommerce',
5 | 'depends' => [
6 | 'aimeos-core',
7 | ],
8 | 'setup' => [
9 | 'setup',
10 | ],
11 | ];
12 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "aimeos/ai-woocommerce",
3 | "description": "Aimeos ai-woocommerce extension",
4 | "keywords": ["aimeos", "extension", "woocommerce", "migration"],
5 | "type": "aimeos-extension",
6 | "license": "LGPL-3.0",
7 | "prefer-stable": true,
8 | "minimum-stability": "dev",
9 | "require": {
10 | "php": "^8.0.11",
11 | "aimeos/aimeos-core": "dev-master"
12 | }
13 | }
--------------------------------------------------------------------------------
/phing.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/setup/WooMigrateAttributeTypes.php:
--------------------------------------------------------------------------------
1 | db( 'db-woocommerce' );
23 |
24 | if( !$db->hasTable( 'wp_terms' ) ) {
25 | return;
26 | }
27 |
28 | $this->info( 'Migrate WooCommerce attribute types', 'vv' );
29 |
30 | $manager = \Aimeos\MShop::create( $this->context(), 'attribute/type' );
31 | $items = $manager->search( $manager->filter()->slice( 0, 0xfffffff ) )->col( null, 'attribute.type.code' );
32 |
33 | $result = $db->query( 'SELECT attribute_name, attribute_label FROM wp_woocommerce_attribute_taxonomies' );
34 |
35 | foreach( $result->iterateAssociative() as $row )
36 | {
37 | $item = $items[$row['attribute_name']] ?? $manager->create();
38 | $item->setCode( $row['attribute_name'] )->setLabel( $row['attribute_label'] )->setDomain( 'product' );
39 |
40 | $manager->save( $item );
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WooCommerce to Aimeos
2 |
3 | Migrate your WooCommerce database to your Aimeos ecommerce installation.
4 |
5 | ## Requirements
6 |
7 | - Wordpress with WooCommerce
8 | - Aimeos 2023.10+
9 |
10 | ## Installation
11 |
12 | In your Aimeos setup, use composer to install the ai-woocommerce package:
13 |
14 | ```
15 | composer req aimeos/ai-woocommerce
16 | ```
17 |
18 | ## Migration
19 |
20 | Configure your Wordpress database in your Laravel `./config/shop.php`:
21 |
22 | ```php
23 | 'resource' => [
24 | 'db' => [
25 | // existing DB connection settings
26 | ],
27 | 'db-woocommerce' => [
28 | 'adapter' => 'mysql',
29 | 'host' => '127.0.0.1',
30 | 'port' => '3306',
31 | 'database' => 'wordpress',
32 | 'username' => 'wp_db_user',
33 | 'password' => 'wp_password',
34 | ],
35 | ],
36 | ```
37 |
38 | **Caution:** Make sure the Aimeos installation contains no demo data and `db-woocommerce` is at the end of the `resource` list!
39 |
40 | Afterwards, run this command to execute all setup tasks including those from the ai-woocommerce package:
41 |
42 | ```
43 | php artisan aimeos:setup
44 | ```
45 |
46 | This will migrate these entities from your WooCommerce database to the Aimeos database:
47 |
48 | - Products
49 | - Categories
50 | - Suppliers/Brands
51 | - Attributes and attribute types
52 | - Extra product options from a WooCommerce extension (partly)
53 |
54 | If everything works correctly, remove the `db-woocommerce` database settings from your `./config/shop.php` again.
55 |
--------------------------------------------------------------------------------
/setup/WooMigrateCategories.php:
--------------------------------------------------------------------------------
1 | db( 'db-woocommerce' );
23 |
24 | if( !$db->hasTable( 'wp_terms' ) ) {
25 | return;
26 | }
27 |
28 | $this->info( 'Migrate WooCommerce categories', 'vv' );
29 |
30 | $textManager = \Aimeos\MShop::create( $this->context(), 'text' );
31 | $manager = \Aimeos\MShop::create( $this->context(), 'catalog' );
32 | $items = $manager->getTree( null, ['text'] )->toList();
33 | $root = $manager->find( 'home' );
34 |
35 | $langId = $this->context()->locale()->getLanguageId();
36 |
37 | $db2 = $this->db( 'db-catalog' );
38 |
39 | $result = $db->query( "
40 | SELECT
41 | t.term_id, tt.parent, t.name, t.slug, tt.description,
42 | st.meta_value AS metatitle,
43 | sd.meta_value AS metadesc
44 | FROM wp_terms t
45 | JOIN wp_term_taxonomy tt ON t.term_id=tt.term_id
46 | LEFT JOIN wp_termmeta st ON st.term_id=t.term_id AND st.meta_key='_seopress_titles_title'
47 | LEFT JOIN wp_termmeta sd ON sd.term_id=t.term_id AND sd.meta_key='_seopress_titles_desc'
48 | WHERE taxonomy='product_cat'
49 | ORDER BY tt.parent, t.name
50 | " );
51 |
52 | foreach( $result->iterateAssociative() as $row )
53 | {
54 | $item = $items[$row['term_id']] ?? $manager->create();
55 | $item->setCode( $row['slug'] )->setLabel( html_entity_decode( $row['name'] ) )->setUrl( $row['slug'] );
56 |
57 | if( !$item->getId() )
58 | {
59 | $parent = $items[$row['parent']] ?? $root;
60 | $item = $manager->insert( $item, $parent?->getId() );
61 |
62 | $db2->update( 'mshop_catalog', ['id' => $row['term_id']], ['id' => $item->getId()] );
63 | $item->setId( $row['term_id'] );
64 | }
65 |
66 | if( $text = $row['description'] ?? null )
67 | {
68 | $listItem = $item->getListItems( 'text', 'default', 'long' )->first() ?? $manager->createListItem();
69 | $refItem = $listItem->getRefItem() ?: $textManager->create();
70 | $refItem->setType( 'long' )->setLanguageId( $langId )->setContent( $text );
71 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $text ), 0, 60 ) ) );
72 | }
73 |
74 | if( $text = $row['metatitle'] ?? null )
75 | {
76 | $listItem = $item->getListItems( 'text', 'default', 'meta-title' )->first() ?? $manager->createListItem();
77 | $refItem = $listItem->getRefItem() ?: $textManager->create();
78 | $refItem->setType( 'meta-title' )->setLanguageId( $langId )->setContent( $text );
79 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $text ), 0, 60 ) ) );
80 | }
81 |
82 | if( $text = $row['metadesc'] ?? null )
83 | {
84 | $listItem = $item->getListItems( 'text', 'default', 'meta-description' )->first() ?? $manager->createListItem();
85 | $refItem = $listItem->getRefItem() ?: $textManager->create();
86 | $refItem->setType( 'meta-description' )->setLanguageId( $langId )->setContent( $text );
87 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $text ), 0, 60 ) ) );
88 | }
89 |
90 | $items[$item->getId()] = $manager->save( $item );
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/setup/WooMigrateAttributes.php:
--------------------------------------------------------------------------------
1 | db( 'db-woocommerce' );
23 |
24 | if( !$db->hasTable( 'wp_terms' ) ) {
25 | return;
26 | }
27 |
28 | $this->info( 'Migrate WooCommerce attributes', 'vv' );
29 |
30 | $context = $this->context();
31 | $mediaManager = \Aimeos\MShop::create( $context, 'media' );
32 | $textManager = \Aimeos\MShop::create( $context, 'text' );
33 | $manager = \Aimeos\MShop::create( $context, 'attribute' );
34 | $items = $manager->search( $manager->filter()->slice( 0, 0x7fffffff ), ['media', 'text'] );
35 |
36 | $result = $db->query( "
37 | SELECT
38 | t.term_id,
39 | t.name,
40 | t.slug,
41 | tt.taxonomy,
42 | tt.description,
43 | pi.guid AS imgurl,
44 | pi.post_title AS imglabel,
45 | pi.post_mime_type AS mimetype
46 | FROM wp_terms t
47 | JOIN wp_term_taxonomy tt ON t.term_id=tt.term_id AND tt.taxonomy LIKE 'pa_%'
48 | LEFT JOIN wp_termmeta tmi ON tmi.term_id=t.term_id AND tmi.meta_key='st-image-swatch'
49 | LEFT JOIN wp_posts pi ON pi.ID=tmi.meta_value
50 | ORDER BY tt.taxonomy, t.name
51 | " );
52 |
53 | $langId = $this->context()->locale()->getLanguageId();
54 | $rows = [];
55 | $type = '';
56 | $pos = 0;
57 |
58 | foreach( $result->iterateAssociative() as $row )
59 | {
60 | if( $row['taxonomy'] !== $type )
61 | {
62 | $type = $row['taxonomy'];
63 | $pos = 0;
64 | }
65 |
66 | $item = $items->get( $row['term_id'] ) ?: $manager->create();
67 | $item->setCode( $row['slug'] )
68 | ->setLabel( $row['name'] )
69 | ->setDomain( 'product' )
70 | ->setPosition( $pos++ )
71 | ->setType( substr( $row['taxonomy'], 3 ) );
72 |
73 | $items[$row['term_id']] = $item;
74 | $rows[] = $row;
75 | }
76 |
77 | $manager->begin();
78 | $manager->save( $items );
79 | $manager->commit();
80 |
81 | $this->db( 'db-attribute' )->transaction( function( $db ) use ( $items ) {
82 |
83 | foreach( $items as $id => $item )
84 | {
85 | if( $id != $item->getId() )
86 | {
87 | $db->update( 'mshop_attribute', ['id' => $id], ['id' => $item->getId()] );
88 | $item->setId( $id );
89 | }
90 | }
91 | } );
92 |
93 | foreach( $rows as $row )
94 | {
95 | $item = $items->get( $row['term_id'] );
96 |
97 | if( $text = $row['description'] ?? null )
98 | {
99 | $listItem = $item->getListItems( 'text', 'default', 'long' )->first() ?? $manager->createListItem();
100 | $refItem = $listItem->getRefItem() ?: $textManager->create();
101 | $refItem->setType( 'long' )->setLanguageId( $langId )->setContent( $text );
102 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $text ), 0, 60 ) ) );
103 | }
104 |
105 | if( $image = $row['imgurl'] ?? null )
106 | {
107 | $listItem = $item->getListItems( 'media', 'default', 'icon' )->first() ?? $manager->createListItem();
108 | $refItem = $listItem->getRefItem() ?: $mediaManager->create();
109 | $refItem->setType( 'icon' )->setUrl( $image )->setMimetype( $row['mimetype'] ?? '' );
110 | $item->addListItem( 'media', $listItem, $refItem->setLabel( $row['imglabel'] ?? $image ) );
111 | }
112 | }
113 |
114 | $manager->begin();
115 | $manager->save( $items );
116 | $manager->commit();
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/setup/WooMigrateBrands.php:
--------------------------------------------------------------------------------
1 | db( 'db-woocommerce' );
23 |
24 | if( !$db->hasTable( 'wp_terms' ) ) {
25 | return;
26 | }
27 |
28 | $this->info( 'Migrate WooCommerce brands', 'vv' );
29 |
30 | $context = $this->context();
31 | $mediaManager = \Aimeos\MShop::create( $context, 'media' );
32 | $textManager = \Aimeos\MShop::create( $context, 'text' );
33 | $manager = \Aimeos\MShop::create( $context, 'supplier' );
34 | $brands = $manager->search( $manager->filter()->slice( 0, 0x7fffffff ), ['media', 'text'] );
35 |
36 | $langId = $context->locale()->getLanguageId();
37 |
38 | $db2 = $this->db( 'db-supplier' );
39 |
40 | $result = $db->query( "
41 | SELECT
42 | t.term_id,
43 | t.name,
44 | t.slug,
45 | tt.description,
46 | st.meta_value AS metatitle,
47 | sd.meta_value AS metadesc,
48 | pi.guid AS imgurl,
49 | pi.post_title AS imglabel,
50 | pi.post_mime_type AS mimetype
51 | FROM wp_terms t
52 | JOIN wp_term_taxonomy tt ON t.term_id=tt.term_id
53 | LEFT JOIN wp_termmeta st ON st.term_id=t.term_id AND st.meta_key='_seopress_titles_title'
54 | LEFT JOIN wp_termmeta sd ON sd.term_id=t.term_id AND sd.meta_key='_seopress_titles_desc'
55 | LEFT JOIN wp_termmeta si ON si.term_id=t.term_id AND si.meta_key='thumbnail_id'
56 | LEFT JOIN wp_posts pi ON pi.ID=si.meta_value
57 | WHERE taxonomy='brand'
58 | ORDER BY t.name
59 | " );
60 |
61 | foreach( $result->iterateAssociative() as $row )
62 | {
63 | $item = $brands[$row['term_id']] ?? $manager->create();
64 | $item->setCode( $row['slug'] )->setLabel( $row['name'] );
65 |
66 | if( !$item->getId() )
67 | {
68 | $item = $manager->save( $item );
69 |
70 | $db2->update( 'mshop_supplier', ['id' => $row['term_id']], ['id' => $item->getId()] );
71 | $item->setId( $row['term_id'] );
72 | }
73 |
74 | if( $text = $row['description'] ?? null )
75 | {
76 | $listItem = $item->getListItems( 'text', 'default', 'long' )->first() ?? $manager->createListItem();
77 | $refItem = $listItem->getRefItem() ?: $textManager->create();
78 | $refItem->setType( 'long' )->setLanguageId( $langId )->setContent( $text );
79 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $text ), 0, 60 ) ) );
80 | }
81 |
82 | if( $text = $row['metatitle'] ?? null )
83 | {
84 | $listItem = $item->getListItems( 'text', 'default', 'meta-title' )->first() ?? $manager->createListItem();
85 | $refItem = $listItem->getRefItem() ?: $textManager->create();
86 | $refItem->setType( 'meta-title' )->setLanguageId( $langId )->setContent( $text );
87 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $text ), 0, 60 ) ) );
88 | }
89 |
90 | if( $text = $row['metadesc'] ?? null )
91 | {
92 | $listItem = $item->getListItems( 'text', 'default', 'meta-description' )->first() ?? $manager->createListItem();
93 | $refItem = $listItem->getRefItem() ?: $textManager->create();
94 | $refItem->setType( 'meta-description' )->setLanguageId( $langId )->setContent( $text );
95 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $text ), 0, 60 ) ) );
96 | }
97 |
98 | if( $image = $row['imgurl'] ?? null )
99 | {
100 | $listItem = $item->getListItems( 'media', 'default', 'default' )->first() ?? $manager->createListItem();
101 | $refItem = $listItem->getRefItem() ?: $mediaManager->create();
102 | $refItem->setType( 'default' )->setUrl( $image )->setMimetype( $row['mimetype'] ?? '' );
103 | $item->addListItem( 'media', $listItem, $refItem->setLabel( $row['imglabel'] ?? $image ) );
104 | }
105 |
106 | $brands[$item->getId()] = $manager->save( $item );
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/setup/WooMigrateExtraProductsOptions.php:
--------------------------------------------------------------------------------
1 | db( 'db-woocommerce' );
32 |
33 | if( !$db->hasTable( 'wp_posts' ) ) {
34 | return;
35 | }
36 |
37 | $this->info( 'Migrate WooCommerce extra product options', 'vv' );
38 |
39 | $result = $db->query( "
40 | SELECT
41 | p.ID,
42 | t.term_id AS catid,
43 | pmt.meta_value AS template,
44 | pme.meta_value AS excludes
45 | FROM wp_posts p
46 | JOIN wp_term_relationships tr ON p.ID = tr.object_id
47 | JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
48 | JOIN wp_terms t ON t.term_id = tt.term_id
49 | JOIN wp_postmeta pmt ON p.ID = pmt.post_id AND pmt.meta_key = 'tm_meta'
50 | LEFT JOIN wp_postmeta pme ON p.ID = pme.post_id AND pme.meta_key = 'tm_meta_product_exclude_ids'
51 | LEFT JOIN wp_postmeta pmd ON p.ID = pmd.post_id AND pmd.meta_key = 'tm_meta_disable_categories'
52 | WHERE
53 | p.post_status = 'publish' AND p.post_type = 'tm_global_cp' AND
54 | ( pmd.meta_value != '1' OR pmd.meta_value IS NULL ) AND
55 | tt.taxonomy = 'product_cat'
56 | ORDER BY p.ID
57 | " );
58 |
59 | $map = $catids = [];
60 | foreach( $result->iterateAssociative() as $row )
61 | {
62 | $catids[$row['ID']][] = $row['catid'];
63 | $map[$row['ID']] = $row;
64 | }
65 |
66 | $this->update( $map, $catids );
67 | }
68 |
69 |
70 | protected function context()
71 | {
72 | if( !isset( $this->context ) )
73 | {
74 | $context = clone parent::context();
75 | $site = $context->config()->get( 'setup/site', 'default' );
76 |
77 | $localeManager = \Aimeos\MShop::create( $context, 'locale', 'Standard' );
78 | $context->setLocale( $localeManager->bootstrap( $site, '', '', false ) );
79 |
80 | $this->context = $context;
81 | }
82 |
83 | return $this->context;
84 | }
85 |
86 |
87 | public function update( array $map, array $catids )
88 | {
89 | $pos = 0;
90 |
91 | foreach( $map as $tid => $row )
92 | {
93 | if( ( $content = unserialize( $row['template'] ?? '' ) ) === false ) {
94 | error_log( sprintf( 'Template "%1$s" can not be unserialized', $tid ) );
95 | continue;
96 | }
97 |
98 | if( ( $section = $content['tmfbuilder'] ?? null ) === null ) {
99 | continue;
100 | }
101 |
102 | if( in_array( 'radiobuttons', $section['element_type'] )
103 | && !empty( $section['multiple_radiobuttons_options_enabled'] )
104 | ) {
105 | $typeItem = $this->attributeType( $tid, $section, $content['priority'] ?? 0 );
106 | $attrIds = $this->attributesItems( $tid, $section, $typeItem->getCode() );
107 |
108 | $excluded = unserialize( $row['excludes'] ?? '' ) ?: [];
109 | $this->assign( $catids[$tid] ?? [], $attrIds, 'attribute', 'config', $excluded, $pos++ );
110 | }
111 | }
112 | }
113 |
114 |
115 | protected function addProducts( array $section, int $idx, \Aimeos\MShop\Attribute\Item\Iface $item )
116 | {
117 | if( $section['product_enabled'][$idx] ?? null )
118 | {
119 | if( ( $section['product_mode'][$idx] ?? '' ) === 'categories' )
120 | {
121 | $catIds = (array) $section['product_categoryids'][$idx] ?? [];
122 | $sort = $section['product_orderby'][$idx] ?? 'ID';
123 | $dir = $section['product_order'][$idx] ?? 'asc';
124 |
125 | $prodIds = $this->catproducts( $catIds, $sort, $dir );
126 | }
127 | elseif( in_array( $section['product_mode'][$idx] ?? '', ['products', 'product'] ) )
128 | {
129 | $prodIds = (array) $section['product_productids'][$idx] ?? [];
130 | }
131 | else
132 | {
133 | error_log( sprintf( 'Unknown product mode %1$s', $section['product_mode'][$idx] ?? '' ) );
134 | return;
135 | }
136 |
137 | $listItems = $item->getListItems( 'product', 'default' )->reverse();
138 |
139 | foreach( $prodIds as $pos => $prodId )
140 | {
141 | $listItem = $item->getListItem( 'product', 'default', $prodId ) ?: $this->listItem();
142 | $item->addListItem( 'product', $listItem->setRefId( $prodId )->setPosition( $pos ) );
143 | $listItems->remove( $listItem->getId() );
144 | }
145 |
146 | $item->deleteListItems( $listItems );
147 | }
148 | }
149 |
150 |
151 | protected function addRadioButtons( string $tid, array $section, string $typeCode , int $idx, \Aimeos\Map $attrItems, int $elIdx ) : array
152 | {
153 | $assign = [];
154 |
155 | if( !( $section['radiobuttons_enabled'][$idx] ?? null ) ) {
156 | return $assign;
157 | }
158 |
159 | foreach( $section['multiple_radiobuttons_options_enabled'][$idx] as $key => $status )
160 | {
161 | if( !$status ) {
162 | continue;
163 | }
164 |
165 | $price = $section['multiple_radiobuttons_options_price'][$idx][$key] ?? 0;
166 | $name = $section['multiple_radiobuttons_options_title'][$idx][$key] ?? '';
167 | $image = $section['multiple_radiobuttons_options_image'][$idx][$key] ?? null;
168 | $cimage = $section['multiple_radiobuttons_options_imagec'][$idx][$key] ?? null;
169 | $lgimage = $section['multiple_radiobuttons_options_imagel'][$idx][$key] ?? null;
170 | $desc = $section['multiple_radiobuttons_options_description'][$idx][$key] ?? '';
171 | $code = \Aimeos\Base\Str::slug( $section['multiple_radiobuttons_options_value'][$idx][$key] ?? '' );
172 |
173 | if( !$code ) {
174 | error_log( 'No value for "multiple_radiobuttons_options_value" in template ' . $tid );
175 | continue;
176 | }
177 |
178 | $code .= '_' . $tid . '_' . $idx . '_' . $key;
179 |
180 | if( $idx !== 0 && $price > 0 )
181 | {
182 | $this->createProduct( $typeCode . '_' . $code, $name, $desc, $price, [$lgimage, $image, $cimage] );
183 | continue;
184 | }
185 |
186 | $item = $attrItems[$code] ?? $this->attribute();
187 | $item->setCode( $code )->setLabel( $name ?: $code )->setType( $typeCode )->setPosition( $elIdx * 100 + $idx * 10 + $key );
188 |
189 | $mediaListItems = $item->getListItems( 'media', 'default', 'icon' )->reverse();
190 | foreach( array_unique( array_filter( [$image, $cimage] ) ) as $pos => $imgurl )
191 | {
192 | $listItem = $mediaListItems->pop() ?: $this->listItem();
193 | $refItem = $listItem->getRefItem() ?: $this->media();
194 | $refItem->setType( 'icon' )->setUrl( $imgurl )->setLabel( $name )->setMimetype( $this->mime( $imgurl ) );
195 | $item->addListItem( 'media', $listItem, $refItem );
196 | }
197 | $item->deleteListItems( $mediaListItems );
198 |
199 | if( $lgimage )
200 | {
201 | $listItem = $item->getListItems( 'media', 'default', 'default' )->first() ?: $this->listItem();
202 | $refItem = $listItem->getRefItem() ?: $this->media();
203 | $refItem->setType( 'default' )->setUrl( $lgimage )->setLabel( $name )->setMimetype( $this->mime( $lgimage ) );
204 | $item->addListItem( 'media', $listItem, $refItem );
205 | }
206 |
207 | if( $desc )
208 | {
209 | $listItem = $item->getListItems( 'text', 'default', 'long' )->first() ?: $this->listItem();
210 | $refItem = $listItem->getRefItem() ?: $this->text();
211 | $refItem->setType( 'long' )->setContent( $desc )->setLabel( mb_strcut( $desc, 0, 100 ) );
212 | $item->addListItem( 'text', $listItem, $refItem );
213 | }
214 |
215 | if( $price && preg_match( '/^[0-9]+\.?[0-9]*$/', $price ) === 1 )
216 | {
217 | $listItem = $item->getListItems( 'price', 'default', 'default' )->first() ?: $this->listItem();
218 | $refItem = $listItem->getRefItem() ?: $this->price();
219 | $refItem->setType( 'default' )->setValue( $price );
220 | $item->addListItem( 'price', $listItem, $refItem );
221 | }
222 |
223 | $attrItems[$code] = $item;
224 | $assign[$key][] = $item;
225 | }
226 |
227 | return $assign;
228 | }
229 |
230 |
231 | protected function addSelectBox( string $tid, array $section, string $typeCode, int $idx, \Aimeos\Map $attrItems, int $elIdx ) : array
232 | {
233 | $assign = [];
234 |
235 | if( !( $section['selectbox_enabled'][$idx] ?? null ) ) {
236 | return $assign;
237 | }
238 |
239 | foreach( $section['multiple_selectbox_options_value'][$idx] as $key => $value )
240 | {
241 | $price = $section['multiple_selectbox_options_price'][$idx][$key] ?? 0;
242 | $name = $section['multiple_selectbox_options_title'][$idx][$key] ?? '';
243 | $image = $section['multiple_selectbox_options_image'][$idx][$key] ?? null;
244 | $cimage = $section['multiple_selectbox_options_imagec'][$idx][$key] ?? null;
245 | $lgimage = $section['multiple_selectbox_options_imagel'][$idx][$key] ?? null;
246 | $code = \Aimeos\Base\Str::slug( $value );
247 |
248 | if( !$code ) {
249 | error_log( 'No value for "multiple_selectbox_options_value" in template ' . $tid );
250 | continue;
251 | }
252 |
253 | $code .= '_' . $tid . '_' . $idx . '_' . $key;
254 | $item = $attrItems[$code] ?? $this->attribute();
255 | $item->setCode( $code )->setLabel( $name ?: $code )->setType( $typeCode )->setPosition( $elIdx * 100 + $idx * 10 + $key );
256 |
257 | $mediaListItems = $item->getListItems( 'media', 'default', 'icon' )->reverse();
258 |
259 | foreach( array_filter( [$image, $cimage] ) as $pos => $imgurl )
260 | {
261 | $listItem = $mediaListItems->pop() ?: $this->listItem();
262 | $refItem = $listItem->getRefItem() ?: $this->media();
263 | $refItem->setType( 'icon' )->setUrl( $imgurl )->setLabel( $name )->setMimetype( $this->mime( $imgurl ) );
264 | $item->addListItem( 'media', $listItem, $refItem );
265 | }
266 |
267 | if( $lgimage )
268 | {
269 | $listItem = $item->getListItems( 'media', 'default', 'default' )->first() ?: $this->listItem();
270 | $refItem = $listItem->getRefItem() ?: $this->media();
271 | $refItem->setType( 'default' )->setUrl( $lgimage )->setLabel( $name )->setMimetype( $this->mime( $lgimage ) );
272 | $item->addListItem( 'media', $listItem, $refItem );
273 | }
274 |
275 | if( $price && preg_match( '/^[0-9]+\.?[0-9]*$/', $price ) === 1 )
276 | {
277 | $listItem = $item->getListItems( 'price', 'default', 'default' )->first() ?: $this->listItem();
278 | $refItem = $listItem->getRefItem() ?: $this->price();
279 | $refItem->setType( 'default' )->setValue( $price );
280 | $item->addListItem( 'price', $listItem, $refItem );
281 | }
282 |
283 | $attrItems[$code] = $item;
284 | $assign[$key][] = $item;
285 | }
286 |
287 | return $assign;
288 | }
289 |
290 |
291 | protected function assign( array $catids, array $refIds, string $domain, string $listType, array $excluded = [], $pos = 0 )
292 | {
293 | if( empty( $catids ) ) {
294 | return;
295 | }
296 |
297 | $context = $this->context();
298 | $manager = \Aimeos\MShop::create( $context, 'product' );
299 |
300 | $filter = $manager->filter();
301 | $filter->add( $filter->make( 'product:has', ['catalog', 'default', $catids] ), '!=', null );
302 | $cursor = $manager->cursor( $filter );
303 |
304 | while( $items = $manager->iterate( $cursor, [$domain] ) )
305 | {
306 | foreach( $items as $id => $item )
307 | {
308 | if( in_array( $id, $excluded ) ) {
309 | continue;
310 | }
311 |
312 | $idx = 0;
313 | foreach( $refIds as $refId )
314 | {
315 | $listItem = $item->getListItem( $domain, $listType, $refId ) ?? $manager->createListItem();
316 | $item->addListItem( $domain, $listItem->setType( $listType )->setRefId( $refId )->setPosition( $pos * 100 + $idx++ ) );
317 | }
318 | }
319 |
320 | $manager->begin();
321 | $manager->save( $items );
322 | $manager->commit();
323 | }
324 | }
325 |
326 |
327 | /**
328 | * Returns an new attribute item
329 | *
330 | * @return \Aimeos\MShop\Attribute\Item\Iface New attribute Item
331 | */
332 | protected function attribute() : \Aimeos\MShop\Attribute\Item\Iface
333 | {
334 | if( !isset( $this->attribute ) )
335 | {
336 | $manager = \Aimeos\MShop::create( $this->context(), 'attribute' );
337 | $this->attribute = $manager->create()->setDomain( 'product' );
338 | }
339 |
340 | return clone $this->attribute;
341 | }
342 |
343 |
344 | protected function attributesItems( string $tid, array $section, string $typeCode ) : array
345 | {
346 | $attrCodes = $attrs = [];
347 | $selectIdx = $radioIdx = $productIdx = 0;
348 |
349 | $attrManager = \Aimeos\MShop::create( $this->context(), 'attribute' );
350 | $filter = $attrManager->filter()->add( 'attribute.type', '==', $typeCode ) ->slice( 0, 0x7fffffff );
351 | $attrItems = $attrManager->search( $filter, ['media', 'price', 'product', 'text'] )->col( null, 'attribute.code' );
352 |
353 | foreach( $section['element_type'] ?? [] as $elIdx => $elType )
354 | {
355 | switch( $elType )
356 | {
357 | case 'selectbox':
358 | $attrs = $this->addSelectBox( $tid, $section, $typeCode, $selectIdx++, $attrItems, $elIdx );
359 | break;
360 | case 'radiobuttons':
361 | $attrs = $this->addRadioButtons( $tid, $section, $typeCode, $radioIdx++, $attrItems, $elIdx );
362 | break;
363 | case 'product':
364 | // this is not correct and must be fixed by hand because section/product logic can be very complicated
365 | foreach( $attrs as $key => $list ) {
366 | foreach( $list as $attr ) {
367 | $this->addProducts( $section, $productIdx++, $attr );
368 | }
369 | }
370 | $attrs = [];
371 | default:
372 | continue 2;
373 | }
374 |
375 | if( $selectIdx + $radioIdx === 1 ) { // only assign first selection level to products
376 | $attrCodes = array_merge( $attrCodes, map( $attrs )->flat( 1 )->col( 'attribute.code' )->all() );
377 | }
378 | }
379 |
380 | $attrManager->begin();
381 | $attrManager->save( $attrItems );
382 | $attrManager->commit();
383 |
384 | return $attrItems->only( array_unique( $attrCodes ) )->getId()->all();
385 | }
386 |
387 |
388 | protected function attributeType( string $tid, array $section, int $pos ) : \Aimeos\MShop\Common\Item\Type\Iface
389 | {
390 | $context = $this->context();
391 | $langId = $context->locale()->getLanguageId();
392 | $manager = \Aimeos\MShop::create( $context, 'attribute/type' );
393 |
394 | if( !isset( $this->attrTypes ) )
395 | {
396 | $filter = $manager->filter()->slice( 0, 0x7fffffff );
397 | $this->attrTypes = $manager->search( $filter )->col( null, 'attribute.type.code' );
398 | }
399 |
400 | $label = $section['sections_internal_name'][0] ?? '';
401 | $code = \Aimeos\Base\Str::slug( $section['sections_internal_name'][0] ?? '' ) . '_' . $tid;
402 | $name = '';
403 |
404 | if( isset( $section['section_header_title'][0] ) ) {
405 | $name .= '
';
406 | }
407 |
408 | $name .= $section['section_header_subtitle'][0] ?? '';
409 |
410 | $item = $this->attrTypes[$code] ?? $manager->create();
411 | $item->setDomain( 'product' )->setCode( $code )->setLabel( $label )->setPosition( $pos )->setI18n( [$langId => $name] );
412 |
413 | return $this->attrTypes[$code] = $manager->save( $item );
414 | }
415 |
416 |
417 | /**
418 | * Returns the product IDs attached to the given category IDs
419 | *
420 | * @param array $catIds List of category IDs
421 | * @param string $sort Type of sorting, i.e. "ID" or "baseprice"
422 | * @param string $dir Sorting direction, "asc" or "desc"
423 | * @return array List of sorted product IDs
424 | */
425 | protected function catproducts( array $catIds, string $sort, string $dir ) : array
426 | {
427 | $ref = [];
428 | $sortFcn = function( $a, $b ) {};
429 |
430 | if( $sort === 'baseprice' )
431 | {
432 | $ref = ['price'];
433 | $sortFcn = function( $a, $b ) {
434 | return $a->getRefItems( 'price', 'default', 'default' )->min( 'price.value' )
435 | <=>
436 | $b->getRefItems( 'price', 'default', 'default' )->min( 'price.value' );
437 | };
438 | }
439 |
440 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
441 |
442 | $filter = $manager->filter( true )->slice( 0, 0x7fffffff )->order( 'product.id' );
443 | $filter->add( $filter->make( 'product:has', ['catalog', 'default', $catIds] ), '!=', null );
444 |
445 | $items = $manager->search( $filter, $ref )->uasort( $sortFcn );
446 |
447 | if( $dir === 'desc' ) {
448 | $items->reverse();
449 | }
450 |
451 | return $items->keys()->all();
452 | }
453 |
454 |
455 | protected function createProduct( $code, $name, $desc, $price, $images )
456 | {
457 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
458 |
459 | if( strlen( $code ) > 64 ) {
460 | $code = substr( $code, 0, 60 ) . '_' . substr( md5( $code ), -3 );
461 | }
462 |
463 | try {
464 | $item = $manager->find( $code, ['media', 'price', 'text'] );
465 | } catch( \Exception $e ) {
466 | $item = $manager->create()->setCode( $code );
467 | }
468 |
469 | $mediaListItems = $item->getListItems( 'media', 'default', 'default' )->reverse();
470 | foreach( array_unique( array_filter( $images ) ) as $pos => $imgurl )
471 | {
472 | $listItem = $mediaListItems->pop() ?: $this->listItem();
473 | $refItem = $listItem->getRefItem() ?: $this->media();
474 | $refItem->setType( 'default' )->setUrl( $imgurl )->setLabel( $name )->setMimetype( $this->mime( $imgurl ) );
475 | $item->addListItem( 'media', $listItem, $refItem );
476 | }
477 | $item->deleteListItems( $mediaListItems );
478 |
479 | if( $desc )
480 | {
481 | $listItem = $item->getListItems( 'text', 'default', 'long' )->first() ?: $this->listItem();
482 | $refItem = $listItem->getRefItem() ?: $this->text();
483 | $refItem->setType( 'long' )->setContent( $desc )->setLabel( mb_strcut( $desc, 0, 100 ) );
484 | $item->addListItem( 'text', $listItem, $refItem );
485 | }
486 |
487 | if( $price && preg_match( '/^[0-9]+\.?[0-9]*$/', $price ) === 1 )
488 | {
489 | $listItem = $item->getListItems( 'price', 'default', 'default' )->first() ?: $this->listItem();
490 | $refItem = $listItem->getRefItem() ?: $this->price();
491 | $refItem->setType( 'default' )->setValue( $price );
492 | $item->addListItem( 'price', $listItem, $refItem );
493 | }
494 |
495 | $manager->save( $item->setLabel( $name ) );
496 | }
497 |
498 |
499 | /**
500 | * Returns an new attribute list item
501 | *
502 | * @return \Aimeos\MShop\Common\Item\Lists\Iface New list Item
503 | */
504 | protected function listItem() : \Aimeos\MShop\Common\Item\Lists\Iface
505 | {
506 | if( !isset( $this->listItem ) ) {
507 | $this->listItem = \Aimeos\MShop::create( $this->context(), 'attribute' )->createListItem();
508 | }
509 |
510 | return clone $this->listItem;
511 | }
512 |
513 |
514 | /**
515 | * Returns an new media item
516 | *
517 | * @return \Aimeos\MShop\Media\Item\Iface New media Item
518 | */
519 | protected function media() : \Aimeos\MShop\Media\Item\Iface
520 | {
521 | if( !isset( $this->media ) )
522 | {
523 | $manager = \Aimeos\MShop::create( $this->context(), 'media' );
524 | $this->media = $manager->create()->setDomain( 'attribute' );
525 | }
526 |
527 | return clone $this->media;
528 | }
529 |
530 |
531 | protected function mime( string $name ) : string
532 | {
533 | return match( pathinfo( $name, PATHINFO_EXTENSION ) ) {
534 | 'webp' => 'image/webp',
535 | 'jpeg' => 'image/jpeg',
536 | 'jpg' => 'image/jpeg',
537 | 'png' => 'image/png',
538 | 'gif' => 'image/gif',
539 | };
540 | }
541 |
542 |
543 | /**
544 | * Returns an new price item
545 | *
546 | * @return \Aimeos\MShop\Price\Item\Iface New price Item
547 | */
548 | protected function price() : \Aimeos\MShop\Price\Item\Iface
549 | {
550 | if( !isset( $this->price ) )
551 | {
552 | $context = $this->context();
553 | $currencyId = $context->locale()->getCurrencyId();
554 | $taxrate = $this->db( 'db-woocommerce' )->query( "SELECT tax_rate FROM wp_woocommerce_tax_rates LIMIT 1" )->fetchOne();
555 |
556 | $manager = \Aimeos\MShop::create( $context, 'price' );
557 | $this->price = $manager->create()->setDomain( 'attribute' )->setCurrencyId( $currencyId )->setTaxrate( $taxrate );
558 | }
559 |
560 | return clone $this->price;
561 | }
562 |
563 |
564 | /**
565 | * Returns an new text item
566 | *
567 | * @return \Aimeos\MShop\Text\Item\Iface New text Item
568 | */
569 | protected function text() : \Aimeos\MShop\Text\Item\Iface
570 | {
571 | if( !isset( $this->text ) )
572 | {
573 | $context = $this->context();
574 | $langId = $context->locale()->getLanguageId();
575 |
576 | $manager = \Aimeos\MShop::create( $context, 'text' );
577 | $this->text = $manager->create()->setDomain( 'attribute' )->setLanguageId( $langId );
578 | }
579 |
580 | return clone $this->text;
581 | }
582 | }
583 |
--------------------------------------------------------------------------------
/setup/WooMigrateProducts.php:
--------------------------------------------------------------------------------
1 | db( 'db-woocommerce' );
26 |
27 | if( !$db->hasTable( 'wp_posts' ) ) {
28 | return;
29 | }
30 |
31 | $this->info( 'Migrate WooCommerce products', 'vv' );
32 |
33 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
34 |
35 | $domains = ['attribute', 'catalog', 'media', 'price', 'product', 'product/property', 'stock', 'supplier', 'text'];
36 | $items = $manager->search( $manager->filter()->slice( 0, 0x7fffffff ), $domains );
37 |
38 | $result = $db->query( "
39 | SELECT
40 | p.ID,
41 | p.post_title,
42 | p.post_excerpt,
43 | p.post_content,
44 | p.post_name,
45 | p.post_date_gmt,
46 | t.name AS type,
47 | pm.sku,
48 | pm.stock_quantity,
49 | pm.stock_status,
50 | st.meta_value AS metatitle,
51 | sd.meta_value AS metadesc
52 | FROM wp_posts p
53 | JOIN wp_wc_product_meta_lookup pm ON p.ID = pm.product_id
54 | JOIN wp_term_relationships tr ON p.ID = tr.object_id
55 | JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
56 | JOIN wp_terms t ON t.term_id = tt.term_id
57 | LEFT JOIN wp_postmeta st ON st.post_id=p.ID AND st.meta_key='_seopress_titles_title'
58 | LEFT JOIN wp_postmeta sd ON sd.post_id=p.ID AND sd.meta_key='_seopress_titles_desc'
59 | WHERE p.post_type = 'product' AND p.post_status = 'publish' AND tt.taxonomy='product_type'
60 | " );
61 |
62 | $items = $this->products( $result, $items );
63 |
64 | $result = $db->query( "
65 | SELECT
66 | p.ID,
67 | p.post_parent,
68 | p.post_title,
69 | p.post_name,
70 | p.post_date_gmt,
71 | pm.sku,
72 | pm.stock_quantity,
73 | pm.stock_status
74 | FROM wp_posts p
75 | JOIN wp_wc_product_meta_lookup pm ON p.ID = pm.product_id
76 | WHERE p.post_type = 'product_variation' AND p.post_status = 'publish'
77 | " );
78 |
79 | $items = $this->products( $result, $items );
80 |
81 | $this->properties( $items );
82 | $this->deliveries( $items );
83 | $this->categories( $items );
84 | $this->attributes( $items );
85 | $this->attributeVariants( $items );
86 | $this->brands( $items );
87 | $this->images( $items );
88 | $this->prices( $items );
89 | $this->suggests( $items );
90 |
91 | $manager->begin();
92 | $manager->save( $items );
93 | $manager->commit();
94 | }
95 |
96 |
97 | protected function context()
98 | {
99 | if( !isset( $this->context ) )
100 | {
101 | $context = clone parent::context();
102 | $site = $context->config()->get( 'setup/site', 'default' );
103 |
104 | $localeManager = \Aimeos\MShop::create( $context, 'locale', 'Standard' );
105 | $context->setLocale( $localeManager->bootstrap( $site, '', '', false ) );
106 |
107 | $this->context = $context;
108 | }
109 |
110 | return $this->context;
111 | }
112 |
113 |
114 | protected function attributes( \Aimeos\Map $items )
115 | {
116 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
117 | $attrManager = \Aimeos\MShop::create( $this->context(), 'attribute' );
118 | $attrs = $attrManager->search( $attrManager->filter()->slice( 0, 0x7fffffff ) );
119 |
120 | $result = $this->db( 'db-woocommerce' )->query( "
121 | SELECT
122 | p.ID,
123 | tr.term_taxonomy_id AS attrid
124 | FROM wp_posts p
125 | JOIN wp_term_relationships AS tr on p.ID = tr.object_id
126 | JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_id
127 | WHERE
128 | p.post_type = 'product' AND
129 | p.post_status = 'publish' AND
130 | tt.taxonomy LIKE 'pa_%'
131 | " );
132 |
133 | foreach( $result->iterateAssociative() as $row )
134 | {
135 | if( ( $item = $items->get( $row['ID'] ) ) !== null && ( $attrItem = $attrs->get( $row['attrid'] ) ) !== null )
136 | {
137 | $listItem = $item->getListItem( 'attribute', 'default', $attrItem->getId() ) ?? $manager->createListItem();
138 | $item->addListItem( 'attribute', $listItem->setType( 'default' ), $attrItem );
139 | }
140 | }
141 | }
142 |
143 |
144 | protected function attributeVariants( \Aimeos\Map $items )
145 | {
146 | $context = $this->context();
147 | $manager = \Aimeos\MShop::create( $context, 'product' );
148 | $attrManager = \Aimeos\MShop::create( $context, 'attribute' );
149 | $typeManager = \Aimeos\MShop::create( $context, 'attribute/type' );
150 |
151 | $attrMap = $attrManager->search( $attrManager->filter()->slice( 0, 0x7fffffff ) )->rekey( function( $item ) {
152 | return $item->getType() . '/' . $item->getCode();
153 | } );
154 |
155 | $attrTypes = $typeManager->search( $typeManager->filter()->slice( 0, 0x7fffffff ) )->col( null, 'attribute.type.code' );
156 |
157 | $result = $this->db( 'db-woocommerce' )->query( "
158 | SELECT
159 | p.ID,
160 | pm.meta_key AS attrtype,
161 | pm.meta_value AS attrname
162 | FROM wp_posts p
163 | JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key LIKE 'attribute_%'
164 | WHERE
165 | p.post_type = 'product_variation' AND
166 | p.post_status = 'publish'
167 | " );
168 |
169 | $attrManager->begin();
170 |
171 | foreach( $result->iterateAssociative() as $row )
172 | {
173 | $name = $row['attrname'];
174 | $code = \Aimeos\Base\Str::slug( $name );
175 | $ftype = substr( $row['attrtype'], 10 );
176 | $type = substr( $ftype, substr_compare( $ftype, 'pa_', 0, 3 ) === 0 ? 3 : 0 );
177 | $key = $type . '/' . $code;
178 |
179 | if( $item = $items->get( $row['ID'] ) )
180 | {
181 | if( $attrTypes->get( $type ) === null ) {
182 | $attrTypes[$type] = $typeManager->create()->setDomain( 'product' )->setCode( $type )->setLabel( $type );
183 | }
184 |
185 | if( ( $attrItem = $attrMap->get( $key ) ) === null )
186 | {
187 | $attrItem = $attrManager->create()->setDomain( 'product' )->setType( $type )->setLabel( $name );
188 | $attrMap[$key] = $attrManager->save( $attrItem->setCode( $code ) );
189 | }
190 |
191 | $listItem = $item->getListItem( 'attribute', 'variant', $attrItem->getId() ) ?? $manager->createListItem();
192 | $item->addListItem( 'attribute', $listItem->setType( 'variant' ), $attrItem );
193 | }
194 | }
195 |
196 | $attrManager->commit();
197 |
198 | $typeManager->begin();
199 | $typeManager->save( $attrTypes );
200 | $typeManager->commit();
201 | }
202 |
203 |
204 | protected function brands( \Aimeos\Map $items )
205 | {
206 | $result = $this->db( 'db-woocommerce' )->query( "
207 | SELECT p.ID, t.term_id AS brandid, tr.term_order AS pos
208 | FROM wp_posts p
209 | JOIN wp_term_relationships tr ON p.ID = tr.object_id
210 | JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
211 | JOIN wp_terms t ON t.term_id = tt.term_id
212 | WHERE p.post_type = 'product' AND p.post_status = 'publish' AND tt.taxonomy='brand'
213 | " );
214 |
215 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
216 |
217 | foreach( $result->iterateAssociative() as $row )
218 | {
219 | if( $item = $items->get( $row['ID'] ) )
220 | {
221 | $listItem = $item->getListItem( 'supplier', 'default', $row['brandid'] ) ?? $manager->createListItem();
222 | $item->addListItem( 'supplier', $listItem->setRefId( $row['brandid'] )->setPosition( $row['pos'] ) );
223 | }
224 | }
225 | }
226 |
227 |
228 | protected function categories( \Aimeos\Map $items )
229 | {
230 | $result = $this->db( 'db-woocommerce' )->query( "
231 | SELECT p.ID, t.term_id AS catid, tr.term_order AS pos
232 | FROM wp_posts p
233 | JOIN wp_term_relationships tr ON p.ID = tr.object_id
234 | JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
235 | JOIN wp_terms t ON t.term_id = tt.term_id
236 | WHERE p.post_type = 'product' AND p.post_status = 'publish' AND tt.taxonomy='product_cat'
237 | " );
238 |
239 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
240 |
241 | foreach( $result->iterateAssociative() as $row )
242 | {
243 | if( $item = $items->get( $row['ID'] ) )
244 | {
245 | $listItem = $item->getListItem( 'catalog', 'default', $row['catid'] ) ?? $manager->createListItem();
246 | $item->addListItem( 'catalog', $listItem->setRefId( $row['catid'] )->setPosition( $row['pos'] ) );
247 | }
248 | }
249 | }
250 |
251 |
252 | protected function deliveries( \Aimeos\Map $items )
253 | {
254 | $typeManager = \Aimeos\MShop::create( $this->context(), 'attribute/type' );
255 |
256 | try {
257 | $typeItem = $typeManager->find( 'delivery', [], 'product' );
258 | } catch( \Exception $e ) {
259 | $typeItem = $typeManager->save( $typeManager->create()->setDomain( 'product' )->setCode( 'delivery' )->setLabel( 'Delivery' ) );
260 | }
261 |
262 | $attrManager = \Aimeos\MShop::create( $this->context(), 'attribute' );
263 | $attrItems = $attrManager->search( $attrManager->filter()->add( 'attribute.type', '==', 'delivery' ) )->col( null, 'attribute.code' );
264 |
265 | $result = $this->db( 'db-woocommerce' )->query( "
266 | SELECT
267 | p.ID,
268 | t.name,
269 | t.slug
270 | FROM wp_posts AS p
271 | JOIN wp_term_relationships AS tr ON p.ID = tr.object_id
272 | JOIN wp_terms AS t ON t.term_id = tr.term_taxonomy_id
273 | JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
274 | WHERE tt.taxonomy = 'product_shipping_class'
275 | " );
276 |
277 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
278 |
279 | foreach( $result->iterateAssociative() as $row )
280 | {
281 | if( ( $item = $items->get( $row['ID'] ) ) && ( $code = $row['slug'] ) )
282 | {
283 | if( ( $attrItem = $attrItems->get( $code ) ) === null )
284 | {
285 | $attrItem = $attrManager->create()->setDomain( 'product' )->setType( 'delivery' )->setLabel( $row['name'] );
286 | $attrItems[$code] = $attrManager->save( $attrItem->setCode( $code ) );
287 | }
288 |
289 | $listItem = $item->getListItem( 'attribute', 'hidden', $attrItem->getId() ) ?? $manager->createListItem();
290 | $item->addListItem( 'attribute', $listItem->setType( 'hidden' )->setRefId( $attrItem->getId() ) );
291 | }
292 | }
293 | }
294 |
295 |
296 | protected function images( \Aimeos\Map $items )
297 | {
298 | $mediaManager = \Aimeos\MShop::create( $this->context(), 'media' );
299 |
300 | $db2 = $this->db( 'db-woocommerce', true );
301 | $result = $this->db( 'db-woocommerce' )->query( "
302 | SELECT
303 | p.ID,
304 | p.post_title,
305 | main_img.meta_value AS image,
306 | gallery_pm.meta_value AS image_ids
307 | FROM wp_posts p
308 | JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_thumbnail_id'
309 | JOIN wp_postmeta main_img ON main_img.post_id = pm.meta_value AND main_img.meta_key = '_wp_attached_file'
310 | LEFT JOIN wp_postmeta gallery_pm ON p.ID = gallery_pm.post_id AND gallery_pm.meta_key = '_product_image_gallery'
311 | WHERE
312 | p.post_type = 'product' AND
313 | p.post_status = 'publish'
314 | " );
315 |
316 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
317 |
318 | foreach( $result->iterateAssociative() as $row )
319 | {
320 | if( $item = $items->get( $row['ID'] ) )
321 | {
322 | $listItems = $item->getListItems( 'media', 'default', 'default' )->reverse();
323 | $images = [$row['image']];
324 | $pos = 0;
325 |
326 | if( $row['image_ids'] )
327 | {
328 | $ids = array_filter( explode( ',', $row['image_ids'] ) );
329 | $images += $db2->query( "
330 | SELECT post_id, meta_value FROM wp_postmeta
331 | WHERE post_id IN (" . join( ',', $ids ) . ") AND meta_key = '_wp_attached_file'
332 | " )->fetchAllKeyValue();
333 | }
334 |
335 | foreach( $images as $image )
336 | {
337 | $listItem = $listItems->pop() ?? $manager->createListItem();
338 | $refItem = $listItem->getRefItem() ?: $mediaManager->create();
339 | $refItem->setUrl( $image )->setLabel( $row['post_title'] )->setMimetype( $this->mime( $image ) );
340 | $item->addListItem( 'media', $listItem->setPosition( $pos++ ), $refItem );
341 |
342 | $attrListItems = $item->getListItems( 'attribute', 'variant', null, false );
343 |
344 | foreach( $attrListItems as $attrListItem )
345 | {
346 | if( $attrItem = $attrListItem->getRefItem() )
347 | {
348 | $listItem = $refItem->getListItem( 'attribute', 'variant', (string) $attrItem->getId() ) ?? $mediaManager->createListItem();
349 | $refItem->addListItem( 'attribute', $listItem->setType( 'variant' ), $attrItem );
350 | }
351 | }
352 | }
353 | }
354 | }
355 |
356 | $db2->close();
357 | }
358 |
359 |
360 | protected function mime( string $name ) : string
361 | {
362 | return match( pathinfo( $name, PATHINFO_EXTENSION ) ) {
363 | 'webp' => 'image/webp',
364 | 'jpeg' => 'image/jpeg',
365 | 'jpg' => 'image/jpeg',
366 | 'png' => 'image/png',
367 | 'gif' => 'image/gif',
368 | };
369 | }
370 |
371 |
372 | protected function prices( \Aimeos\Map $items )
373 | {
374 | $context = $this->context();
375 | $db = $this->db( 'db-woocommerce' );
376 | $currencyId = $context->locale()->getCurrencyId();
377 |
378 | $manager = \Aimeos\MShop::create( $context, 'product' );
379 | $priceManager = \Aimeos\MShop::create( $context, 'price' );
380 |
381 | $taxrate = $db->query( "SELECT tax_rate FROM wp_woocommerce_tax_rates LIMIT 1" )->fetchOne();
382 | $priceItem = $priceManager->create()->setDomain( 'product' )->setType( 'default' )
383 | ->setCurrencyId( $currencyId )->setTaxrate( $taxrate );
384 |
385 | $result = $db->query( "
386 | SELECT
387 | p.ID,
388 | p.post_parent AS selectionid,
389 | pm.meta_value AS price,
390 | pms.meta_value AS saleprice
391 | FROM wp_posts p
392 | JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_regular_price'
393 | LEFT JOIN wp_postmeta pms ON p.ID = pms.post_id AND pms.meta_key = '_sale_price'
394 | ORDER BY p.ID
395 | " );
396 |
397 | foreach( $result->iterateAssociative() as $row )
398 | {
399 | if( $item = $items->get( $row['ID'] ) )
400 | {
401 | $listItems = $item->getListItems( 'price', 'default', 'default', false )->reverse();
402 |
403 | $listItem = $listItems->pop() ?? $manager->createListItem();
404 | $refItem = $listItem->getRefItem() ?: clone $priceItem;
405 | $refItem->setValue( $row['price'] );
406 | $item->addListItem( 'price', $listItem, $refItem );
407 |
408 | if( $row['saleprice'] > 0 )
409 | {
410 | $listItem = $listItems->pop() ?? $manager->createListItem();
411 | $refItem = $listItem->getRefItem() ?: clone $priceItem;
412 | $refItem->setValue( $row['saleprice'] )->setRebate( $row['price'] - $row['saleprice'] );
413 | $item->addListItem( 'price', $listItem, $refItem );
414 | }
415 |
416 | $item->deleteListItems( $listItems );
417 | }
418 |
419 | if( $item = $items->get( $row['selectionid'] ) )
420 | {
421 | $value = $row['saleprice'] > 0 ? $row['saleprice'] : $row['price'];
422 | $rebate = $row['saleprice'] > 0 ? (float) $row['price'] - (float) $row['saleprice'] : '0.00';
423 |
424 | if( ( $listItem = $item->getListItems( 'price', 'default', 'default', false )->first() ) === null ) {
425 | $item->addListItem( 'price', $listItem = $manager->createListItem(), $refItem = clone $priceItem );
426 | } else {
427 | $refItem = $listItem->getRefItem();
428 | }
429 |
430 | if( $refItem->getValue() == 0 || $refItem->getValue() > $value ) {
431 | $refItem->setValue( $value )->setRebate( $rebate );
432 | }
433 | }
434 | }
435 | }
436 |
437 |
438 | public function products( \Doctrine\DBAL\Result $result, \Aimeos\Map $items ) : \Aimeos\Map
439 | {
440 | $stockManager = \Aimeos\MShop::create( $this->context(), 'stock' );
441 | $textManager = \Aimeos\MShop::create( $this->context(), 'text' );
442 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
443 |
444 | $langId = $this->context()->locale()->getLanguageId();
445 | $rows = [];
446 |
447 | foreach( $result->iterateAssociative() as $row )
448 | {
449 | $code = str_replace( ' ', '-', $row['sku'] );
450 |
451 | if( strlen( $code ) > 64 ) {
452 | $code = substr( $code, 0, 60 ) . '_' . substr( md5( microtime( true) . rand() ), -3 );
453 | }
454 |
455 | $item = $items->get( $row['ID'] ) ?: $manager->create();
456 | $item->setCode( $code ?: 'woo-' . $row['ID'] )
457 | ->setUrl( $row['post_name'] )
458 | ->setLabel( $row['post_title'] )
459 | ->setType( $this->type( $row['type'] ?? '' ) )
460 | ->setTimeCreated( $row['post_date_gmt'] );
461 |
462 | $items[$row['ID']] = $item;
463 | $rows[] = $row;
464 | }
465 |
466 | $manager->begin();
467 | $manager->save( $items );
468 | $manager->commit();
469 |
470 | $this->db( 'db-product' )->transaction( function( $db ) use ( $items ) {
471 |
472 | foreach( $items as $id => $item )
473 | {
474 | if( $id != $item->getId() )
475 | {
476 | $db->update( 'mshop_product', ['id' => $id], ['id' => $item->getId()] );
477 | $item->setId( $id );
478 | }
479 | }
480 | } );
481 |
482 |
483 | foreach( $rows as $row )
484 | {
485 | $item = $items->get( $row['ID'] );
486 |
487 | if( $short = $row['post_excerpt'] ?? null )
488 | {
489 | $listItem = $item->getListItems( 'text', 'default', 'short' )->first() ?? $manager->createListItem();
490 | $refItem = $listItem->getRefItem() ?: $textManager->create();
491 | $refItem->setType( 'short' )->setLanguageId( $langId )->setContent( $short );
492 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $short ), 0, 60 ) ) );
493 | }
494 |
495 | if( ( $text = $row['post_content'] ?? null ) && $text !== $short )
496 | {
497 | $listItem = $item->getListItems( 'text', 'default', 'long' )->first() ?? $manager->createListItem();
498 | $refItem = $listItem->getRefItem() ?: $textManager->create();
499 | $refItem->setType( 'long' )->setLanguageId( $langId )->setContent( $text );
500 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $text ), 0, 60 ) ) );
501 | }
502 |
503 | if( $text = $row['metatitle'] ?? null )
504 | {
505 | $listItem = $item->getListItems( 'text', 'default', 'meta-title' )->first() ?? $manager->createListItem();
506 | $refItem = $listItem->getRefItem() ?: $textManager->create();
507 | $refItem->setType( 'meta-title' )->setLanguageId( $langId )->setContent( $text );
508 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $text ), 0, 60 ) ) );
509 | }
510 |
511 | if( $text = $row['metadesc'] ?? null )
512 | {
513 | $listItem = $item->getListItems( 'text', 'default', 'meta-description' )->first() ?? $manager->createListItem();
514 | $refItem = $listItem->getRefItem() ?: $textManager->create();
515 | $refItem->setType( 'meta-description' )->setLanguageId( $langId )->setContent( $text );
516 | $item->addListItem( 'text', $listItem, $refItem->setLabel( mb_substr( strip_tags( $text ), 0, 60 ) ) );
517 | }
518 |
519 | if( $row['stock_status'] ?? null )
520 | {
521 | $stockItem = $item->getStockItems( 'default' )->first() ?? $stockManager->create();
522 | $stockManager->save( $stockItem->setProductId( $row['ID'] )->setStockLevel( $row['stock_quantity'] ) );
523 | }
524 |
525 | if( $parent = $items[$row['post_parent'] ?? null] ?? null )
526 | {
527 | $listItem = $parent->getListItem( 'product', 'default', $row['ID'] ) ?? $manager->createListItem();
528 | $parent->addListItem( 'product', $listItem->setRefId( $row['ID'] ) );
529 | }
530 | }
531 |
532 | return $items;
533 | }
534 |
535 |
536 | protected function properties( \Aimeos\Map $items )
537 | {
538 | $result = $this->db( 'db-woocommerce' )->query( "
539 | SELECT post_id, meta_key, meta_value
540 | FROM wp_postmeta
541 | WHERE meta_key in ('_weight', '_width', '_length', '_height')
542 | " );
543 |
544 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
545 |
546 | foreach( $result->iterateAssociative() as $row )
547 | {
548 | if( $item = $items->get( $row['post_id'] ) )
549 | {
550 | $type = substr( $row['meta_key'], 1 );
551 | $propItem = $item->getPropertyItems( $type )->first() ?? $manager->createPropertyItem();
552 | $item->addPropertyItem( $propItem->setType( $type )->setValue( $row['meta_value'] ) );
553 | }
554 | }
555 | }
556 |
557 |
558 | protected function suggests( \Aimeos\Map $items )
559 | {
560 | $result = $this->db( 'db-woocommerce' )->query( "
561 | SELECT post_id, meta_value
562 | FROM wp_postmeta
563 | WHERE meta_key = '_crosssell_ids'
564 | " );
565 |
566 | $manager = \Aimeos\MShop::create( $this->context(), 'product' );
567 |
568 | foreach( $result->iterateAssociative() as $row )
569 | {
570 | if( ( $item = $items->get( $row['post_id'] ) ) !== null && is_array( $list = unserialize( $row['meta_value'] ) ) )
571 | {
572 | foreach( $list as $id )
573 | {
574 | $listItem = $item->getListItem( 'product', 'suggest', $id ) ?? $manager->createListItem();
575 | $item->addListItem( 'product', $listItem->setType( 'suggest' )->setRefId( $id ) );
576 | }
577 | }
578 | }
579 | }
580 |
581 |
582 | protected function type( string $value )
583 | {
584 | return match( $value ) {
585 | 'grouped' => 'group',
586 | 'variable' => 'select',
587 | default => 'default'
588 | };
589 | }
590 | }
591 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 2.1, February 1999
3 |
4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | [This is the first released version of the Lesser GPL. It also counts
10 | as the successor of the GNU Library Public License, version 2, hence
11 | the version number 2.1.]
12 |
13 | Preamble
14 |
15 | The licenses for most software are designed to take away your
16 | freedom to share and change it. By contrast, the GNU General Public
17 | Licenses are intended to guarantee your freedom to share and change
18 | free software--to make sure the software is free for all its users.
19 |
20 | This license, the Lesser General Public License, applies to some
21 | specially designated software packages--typically libraries--of the
22 | Free Software Foundation and other authors who decide to use it. You
23 | can use it too, but we suggest you first think carefully about whether
24 | this license or the ordinary General Public License is the better
25 | strategy to use in any particular case, based on the explanations below.
26 |
27 | When we speak of free software, we are referring to freedom of use,
28 | not price. Our General Public Licenses are designed to make sure that
29 | you have the freedom to distribute copies of free software (and charge
30 | for this service if you wish); that you receive source code or can get
31 | it if you want it; that you can change the software and use pieces of
32 | it in new free programs; and that you are informed that you can do
33 | these things.
34 |
35 | To protect your rights, we need to make restrictions that forbid
36 | distributors to deny you these rights or to ask you to surrender these
37 | rights. These restrictions translate to certain responsibilities for
38 | you if you distribute copies of the library or if you modify it.
39 |
40 | For example, if you distribute copies of the library, whether gratis
41 | or for a fee, you must give the recipients all the rights that we gave
42 | you. You must make sure that they, too, receive or can get the source
43 | code. If you link other code with the library, you must provide
44 | complete object files to the recipients, so that they can relink them
45 | with the library after making changes to the library and recompiling
46 | it. And you must show them these terms so they know their rights.
47 |
48 | We protect your rights with a two-step method: (1) we copyright the
49 | library, and (2) we offer you this license, which gives you legal
50 | permission to copy, distribute and/or modify the library.
51 |
52 | To protect each distributor, we want to make it very clear that
53 | there is no warranty for the free library. Also, if the library is
54 | modified by someone else and passed on, the recipients should know
55 | that what they have is not the original version, so that the original
56 | author's reputation will not be affected by problems that might be
57 | introduced by others.
58 |
59 | Finally, software patents pose a constant threat to the existence of
60 | any free program. We wish to make sure that a company cannot
61 | effectively restrict the users of a free program by obtaining a
62 | restrictive license from a patent holder. Therefore, we insist that
63 | any patent license obtained for a version of the library must be
64 | consistent with the full freedom of use specified in this license.
65 |
66 | Most GNU software, including some libraries, is covered by the
67 | ordinary GNU General Public License. This license, the GNU Lesser
68 | General Public License, applies to certain designated libraries, and
69 | is quite different from the ordinary General Public License. We use
70 | this license for certain libraries in order to permit linking those
71 | libraries into non-free programs.
72 |
73 | When a program is linked with a library, whether statically or using
74 | a shared library, the combination of the two is legally speaking a
75 | combined work, a derivative of the original library. The ordinary
76 | General Public License therefore permits such linking only if the
77 | entire combination fits its criteria of freedom. The Lesser General
78 | Public License permits more lax criteria for linking other code with
79 | the library.
80 |
81 | We call this license the "Lesser" General Public License because it
82 | does Less to protect the user's freedom than the ordinary General
83 | Public License. It also provides other free software developers Less
84 | of an advantage over competing non-free programs. These disadvantages
85 | are the reason we use the ordinary General Public License for many
86 | libraries. However, the Lesser license provides advantages in certain
87 | special circumstances.
88 |
89 | For example, on rare occasions, there may be a special need to
90 | encourage the widest possible use of a certain library, so that it becomes
91 | a de-facto standard. To achieve this, non-free programs must be
92 | allowed to use the library. A more frequent case is that a free
93 | library does the same job as widely used non-free libraries. In this
94 | case, there is little to gain by limiting the free library to free
95 | software only, so we use the Lesser General Public License.
96 |
97 | In other cases, permission to use a particular library in non-free
98 | programs enables a greater number of people to use a large body of
99 | free software. For example, permission to use the GNU C Library in
100 | non-free programs enables many more people to use the whole GNU
101 | operating system, as well as its variant, the GNU/Linux operating
102 | system.
103 |
104 | Although the Lesser General Public License is Less protective of the
105 | users' freedom, it does ensure that the user of a program that is
106 | linked with the Library has the freedom and the wherewithal to run
107 | that program using a modified version of the Library.
108 |
109 | The precise terms and conditions for copying, distribution and
110 | modification follow. Pay close attention to the difference between a
111 | "work based on the library" and a "work that uses the library". The
112 | former contains code derived from the library, whereas the latter must
113 | be combined with the library in order to run.
114 |
115 | GNU LESSER GENERAL PUBLIC LICENSE
116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117 |
118 | 0. This License Agreement applies to any software library or other
119 | program which contains a notice placed by the copyright holder or
120 | other authorized party saying it may be distributed under the terms of
121 | this Lesser General Public License (also called "this License").
122 | Each licensee is addressed as "you".
123 |
124 | A "library" means a collection of software functions and/or data
125 | prepared so as to be conveniently linked with application programs
126 | (which use some of those functions and data) to form executables.
127 |
128 | The "Library", below, refers to any such software library or work
129 | which has been distributed under these terms. A "work based on the
130 | Library" means either the Library or any derivative work under
131 | copyright law: that is to say, a work containing the Library or a
132 | portion of it, either verbatim or with modifications and/or translated
133 | straightforwardly into another language. (Hereinafter, translation is
134 | included without limitation in the term "modification".)
135 |
136 | "Source code" for a work means the preferred form of the work for
137 | making modifications to it. For a library, complete source code means
138 | all the source code for all modules it contains, plus any associated
139 | interface definition files, plus the scripts used to control compilation
140 | and installation of the library.
141 |
142 | Activities other than copying, distribution and modification are not
143 | covered by this License; they are outside its scope. The act of
144 | running a program using the Library is not restricted, and output from
145 | such a program is covered only if its contents constitute a work based
146 | on the Library (independent of the use of the Library in a tool for
147 | writing it). Whether that is true depends on what the Library does
148 | and what the program that uses the Library does.
149 |
150 | 1. You may copy and distribute verbatim copies of the Library's
151 | complete source code as you receive it, in any medium, provided that
152 | you conspicuously and appropriately publish on each copy an
153 | appropriate copyright notice and disclaimer of warranty; keep intact
154 | all the notices that refer to this License and to the absence of any
155 | warranty; and distribute a copy of this License along with the
156 | Library.
157 |
158 | You may charge a fee for the physical act of transferring a copy,
159 | and you may at your option offer warranty protection in exchange for a
160 | fee.
161 |
162 | 2. You may modify your copy or copies of the Library or any portion
163 | of it, thus forming a work based on the Library, and copy and
164 | distribute such modifications or work under the terms of Section 1
165 | above, provided that you also meet all of these conditions:
166 |
167 | a) The modified work must itself be a software library.
168 |
169 | b) You must cause the files modified to carry prominent notices
170 | stating that you changed the files and the date of any change.
171 |
172 | c) You must cause the whole of the work to be licensed at no
173 | charge to all third parties under the terms of this License.
174 |
175 | d) If a facility in the modified Library refers to a function or a
176 | table of data to be supplied by an application program that uses
177 | the facility, other than as an argument passed when the facility
178 | is invoked, then you must make a good faith effort to ensure that,
179 | in the event an application does not supply such function or
180 | table, the facility still operates, and performs whatever part of
181 | its purpose remains meaningful.
182 |
183 | (For example, a function in a library to compute square roots has
184 | a purpose that is entirely well-defined independent of the
185 | application. Therefore, Subsection 2d requires that any
186 | application-supplied function or table used by this function must
187 | be optional: if the application does not supply it, the square
188 | root function must still compute square roots.)
189 |
190 | These requirements apply to the modified work as a whole. If
191 | identifiable sections of that work are not derived from the Library,
192 | and can be reasonably considered independent and separate works in
193 | themselves, then this License, and its terms, do not apply to those
194 | sections when you distribute them as separate works. But when you
195 | distribute the same sections as part of a whole which is a work based
196 | on the Library, the distribution of the whole must be on the terms of
197 | this License, whose permissions for other licensees extend to the
198 | entire whole, and thus to each and every part regardless of who wrote
199 | it.
200 |
201 | Thus, it is not the intent of this section to claim rights or contest
202 | your rights to work written entirely by you; rather, the intent is to
203 | exercise the right to control the distribution of derivative or
204 | collective works based on the Library.
205 |
206 | In addition, mere aggregation of another work not based on the Library
207 | with the Library (or with a work based on the Library) on a volume of
208 | a storage or distribution medium does not bring the other work under
209 | the scope of this License.
210 |
211 | 3. You may opt to apply the terms of the ordinary GNU General Public
212 | License instead of this License to a given copy of the Library. To do
213 | this, you must alter all the notices that refer to this License, so
214 | that they refer to the ordinary GNU General Public License, version 2,
215 | instead of to this License. (If a newer version than version 2 of the
216 | ordinary GNU General Public License has appeared, then you can specify
217 | that version instead if you wish.) Do not make any other change in
218 | these notices.
219 |
220 | Once this change is made in a given copy, it is irreversible for
221 | that copy, so the ordinary GNU General Public License applies to all
222 | subsequent copies and derivative works made from that copy.
223 |
224 | This option is useful when you wish to copy part of the code of
225 | the Library into a program that is not a library.
226 |
227 | 4. You may copy and distribute the Library (or a portion or
228 | derivative of it, under Section 2) in object code or executable form
229 | under the terms of Sections 1 and 2 above provided that you accompany
230 | it with the complete corresponding machine-readable source code, which
231 | must be distributed under the terms of Sections 1 and 2 above on a
232 | medium customarily used for software interchange.
233 |
234 | If distribution of object code is made by offering access to copy
235 | from a designated place, then offering equivalent access to copy the
236 | source code from the same place satisfies the requirement to
237 | distribute the source code, even though third parties are not
238 | compelled to copy the source along with the object code.
239 |
240 | 5. A program that contains no derivative of any portion of the
241 | Library, but is designed to work with the Library by being compiled or
242 | linked with it, is called a "work that uses the Library". Such a
243 | work, in isolation, is not a derivative work of the Library, and
244 | therefore falls outside the scope of this License.
245 |
246 | However, linking a "work that uses the Library" with the Library
247 | creates an executable that is a derivative of the Library (because it
248 | contains portions of the Library), rather than a "work that uses the
249 | library". The executable is therefore covered by this License.
250 | Section 6 states terms for distribution of such executables.
251 |
252 | When a "work that uses the Library" uses material from a header file
253 | that is part of the Library, the object code for the work may be a
254 | derivative work of the Library even though the source code is not.
255 | Whether this is true is especially significant if the work can be
256 | linked without the Library, or if the work is itself a library. The
257 | threshold for this to be true is not precisely defined by law.
258 |
259 | If such an object file uses only numerical parameters, data
260 | structure layouts and accessors, and small macros and small inline
261 | functions (ten lines or less in length), then the use of the object
262 | file is unrestricted, regardless of whether it is legally a derivative
263 | work. (Executables containing this object code plus portions of the
264 | Library will still fall under Section 6.)
265 |
266 | Otherwise, if the work is a derivative of the Library, you may
267 | distribute the object code for the work under the terms of Section 6.
268 | Any executables containing that work also fall under Section 6,
269 | whether or not they are linked directly with the Library itself.
270 |
271 | 6. As an exception to the Sections above, you may also combine or
272 | link a "work that uses the Library" with the Library to produce a
273 | work containing portions of the Library, and distribute that work
274 | under terms of your choice, provided that the terms permit
275 | modification of the work for the customer's own use and reverse
276 | engineering for debugging such modifications.
277 |
278 | You must give prominent notice with each copy of the work that the
279 | Library is used in it and that the Library and its use are covered by
280 | this License. You must supply a copy of this License. If the work
281 | during execution displays copyright notices, you must include the
282 | copyright notice for the Library among them, as well as a reference
283 | directing the user to the copy of this License. Also, you must do one
284 | of these things:
285 |
286 | a) Accompany the work with the complete corresponding
287 | machine-readable source code for the Library including whatever
288 | changes were used in the work (which must be distributed under
289 | Sections 1 and 2 above); and, if the work is an executable linked
290 | with the Library, with the complete machine-readable "work that
291 | uses the Library", as object code and/or source code, so that the
292 | user can modify the Library and then relink to produce a modified
293 | executable containing the modified Library. (It is understood
294 | that the user who changes the contents of definitions files in the
295 | Library will not necessarily be able to recompile the application
296 | to use the modified definitions.)
297 |
298 | b) Use a suitable shared library mechanism for linking with the
299 | Library. A suitable mechanism is one that (1) uses at run time a
300 | copy of the library already present on the user's computer system,
301 | rather than copying library functions into the executable, and (2)
302 | will operate properly with a modified version of the library, if
303 | the user installs one, as long as the modified version is
304 | interface-compatible with the version that the work was made with.
305 |
306 | c) Accompany the work with a written offer, valid for at
307 | least three years, to give the same user the materials
308 | specified in Subsection 6a, above, for a charge no more
309 | than the cost of performing this distribution.
310 |
311 | d) If distribution of the work is made by offering access to copy
312 | from a designated place, offer equivalent access to copy the above
313 | specified materials from the same place.
314 |
315 | e) Verify that the user has already received a copy of these
316 | materials or that you have already sent this user a copy.
317 |
318 | For an executable, the required form of the "work that uses the
319 | Library" must include any data and utility programs needed for
320 | reproducing the executable from it. However, as a special exception,
321 | the materials to be distributed need not include anything that is
322 | normally distributed (in either source or binary form) with the major
323 | components (compiler, kernel, and so on) of the operating system on
324 | which the executable runs, unless that component itself accompanies
325 | the executable.
326 |
327 | It may happen that this requirement contradicts the license
328 | restrictions of other proprietary libraries that do not normally
329 | accompany the operating system. Such a contradiction means you cannot
330 | use both them and the Library together in an executable that you
331 | distribute.
332 |
333 | 7. You may place library facilities that are a work based on the
334 | Library side-by-side in a single library together with other library
335 | facilities not covered by this License, and distribute such a combined
336 | library, provided that the separate distribution of the work based on
337 | the Library and of the other library facilities is otherwise
338 | permitted, and provided that you do these two things:
339 |
340 | a) Accompany the combined library with a copy of the same work
341 | based on the Library, uncombined with any other library
342 | facilities. This must be distributed under the terms of the
343 | Sections above.
344 |
345 | b) Give prominent notice with the combined library of the fact
346 | that part of it is a work based on the Library, and explaining
347 | where to find the accompanying uncombined form of the same work.
348 |
349 | 8. You may not copy, modify, sublicense, link with, or distribute
350 | the Library except as expressly provided under this License. Any
351 | attempt otherwise to copy, modify, sublicense, link with, or
352 | distribute the Library is void, and will automatically terminate your
353 | rights under this License. However, parties who have received copies,
354 | or rights, from you under this License will not have their licenses
355 | terminated so long as such parties remain in full compliance.
356 |
357 | 9. You are not required to accept this License, since you have not
358 | signed it. However, nothing else grants you permission to modify or
359 | distribute the Library or its derivative works. These actions are
360 | prohibited by law if you do not accept this License. Therefore, by
361 | modifying or distributing the Library (or any work based on the
362 | Library), you indicate your acceptance of this License to do so, and
363 | all its terms and conditions for copying, distributing or modifying
364 | the Library or works based on it.
365 |
366 | 10. Each time you redistribute the Library (or any work based on the
367 | Library), the recipient automatically receives a license from the
368 | original licensor to copy, distribute, link with or modify the Library
369 | subject to these terms and conditions. You may not impose any further
370 | restrictions on the recipients' exercise of the rights granted herein.
371 | You are not responsible for enforcing compliance by third parties with
372 | this License.
373 |
374 | 11. If, as a consequence of a court judgment or allegation of patent
375 | infringement or for any other reason (not limited to patent issues),
376 | conditions are imposed on you (whether by court order, agreement or
377 | otherwise) that contradict the conditions of this License, they do not
378 | excuse you from the conditions of this License. If you cannot
379 | distribute so as to satisfy simultaneously your obligations under this
380 | License and any other pertinent obligations, then as a consequence you
381 | may not distribute the Library at all. For example, if a patent
382 | license would not permit royalty-free redistribution of the Library by
383 | all those who receive copies directly or indirectly through you, then
384 | the only way you could satisfy both it and this License would be to
385 | refrain entirely from distribution of the Library.
386 |
387 | If any portion of this section is held invalid or unenforceable under any
388 | particular circumstance, the balance of the section is intended to apply,
389 | and the section as a whole is intended to apply in other circumstances.
390 |
391 | It is not the purpose of this section to induce you to infringe any
392 | patents or other property right claims or to contest validity of any
393 | such claims; this section has the sole purpose of protecting the
394 | integrity of the free software distribution system which is
395 | implemented by public license practices. Many people have made
396 | generous contributions to the wide range of software distributed
397 | through that system in reliance on consistent application of that
398 | system; it is up to the author/donor to decide if he or she is willing
399 | to distribute software through any other system and a licensee cannot
400 | impose that choice.
401 |
402 | This section is intended to make thoroughly clear what is believed to
403 | be a consequence of the rest of this License.
404 |
405 | 12. If the distribution and/or use of the Library is restricted in
406 | certain countries either by patents or by copyrighted interfaces, the
407 | original copyright holder who places the Library under this License may add
408 | an explicit geographical distribution limitation excluding those countries,
409 | so that distribution is permitted only in or among countries not thus
410 | excluded. In such case, this License incorporates the limitation as if
411 | written in the body of this License.
412 |
413 | 13. The Free Software Foundation may publish revised and/or new
414 | versions of the Lesser General Public License from time to time.
415 | Such new versions will be similar in spirit to the present version,
416 | but may differ in detail to address new problems or concerns.
417 |
418 | Each version is given a distinguishing version number. If the Library
419 | specifies a version number of this License which applies to it and
420 | "any later version", you have the option of following the terms and
421 | conditions either of that version or of any later version published by
422 | the Free Software Foundation. If the Library does not specify a
423 | license version number, you may choose any version ever published by
424 | the Free Software Foundation.
425 |
426 | 14. If you wish to incorporate parts of the Library into other free
427 | programs whose distribution conditions are incompatible with these,
428 | write to the author to ask for permission. For software which is
429 | copyrighted by the Free Software Foundation, write to the Free
430 | Software Foundation; we sometimes make exceptions for this. Our
431 | decision will be guided by the two goals of preserving the free status
432 | of all derivatives of our free software and of promoting the sharing
433 | and reuse of software generally.
434 |
435 | NO WARRANTY
436 |
437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446 |
447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456 | DAMAGES.
457 |
458 | END OF TERMS AND CONDITIONS
459 |
460 | How to Apply These Terms to Your New Libraries
461 |
462 | If you develop a new library, and you want it to be of the greatest
463 | possible use to the public, we recommend making it free software that
464 | everyone can redistribute and change. You can do so by permitting
465 | redistribution under these terms (or, alternatively, under the terms of the
466 | ordinary General Public License).
467 |
468 | To apply these terms, attach the following notices to the library. It is
469 | safest to attach them to the start of each source file to most effectively
470 | convey the exclusion of warranty; and each file should have at least the
471 | "copyright" line and a pointer to where the full notice is found.
472 |
473 |
474 | Copyright (C)
475 |
476 | This library is free software; you can redistribute it and/or
477 | modify it under the terms of the GNU Lesser General Public
478 | License as published by the Free Software Foundation; either
479 | version 2.1 of the License, or (at your option) any later version.
480 |
481 | This library is distributed in the hope that it will be useful,
482 | but WITHOUT ANY WARRANTY; without even the implied warranty of
483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
484 | Lesser General Public License for more details.
485 |
486 | You should have received a copy of the GNU Lesser General Public
487 | License along with this library; if not, write to the Free Software
488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
489 | USA
490 |
491 | Also add information on how to contact you by electronic and paper mail.
492 |
493 | You should also get your employer (if you work as a programmer) or your
494 | school, if any, to sign a "copyright disclaimer" for the library, if
495 | necessary. Here is a sample; alter the names:
496 |
497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the
498 | library `Frob' (a library for tweaking knobs) written by James Random
499 | Hacker.
500 |
501 | , 1 April 1990
502 | Ty Coon, President of Vice
503 |
504 | That's all there is to it!
505 |
--------------------------------------------------------------------------------