Jump to content

Change addon price when configoption is selected


pRieStaKos

Recommended Posts

Hello, 

I want to change an addon price (Support Plan), when client chooses a specific configoption.

I tried  from OrderAddonPricingOverride and PreCalculateCartTotals from Shopping Cart, but neither of them worked.

add_hook('OrderAddonPricingOverride', 1, function($vars) {
    $return = [];
    foreach($_SESSION['cart']['products'] as $product) {
        // This is a product with addon purchase
        $productObj = Product::find($product['pid']);
        if ($productObj->module == "OvhVpsAndDedicated") {
            foreach($product['configoptions'] as $id => $configOption) {
                $optionName = Capsule::table('tblproductconfigoptions')->where('id', $id)->value('optionName');
                if ($optionName == "Storage") {
                    $price = Capsule::table('tblpricing')
                              ->where('type','configoptions')
                              ->where('currency', 1)
                              ->where('relid', $configOption)
                              ->value('monthly');
                    $return = ['recurring' => $price['monthly'] * 1.20];
                }
            }
        }
    }
    return $return;
});

Any suggestions ?

Thank you in advance.

Edited by pRieStaKos
Link to comment
Share on other sites

Try using OrderProductPricingOverride instead as you're dealing with configurable options here and not addons and OrderAddonPricingOverride wont fire otherwise.  I tested with  OrderProductPricingOverride and it worked.   Also I will presume you have the use capsule and product lines above this. 

Link to comment
Share on other sites

12 minutes ago, steven99 said:

Try using OrderProductPricingOverride instead as you're dealing with configurable options here and not addons and OrderAddonPricingOverride wont fire otherwise.  I tested with  OrderProductPricingOverride and it worked.   Also I will presume you have the use capsule and product lines above this. 

Worked with 

$return = ['recurring' => $price * 1.20];
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated