diff --git a/backend/3rdparty/woocommerce-product-bundles.zip b/backend/3rdparty/woocommerce-product-bundles.zip new file mode 100644 index 0000000..e96c63b Binary files /dev/null and b/backend/3rdparty/woocommerce-product-bundles.zip differ diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-db-update.php b/backend/app/plugins/wiaas/includes/class-wiaas-db-update.php index e787b1c..9121bb4 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-db-update.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-db-update.php @@ -11,7 +11,8 @@ class Wiaas_DB_Update { '20180807222206' => 'wiaas_db_update_setup_customer_capabilities', '20180809134511' => 'wiaas_db_update_add_customer_read_permission', '20180811134511' => 'wiaas_db_update_enable_orders_access_management', - '20180813134511' => 'wiaas_db_update_enable_order_numbers' + '20180813134511' => 'wiaas_db_update_enable_order_numbers', + '20180826153509' => 'wiaas_create_broker_access_group' ); public static function execute() { diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-order.php b/backend/app/plugins/wiaas/includes/class-wiaas-order.php index 2d26e05..f6ba5a4 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-order.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-order.php @@ -15,7 +15,7 @@ class Wiaas_Order { add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4); - add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 10, 3); + add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 999, 3); add_filter('woocommerce_rest_orders_prepare_object_query', array( __CLASS__, 'wiaas_prepare_rest_orders_query'), 10, 2); } @@ -148,7 +148,7 @@ class Wiaas_Order { } /** - * Appends additional wiaas products info to order json response + * Filters only package product lines and appends additional wiaas products info to order json response * @param $data * @param $order * @param $request @@ -156,35 +156,41 @@ class Wiaas_Order { * @return mixed */ private static function _append_products_info($data, $order, $request) { + $line_items = array(); foreach ($data['line_items'] as $index => $product_line) { - # lock all products to `Purchase` payment type - $product_line['payment_type'] = 'Purchase'; + // add only product lines that represent product bundles + if (empty($product_line['bundled_by'])) { + # lock all products to `Purchase` payment type + $product_line['payment_type'] = 'Purchase'; - # lock all products to have no service - $product_line['service_price'] = 0; - $product_line['service_contract_period'] = 0; - $product_line['max_contract_period'] = 36; - $product_line['period_unit'] = 'month'; + # lock all products to have no service + $product_line['service_price'] = 0; + $product_line['service_contract_period'] = 0; + $product_line['max_contract_period'] = 36; + $product_line['period_unit'] = 'month'; - # simplify payment for all products - $product_line['recurring_price'] = 0; - $product_line['pay_period'] = 0; + # simplify payment for all products + $product_line['recurring_price'] = 0; + $product_line['pay_period'] = 0; - # collect status from order - if ($data['status'] === 'completed') { - $product_line['status'] = 'production'; - } else if ($data['status'] === 'cancelled') { - $product_line['status'] = 'cancelled'; - } else { - $product_line['status'] = 'processing'; + # collect status from order + if ($data['status'] === 'completed') { + $product_line['status'] = 'production'; + } else if ($data['status'] === 'cancelled') { + $product_line['status'] = 'cancelled'; + } else { + $product_line['status'] = 'processing'; + } + $product_line['short_desc'] = $product_line['status']; + + # collect completion data from order + $product_line['date_completed'] = $data['date_completed']; + + $line_items[] = $product_line; } - $product_line['short_desc'] = $product_line['status']; - - # collect completion data from order - $product_line['date_completed'] = $data['date_completed']; - - $data['line_items'][$index] = $product_line; } + $data['line_items'] = $line_items; + return $data; } diff --git a/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-functions.php b/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-functions.php index 06b2694..3ce2174 100644 --- a/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-functions.php +++ b/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-functions.php @@ -107,3 +107,9 @@ function wiaas_db_update_enable_order_numbers() { update_option('wcj_order_number_counter_reset_enabled', 'no'); update_option('wcj_order_number_prefix', '1000000'); } + +function wiaas_create_broker_access_group() { + Groups_Group::create(array( + 'name' => 'Broker', + )); +} \ No newline at end of file diff --git a/backend/composer.json b/backend/composer.json index c79d66b..1fe0274 100644 --- a/backend/composer.json +++ b/backend/composer.json @@ -29,6 +29,18 @@ "reference": "origin/master" } } + }, + { + "type": "package", + "package": { + "name": "3rdparty/woocommerce-product-bundles", + "type": "wordpress-plugin", + "version": "5.7.11", + "dist": { + "url": "3rdparty/woocommerce-product-bundles.zip", + "type": "zip" + } + } } ], "require": { @@ -51,7 +63,8 @@ "wpackagist-plugin/wp-user-groups": "2.2.0", "3rdparty/gravityforms": "*", - "3rdparty/gravityflow": "*" + "3rdparty/gravityflow": "*", + "3rdparty/woocommerce-product-bundles": "*" }, "require-dev": { "vlucas/phpdotenv": "2.5.0" @@ -73,6 +86,7 @@ ], "activate-plugins": [ "wp plugin activate woocommerce", + "wp plugin activate woocommerce-product-bundles", "wp plugin activate woocommerce-jetpack", "wp plugin activate jwt-authentication-for-wp-rest-api", "wp plugin activate gravityforms", @@ -86,6 +100,7 @@ "wp core update-db", "composer activate-plugins", "wp wc update", + "wp wc pb update", "wp wiaas update-db" ] } diff --git a/backend/composer.lock b/backend/composer.lock index bb5efa2..b59d0b9 100644 --- a/backend/composer.lock +++ b/backend/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "798e9b8b675248e2b8dbc2bc7dcab511", + "content-hash": "302f569929ecdaf4d349b0bf764de74c", "packages": [ { "name": "3rdparty/gravityflow", @@ -26,6 +26,17 @@ }, "type": "wordpress-plugin" }, + { + "name": "3rdparty/woocommerce-product-bundles", + "version": "5.7.11", + "dist": { + "type": "zip", + "url": "3rdparty/woocommerce-product-bundles.zip", + "reference": null, + "shasum": null + }, + "type": "wordpress-plugin" + }, { "name": "composer/installers", "version": "v1.5.0", diff --git a/frontend/src/actions/coMarket/coMarketPackagesActions.js b/frontend/src/actions/coMarket/coMarketPackagesActions.js index ec55aee..d85a169 100644 --- a/frontend/src/actions/coMarket/coMarketPackagesActions.js +++ b/frontend/src/actions/coMarket/coMarketPackagesActions.js @@ -9,6 +9,8 @@ import { RECIEVE_SHOP_COMMERCIAL_LEADS, SELECT_SHOP_COMMERCIAL_LEAD } from '../../constants/coMarketConstants'; +import { fromWCPackage } from '../../helpers/PackageHelper'; + const client = new HtmlClient(); const requestShopPackages = () => ({ @@ -37,7 +39,7 @@ export const fetchShopPackages = (cl, search) => { }) .then(response => { if (response.data) { - dispatch(recieveShopPackages(response.data)) + dispatch(recieveShopPackages(response.data.map(wcPackage => fromWCPackage(wcPackage)))) } }) .catch(error => { diff --git a/frontend/src/containers/coMarket/components/ShopItem.jsx b/frontend/src/containers/coMarket/components/ShopItem.jsx index 5f74f39..9817c9d 100644 --- a/frontend/src/containers/coMarket/components/ShopItem.jsx +++ b/frontend/src/containers/coMarket/components/ShopItem.jsx @@ -14,7 +14,10 @@ class ShopItem extends Component { return ( -
+
diff --git a/frontend/src/helpers/PackageHelper.js b/frontend/src/helpers/PackageHelper.js new file mode 100644 index 0000000..97a276b --- /dev/null +++ b/frontend/src/helpers/PackageHelper.js @@ -0,0 +1,16 @@ + +const DEFAULT_PACKAGE_IMG = 'static/img/no-photo-package.jpg'; + +export const fromWCPackage = wcPackage => { + return { + id: wcPackage.id, + reference: wcPackage.slug, + image: wcPackage.images[0].src || DEFAULT_PACKAGE_IMG, + name: wcPackage.name, + country: 'Sweden', + countryCode: 'se', + currency: 'SEK', + documents: [], + shortDescription: wcPackage.description, + } +}; \ No newline at end of file