diff --git a/Makefile b/Makefile index 1faab50..67c4520 100644 --- a/Makefile +++ b/Makefile @@ -47,4 +47,3 @@ coverage: build_archive: zip -r $(ARCHIVE_NAME) ./src/* - diff --git a/src/include/class-wc-retailcrm-icml.php b/src/include/class-wc-retailcrm-icml.php index ee21a86..5c33cd6 100644 --- a/src/include/class-wc-retailcrm-icml.php +++ b/src/include/class-wc-retailcrm-icml.php @@ -36,6 +36,8 @@ if (!class_exists('WC_Retailcrm_Icml')) : protected $icmlWriter; + protected $unloadServices = false; + /** * WC_Retailcrm_Icml constructor. * @@ -47,6 +49,10 @@ if (!class_exists('WC_Retailcrm_Icml')) : $this->tmpFile = sprintf('%s.tmp', $this->file); $this->settings = get_option(WC_Retailcrm_Base::$option_key); $this->icmlWriter = new WC_Retailcrm_Icml_Writer($this->tmpFile); + $this->unloadServices = ( + isset($this->settings['icml_services']) && + $this->settings['icml_services'] === WC_Retailcrm_Base::YES + ); } public function changeBindBySku($useXmlId) @@ -252,7 +258,8 @@ if (!class_exists('WC_Retailcrm_Icml')) : 'categoryId' => $termList, 'dimensions' => $dimensions, 'weight' => $weight, - 'tax' => isset($tax) ? $tax['rate'] : 'none' + 'tax' => isset($tax) ? $tax['rate'] : 'none', + 'type' => ($this->unloadServices && $product->is_virtual()) ? 'service' : 'product', ]; if ($product->get_sku() !== '') { diff --git a/src/include/icml/class-wc-retailcrm-icml-writer.php b/src/include/icml/class-wc-retailcrm-icml-writer.php index 5980223..fa70502 100644 --- a/src/include/icml/class-wc-retailcrm-icml-writer.php +++ b/src/include/icml/class-wc-retailcrm-icml-writer.php @@ -121,6 +121,7 @@ if (!class_exists('WC_Retailcrm_Icml_Writer')) : $this->writer->writeAttribute('id', $offer['id']); $this->writer->writeAttribute('productId', $offer['productId']); $this->writer->writeAttribute('quantity', (int) $offer['quantity'] ?? 0); + $this->writer->writeAttribute('type', $offer['type']); if (isset($offer['categoryId'])) { if (is_array($offer['categoryId'])) { diff --git a/tests/helpers/class-wc-retailcrm-test-case-helper.php b/tests/helpers/class-wc-retailcrm-test-case-helper.php index a099ac2..a89eb35 100644 --- a/tests/helpers/class-wc-retailcrm-test-case-helper.php +++ b/tests/helpers/class-wc-retailcrm-test-case-helper.php @@ -80,6 +80,7 @@ class WC_Retailcrm_Test_Case_Helper extends WC_Unit_Test_Case 'product_description' => 'full', 'stores_for_uploading' => ['woocommerce', 'main'], 'woo_coupon_apply_field' => 'testField', + 'icml_services' => 'yes' ]; update_option(WC_Retailcrm_Base::$option_key, $options); diff --git a/tests/test-wc-retailcrm-icml.php b/tests/test-wc-retailcrm-icml.php index ff751c6..8c154aa 100644 --- a/tests/test-wc-retailcrm-icml.php +++ b/tests/test-wc-retailcrm-icml.php @@ -17,6 +17,9 @@ class WC_Retailcrm_Icml_Test extends WC_Retailcrm_Test_Case_Helper { WC_Helper_Product::create_simple_product(); WC_Helper_Product::create_variation_product(); + + $this->createVirtualProduct(); + $this->setOptions(); } public function testGenerate() @@ -35,9 +38,9 @@ class WC_Retailcrm_Icml_Test extends WC_Retailcrm_Test_Case_Helper $this->assertNotEmpty($xmlArray['shop']['categories']['category']); $this->assertCount(2, $xmlArray['shop']['categories']['category']); $this->assertNotEmpty($xmlArray['shop']['offers']['offer']); - $this->assertCount(7, $xmlArray['shop']['offers']['offer']); $this->assertNotEmpty($xmlArray['shop']['offers']['offer'][0]); $this->assertNotEmpty($xmlArray['shop']['offers']['offer'][1]); + $this->assertNotEmpty($xmlArray['shop']['offers']['offer'][2]); foreach ($xmlArray['shop']['offers']['offer'] as $product) { $this->assertNotEmpty($product['name']); @@ -48,6 +51,34 @@ class WC_Retailcrm_Icml_Test extends WC_Retailcrm_Test_Case_Helper $this->assertNotEmpty($product['vatRate']); $this->assertEquals('none', $product['vatRate']); $this->assertContains('Dummy', $product['productName']); + $this->assertNotEmpty($product['@attributes']['type']); } + + $attributesList = array_column($xmlArray['shop']['offers']['offer'], '@attributes'); + $typeList = array_column($attributesList, 'type'); + + $this->assertContains('service', $typeList); + } + + private function createVirtualProduct() + { + $product = wp_insert_post( array( + 'post_title' => 'Dummy Product', + 'post_type' => 'product', + 'post_status' => 'publish', + ) ); + update_post_meta( $product, '_price', '10' ); + update_post_meta( $product, '_regular_price', '10' ); + update_post_meta( $product, '_sale_price', '' ); + update_post_meta( $product, '_sku', 'DUMMY SKU' ); + update_post_meta( $product, '_manage_stock', 'no' ); + update_post_meta( $product, '_tax_status', 'taxable' ); + update_post_meta( $product, '_downloadable', 'no' ); + update_post_meta( $product, '_virtual', 'yes' ); + update_post_meta( $product, '_stock_status', 'instock' ); + update_post_meta( $product, '_weight', '1.1' ); + wp_set_object_terms( $product, 'simple', 'product_type' ); + + return new WC_Product_Simple( $product ); } }