Add package addons and options
This commit is contained in:
@@ -72,10 +72,9 @@ class Wiaas_Cart_API {
|
||||
$count = 0;
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
if (isset($item['bundled_by'])) {
|
||||
continue;
|
||||
if (isset($item['_wiaas_standard_package'])) {
|
||||
$count++;
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
|
||||
return new WP_REST_Response(array(
|
||||
@@ -94,17 +93,52 @@ class Wiaas_Cart_API {
|
||||
$result = array();
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
if (isset($item['bundled_by'])) {
|
||||
if (!isset($item['_wiaas_standard_package'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$package = wc_get_product($item['product_id']);
|
||||
|
||||
// Retrieve package addons
|
||||
$addon_cart_items = Wiaas_Package_Addon::get_cart_item_addons($item);
|
||||
$additional_packages = array();
|
||||
|
||||
foreach ($addon_cart_items as $addon_cart_item) {
|
||||
$additional_package = wc_get_product($addon_cart_item['product_id']);
|
||||
$additional_packages[] = array(
|
||||
'idAdditionalPackage' => $additional_package->get_id(),
|
||||
'packageName' => $additional_package->get_title(),
|
||||
'prices' => array(
|
||||
'fixedExtra' => $addon_cart_item['_wiaas_payment']['minimal_fixed_price'],
|
||||
'recurentExtra' => $addon_cart_item['_wiaas_payment']['recurrent_price'],
|
||||
'servicesExtra' => $addon_cart_item['_wiaas_payment']['minimal_services_price'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Retrieve package options
|
||||
$option_cart_items = Wiaas_Package_Option_Groups::get_cart_item_options($item);
|
||||
$package_options = array();
|
||||
foreach ($option_cart_items as $option_cart_item) {
|
||||
$option_package = wc_get_product($option_cart_item['product_id']);
|
||||
$package_options[] = array(
|
||||
'idOptionPackage' => $option_package->get_id(),
|
||||
'groupName' => $option_package->get_title(),
|
||||
'packageName' => $option_package->get_title(),
|
||||
'prices' => array(
|
||||
'fixedExtra' => $item['_wiaas_payment']['minimal_fixed_price'],
|
||||
'recurentExtra' => $item['_wiaas_payment']['recurrent_price'],
|
||||
'servicesExtra' => $item['_wiaas_payment']['minimal_services_price'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$result[] = array(
|
||||
'idPackage' => $item['product_id'],
|
||||
'key' => $item['key'],
|
||||
'packageName' => $package->get_title(),
|
||||
'additionalPackages' => array(),
|
||||
'additionalPackages' => $additional_packages,
|
||||
'areAdditionalAvailable' => true,
|
||||
'areOptionsAvailable' => true,
|
||||
'bids' => array(),
|
||||
@@ -112,21 +146,21 @@ class Wiaas_Cart_API {
|
||||
'country' => array(
|
||||
'currency' => 'SEK'
|
||||
),
|
||||
'options' => array(),
|
||||
'options' => $package_options,
|
||||
'quantity' => $item['quantity'],
|
||||
|
||||
'idPayType' => $item['_wiaas_price']['id'],
|
||||
'payType' => $item['_wiaas_price']['payment_type'],
|
||||
'periodUnit' => $item['_wiaas_price']['period_unit'],
|
||||
'idPrice' => $item['_wiaas_price']['id'],
|
||||
'fixedPrice' => $item['_wiaas_price']['minimal_fixed_price'],
|
||||
'recurentPrice' => $item['_wiaas_price']['recurrent_price'],
|
||||
'servicesPrice' => $item['_wiaas_price']['minimal_services_price'],
|
||||
'idPayType' => $item['_wiaas_payment']['id'],
|
||||
'payType' => $item['_wiaas_payment']['payment_type'],
|
||||
'periodUnit' => $item['_wiaas_payment']['period_unit'],
|
||||
'idPrice' => $item['_wiaas_payment']['id'],
|
||||
'fixedPrice' => $item['_wiaas_payment']['minimal_fixed_price'],
|
||||
'recurentPrice' => $item['_wiaas_payment']['recurrent_price'],
|
||||
'servicesPrice' => $item['_wiaas_payment']['minimal_services_price'],
|
||||
|
||||
'totalPrices' => array(
|
||||
'fixedPrice' => $item['_wiaas_price']['minimal_fixed_price'],
|
||||
'recurentPrice' => $item['_wiaas_price']['recurrent_price'],
|
||||
'servicesPrice' => $item['_wiaas_price']['minimal_services_price'],
|
||||
'fixedPrice' => $item['_wiaas_payment']['minimal_fixed_price'],
|
||||
'recurentPrice' => $item['_wiaas_payment']['recurrent_price'],
|
||||
'servicesPrice' => $item['_wiaas_payment']['minimal_services_price'],
|
||||
),
|
||||
|
||||
'status' => 'available',
|
||||
@@ -136,6 +170,7 @@ class Wiaas_Cart_API {
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'cartItems' => $result,
|
||||
'items' => $items,
|
||||
'totalPrice' => ''
|
||||
)
|
||||
);
|
||||
@@ -162,22 +197,10 @@ class Wiaas_Cart_API {
|
||||
*/
|
||||
public static function add_package_to_cart() {
|
||||
$package_id = $_POST['package_id'];
|
||||
$price_id = $_POST['price_id'];
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
$prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
$selected_price = $prices[$price_id];
|
||||
|
||||
WC()->session->set('wiaas_price_' . $package_id, $price_id);
|
||||
|
||||
$success = WC()->cart->add_to_cart(
|
||||
$package_id,
|
||||
1,
|
||||
0,
|
||||
array(),
|
||||
array(
|
||||
'_wiaas_price' => $selected_price,
|
||||
));
|
||||
$success = WC()->cart->add_to_cart($package_id, 1, 0, array(), array(
|
||||
'_wiaas_standard_package' => true
|
||||
));
|
||||
|
||||
if ($success) {
|
||||
return new WP_REST_Response(array(
|
||||
|
||||
Reference in New Issue
Block a user