<commit_before><?php


class CustomisableProductShoppingCart extends Extension {

    /**
     * Augment setup to get item price
     *
     */
    public function augmentSetup() {
        foreach($this->owner->Items as $item) {
            if($item->Customisations && is_array($item->Customisations)) {
                $base_price = $item->Price->RAW();
                $customisations = ArrayList::create();

                foreach($item->Customisations as $customisation) {
                    if($customisation['Price'])
                        $base_price += $customisation['Price'];

                    $customisations->add($customisation);
                }

                $item->Customisations = $customisations;
                $item->Price->setValue($base_price);
            }

            // If tax rate set work out tax
            if($item->TaxRate) {
                $tax = new Currency("Tax");
                $tax->setValue(($item->Price->RAW() / 100) * $item->TaxRate);
                $item->Tax = $tax;
            }
        }
    }

    public function onBeforeSave($items) {
        // Convert customisations back to an array
        foreach($this->owner->items as $item) {
            if($item->Customisations && is_object($item->Customisations)) {
                $customisations = array();

                foreach($item->Customisations as $customisation) {
                    $customisations[] = array(
                        "Title" => $customisation->Title,
                        "Value" => $customisation->Value,
                        "Price" => $customisation->Price
                    );
                }

                $item->Customisations = $customisations;
            }
        }
    }
}
<commit_msg>Update shoppingcart setup to use updated tax calculation<commit_after><?php


class CustomisableProductShoppingCart extends Extension {

    /**
     * Augment setup to get item price
     *
     */
    public function augmentSetup() {
        foreach($this->owner->Items as $item) {
            if($item->Customisations && is_array($item->Customisations)) {
                $base_price = $item->Price->RAW();
                $customisations = ArrayList::create();

                foreach($item->Customisations as $customisation) {
                    if($customisation['Price'])
                        $base_price += $customisation['Price'];

                    $customisations->add($customisation);
                }

                $item->Customisations = $customisations;
                $item->Price->setValue($base_price);
            }

            // If tax rate set work out tax
            if($item->TaxRate) {
                $item->Tax = new Currency("Tax");
                $item->Tax->setValue((($item->Price->RAW() - $item->Discount->RAW()) / 100) * $item->TaxRate);
            }
        }
    }

    public function onBeforeSave($items) {
        // Convert customisations back to an array
        foreach($this->owner->items as $item) {
            if($item->Customisations && is_object($item->Customisations)) {
                $customisations = array();

                foreach($item->Customisations as $customisation) {
                    $customisations[] = array(
                        "Title" => $customisation->Title,
                        "Value" => $customisation->Value,
                        "Price" => $customisation->Price
                    );
                }

                $item->Customisations = $customisations;
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.13025091626726812, 'fraction_numerical': 0.0016915703411333521, 'mean_word_length': 1.518097941802697, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3429175', 'n_tokens_mistral': 928, 'n_tokens_neox': 833, 'n_words': 162}