diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache new file mode 100644 index 0000000..77e4337 --- /dev/null +++ b/.php-cs-fixer.cache @@ -0,0 +1 @@ +{"php":"8.1.9","version":"3.10.0:v3.10.0#76d7da666e66d83a1dc27a9d1c625c80cc4ac1fe","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true,"allow_single_line_closure":true},"class_definition":{"single_line":true},"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ignore"},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true,"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":true,"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"array_syntax":{"syntax":"short"},"backtick_to_shell_exec":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["return"]},"cast_spaces":{"space":"none"},"class_attributes_separation":{"elements":{"method":"one"}},"class_reference_name_casing":true,"clean_namespace":true,"concat_space":{"spacing":"one"},"echo_tag_syntax":true,"empty_loop_body":{"style":"braces"},"empty_loop_condition":true,"fully_qualified_strict_types":true,"function_typehint_space":true,"general_phpdoc_tag_rename":{"replacements":{"inheritDocs":"inheritDoc"}},"include":true,"integer_literal_case":true,"lambda_not_used_import":true,"linebreak_after_opening_tag":true,"magic_constant_casing":true,"magic_method_casing":true,"native_function_casing":true,"native_function_type_declaration_casing":true,"no_alias_language_construct_call":true,"no_alternative_syntax":true,"no_binary_string":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["attribute","case","continue","curly_brace_block","default","extra","parenthesis_brace_block","square_brace_block","switch","throw","use"]},"no_leading_namespace_whitespace":true,"no_mixed_echo_print":true,"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_trailing_comma_in_singleline_function_call":true,"no_unneeded_control_parentheses":{"statements":["break","clone","continue","echo_print","others","return","switch_case","yield","yield_from"]},"no_unneeded_curly_braces":{"namespaces":true},"no_unneeded_import_alias":true,"no_unset_cast":true,"no_unused_imports":true,"no_useless_nullsafe_operator":true,"no_whitespace_before_comma_in_array":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"php_unit_fqcn_annotation":true,"php_unit_method_casing":true,"phpdoc_align":{"align":"left"},"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag_normalizer":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_order":{"order":["param","return","throws"]},"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_single_line_var_spacing":true,"phpdoc_tag_type":{"tags":{"inheritDoc":"inline"}},"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_trim_consecutive_blank_line_separation":true,"phpdoc_types":true,"phpdoc_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"phpdoc_var_without_name":true,"protected_to_private":true,"semicolon_after_instruction":true,"simple_to_complex_string_variable":true,"single_line_comment_spacing":true,"single_line_comment_style":{"comment_types":["hash"]},"single_line_throw":true,"single_quote":true,"single_space_after_construct":{"constructs":["abstract","as","attribute","break","case","catch","class","clone","comment","const","const_import","continue","do","echo","else","elseif","enum","extends","final","finally","for","foreach","function","function_import","global","goto","if","implements","include","include_once","instanceof","insteadof","interface","match","named_argument","namespace","new","open_tag_with_echo","php_doc","php_open","print","private","protected","public","readonly","require","require_once","return","static","switch","throw","trait","try","type_colon","use","use_lambda","use_trait","var","while","yield","yield_from"]},"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":true,"standardize_not_equals":true,"switch_continue_to_break":true,"trailing_comma_in_multiline":true,"trim_array_spaces":true,"types_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"general_phpdoc_annotation_remove":{"annotations":["author","category","see","since","version"]}},"hashes":{"system\/user\/addons\/cartthrob_order_loader\/addon.setup.php":1531618901,"system\/user\/addons\/cartthrob_order_loader\/pi.cartthrob_order_loader.php":4187454962}} \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..0aeaeed --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,34 @@ +exclude('automation') + ->exclude('build') + ->name('*.php') + ->in(__DIR__) + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +$config = new PhpCsFixer\Config(); +return $config + ->setRules([ + '@PSR2' => true, + '@PSR12' => true, + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + 'cast_spaces' => ['space' => 'none'], + 'concat_space' => ['spacing' => 'one'], + 'general_phpdoc_annotation_remove' => [ + 'annotations' => ['author', 'category', 'see', 'since', 'version'], + ], + 'increment_style' => false, + 'linebreak_after_opening_tag' => true, + 'no_superfluous_phpdoc_tags' => false, + 'ordered_imports' => true, + 'phpdoc_align' => ['align' => 'left'], + 'phpdoc_separation' => false, + 'phpdoc_summary' => false, + 'yoda_style' => false, + ]) + ->setFinder($finder); \ No newline at end of file diff --git a/README.md b/README.md index 07e3be3..08c0fc3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ -plugin-load-order -================= +# CartThrobOrderLoader -Loads a previous order into the cart. +* [Build Process](/documentation/build.md) +* [Release Process](/documentation/release.md) +* [Changelog](/documentation/changelog.md) -Installation: move file to system > expressionengine > third_party +## Code Quality -This add-on is provided as-is at no cost with no warranty expressed or implied. Support is not included. \ No newline at end of file +* Prior to committing, run `php-cs-fixer fix` to validate code formatting. diff --git a/automation/make_addon.command b/automation/make_addon.command index cb63edb..121315c 100755 --- a/automation/make_addon.command +++ b/automation/make_addon.command @@ -1,13 +1,13 @@ #!/bin/bash -# the EE5 branch -EE5BRANCH="develop" +# the EE branch +EEBRANCH="develop" # allow branch override -while getopts "e:" OPTION; do +while getopts "b:" OPTION; do case $OPTION in - e) - EE5BRANCH=$OPTARG + b) + EEBRANCH=$OPTARG ;; esac done @@ -19,30 +19,30 @@ DIR=$(cd "$(dirname "$0")/.."; pwd) BASENAME=$(basename $DIR) # check out EE5 branch -git checkout $EE5BRANCH || { echo "Could'nt check out $EE5BRANCH branch"; exit 1; } +git checkout $EE5RANCH || { echo "Couldn't check out $EEBRANCH branch"; exit 1; } # get version number from config.php file -EE5VERSION=$(php -r "include '$DIR/system/user/addons/cartthrob_order_loader/addon.setup.php'; echo \CARTTHROB_ORDER_LOADER_VERSION;") +EEVERSION=$(php -r "include '$DIR/system/user/addons/cartthrob_order_loader/addon.setup.php'; echo \CARTTHROB_ORDER_LOADER_VERSION;") # go to the directory above the repo cd .. # temporarily rename the repo directory to EE5 -mv $BASENAME cartthrob_order_loader_$EE5VERSION +mv $BASENAME cartthrob_order_loader_$EEVERSION -ARTIFACTSDIR=cartthrob_order_loader-build +ARTIFACTSDIR=cartthrob_order_loader-build/ mkdir -p $ARTIFACTSDIR # add EE5 version to zip -zip -r $ARTIFACTSDIR/cartthrob_order_loader_$EE5VERSION.zip cartthrob_order_loader_$EE5VERSION/system -x "*.DS_Store" -x "__MACOSX*" -x "*composer.lock" -x "*composer.json" -x "*.orig" -x "*.git*" +zip -r $ARTIFACTSDIR/cartthrob_order_loader_$EEVERSION.zip cartthrob_order_loader_$EEVERSION/system -x "*.DS_Store" -x "__MACOSX*" -x "*composer.lock" -x "*composer.json" -x "*.orig" -x "*.git*" # move the build directory into the project directory -rm -rf cartthrob_order_loader_$EE5VERSION/build -mv $ARTIFACTSDIR cartthrob_order_loader_$EE5VERSION/build +rm -rf cartthrob_order_loader_$EEVERSION/build +mv $ARTIFACTSDIR cartthrob_order_loader_$EEVERSION/build # rename the repo back to its original name -mv cartthrob_order_loader_$EE5VERSION $BASENAME +mv cartthrob_order_loader_$EEVERSION $BASENAME # change directory back to repo cd $DIR diff --git a/build/cartthrob_order_loader_2.0.0.zip b/build/cartthrob_order_loader_2.0.0.zip index c7bf3ea..ad9688a 100644 Binary files a/build/cartthrob_order_loader_2.0.0.zip and b/build/cartthrob_order_loader_2.0.0.zip differ diff --git a/RELEASE.MD b/documentation/build.md similarity index 51% rename from RELEASE.MD rename to documentation/build.md index 3e04373..c03311f 100644 --- a/RELEASE.MD +++ b/documentation/build.md @@ -1,6 +1,4 @@ -## CartThrob Order Loader - -### Build Process +# CartThrob CartThrobOrderLoader: Build Process 1. From the terminal, make sure you are in the project root directory 2. Update and commit the version number bump @@ -10,26 +8,16 @@ * PATCH version when you make backwards-compatible bug fixes. A PATCH number should be excluded if it equals '0' * Update `CARTTHROB_ORDER_LOADER_VERSION` constant in `system/user/addons/cartthrob_order_loader/addon.setup.php` * `$ git commit -am "Bumping version"` -3. Merge `develop` branch into `master` branch +3. Merge `develop` branch into `main` branch * `$ git checkout develop && git pull origin develop && git push origin develop` - * `$ git checkout master && git pull origin master` + * `$ git checkout main && git pull origin main` * `$ git merge develop` 4. Tag the version in git * `$ git tag v` * For example – `$ git tag v4.3` or `$ git tag v4.3.1` 5. Push all changes to GitHub - * `$ git push --tags origin master` -6. Build CartThrob Order Loader ZIP + * `$ git push --tags origin main` +6. Build CartThrob CartThrobOrderLoader Zip * `$ npm run build-addon` - * Built CartThrob Order Loader ZIP files will be added to the `./build` folder -1. Publish a release on GitHub - * [Draft a New Release](https://github.com/CartThrob/Cart-LoadOrder/releases/new) on GitHub - * Type the tag name from the tagging step above into the "Tag version" field - * Repeat the tag name in the "Release title" field - * Upload the built ZIP file by dropping it into the Dropzone uploader. - * Publish the release - -### Release Process -1. Update the CartThrob website. Follow CartThrob update process. -2. Update the ExpressionEngine website. Follow CartThrob update process. -3. Announcements. Follow CartThrob update process. + * Built CartThrob CartThrobOrderLoader ZIP files will be added to the `./build` folder +7. [Publish the release](release.md) \ No newline at end of file diff --git a/documentation/changelog.md b/documentation/changelog.md new file mode 100644 index 0000000..ed61128 --- /dev/null +++ b/documentation/changelog.md @@ -0,0 +1,5 @@ +# Change Log + +### Version 3.0.0 + +* UPDATED: CartThrob 8 Support \ No newline at end of file diff --git a/documentation/release.md b/documentation/release.md new file mode 100644 index 0000000..b68a16d --- /dev/null +++ b/documentation/release.md @@ -0,0 +1,20 @@ +# CartThrob CartThrobOrderLoader: Release Process + +## Publish a release on GitHub +1. [Draft a New Release](https://github.com/CartThrob/CartThrobOrderLoader/releases/new) on GitHub +2. Type the tag name from the tagging step above into the "Tag version" field +3. Repeat the tag name in the "Release title" field +4. Upload the built ZIP file by dropping it into the Dropzone uploader. +5. Publish the release + +## Update the ExpressionEngine website +1. Login to the [EE addon portal](https://expressionengine.com/forums/member/profile) (see 1Password) +2. Visit the [Edit the addon](---) page +3. In the "Latest Version" field, change the version to match your release +4. In the "Zip File" field, remove the existing file and upload your ZIP file +5. In the "Latest Update" field, update the date to match the release date +6. Save the entry + +## Announcement +1. [Twitter](https://twitter.com/cartthrob) +2. [Mailchimp](https://us7.admin.mailchimp.com/campaigns/#f_list:all;t:campaigns-list) diff --git a/package.json b/package.json index b3e7081..8e5b4c3 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/CartThrob/Cart-LoadOrder" + "url": "git+https://github.com/CartThrob/CartThrobOrderLoader" }, "private": true } diff --git a/system/user/addons/cartthrob_order_loader/addon.setup.php b/system/user/addons/cartthrob_order_loader/addon.setup.php index 9418e33..c906605 100644 --- a/system/user/addons/cartthrob_order_loader/addon.setup.php +++ b/system/user/addons/cartthrob_order_loader/addon.setup.php @@ -1,14 +1,14 @@ 'Foster Made', - 'author_url' => 'https://cartthrob.com', - 'docs_url' => '', - 'name' => CARTTHROB_ORDER_LOADER_NAME, + 'author' => 'Foster Made', + 'author_url' => 'https://cartthrob.com', + 'docs_url' => '', + 'name' => CARTTHROB_ORDER_LOADER_NAME, 'description' => 'This reloads an existing order to the cart. This does not reload subscriptions or permissions attached to items.', - 'version' => CARTTHROB_ORDER_LOADER_VERSION, - 'namespace' => 'Cartthrob\OrderLoader', + 'version' => CARTTHROB_ORDER_LOADER_VERSION, + 'namespace' => 'Cartthrob\OrderLoader', ]; diff --git a/system/user/addons/cartthrob_order_loader/pi.cartthrob_order_loader.php b/system/user/addons/cartthrob_order_loader/pi.cartthrob_order_loader.php index 8727710..673297d 100644 --- a/system/user/addons/cartthrob_order_loader/pi.cartthrob_order_loader.php +++ b/system/user/addons/cartthrob_order_loader/pi.cartthrob_order_loader.php @@ -1,100 +1,105 @@ load->add_package_path(PATH_THIRD.'cartthrob/'); - ee()->load->library('cartthrob_loader'); - ee()->load->library('number'); - } - - public function load() - { - ee()->load->model("order_model"); - - $order_items = ee()->order_model->get_order_items(ee()->TMPL->fetch_param('entry_id')); - - if (!$order_items) { - return false; - } - - $default_columns = [ - 'row_id', - 'row_order', - 'order_id', - 'entry_id', - 'title', - 'quantity', - 'price', - 'price_plus_tax', - 'weight', - 'shipping', - 'no_tax', - 'no_shipping', - 'license_number', - 'entry_date', - 'discount', - ]; - - foreach ($order_items as $key => $item) { - $data = array( - 'entry_id' => element('entry_id',$item), - 'product_id' => element('entry_id',$item), - 'quantity' => element('quantity',$item) - ); - - $data['no_shipping'] = bool_string(element("no_shipping", $item)); - $data['no_tax'] = bool_string(element("no_tax", $item)); - - $data['item_options'] = array_diff_key($item, array_flip($default_columns)); - - if ( (! bool_string(element("on_the_fly", $item,"0")) && ! element("nominal_charge", $item)) && ! (ee()->TMPL->fetch_param('on_the_fly') !== false && bool_string(ee()->TMPL->fetch_param('on_the_fly'))) ) - { - $data['class'] = 'product'; - } else { - $data['price'] = element("price",$item); - $data['weight'] = element("weight",$item); - $data['shipping'] = element("shipping", $item); - $data['title'] = element("title",$item); - } - - $new_item = ee()->cartthrob->cart->add_item($data); - - if ($new_item) { - if ($value = element("license_number", $item)) { - $new_item->set_meta('license_number', true); - } - - // Price may be set by something else, so let's set it back ot the original order's price i.e. price multiplier - if (bool_string(ee()->TMPL->fetch_param('update_price')) && (float) element("price",$item) != (float) $new_item->price()) { - $new_item->update([ - 'price' => element('price', $item), - 'class' => 'default'] + public function __construct() + { + ee()->load->add_package_path(PATH_THIRD . 'cartthrob/'); + ee()->load->library('cartthrob_loader'); + ee()->load->library('number'); + } + + public function load() + { + ee()->load->model('order_model'); + + $return = ee()->TMPL->fetch_param('return') ?? 'store/view_cart'; + $order_items = ee()->order_model->getOrderItems(ee()->TMPL->fetch_param('entry_id')); + + if (!$order_items) { + return false; + } + + $default_columns = [ + 'row_id', + 'row_order', + 'order_id', + 'entry_id', + 'title', + 'quantity', + 'price', + 'price_plus_tax', + 'weight', + 'shipping', + 'no_tax', + 'no_shipping', + 'license_number', + 'entry_date', + 'discount', + ]; + + foreach ($order_items as $key => $item) { + $data = [ + 'entry_id' => element('entry_id', $item), + 'product_id' => element('entry_id', $item), + 'quantity' => element('quantity', $item), + ]; + + $data['no_shipping'] = bool_string(element('no_shipping', $item)); + $data['no_tax'] = bool_string(element('no_tax', $item)); + + $data['item_options'] = array_diff_key($item, array_flip($default_columns)); + + if ((!bool_string(element('on_the_fly', $item, '0')) && !element('nominal_charge', $item)) && !(ee()->TMPL->fetch_param('on_the_fly') !== false && bool_string(ee()->TMPL->fetch_param('on_the_fly')))) { + $data['class'] = 'product'; + } else { + $data['price'] = element('price', $item); + $data['weight'] = element('weight', $item); + $data['shipping'] = element('shipping', $item); + $data['title'] = element('title', $item); + } + + if (isset($data['item_options']['site_id'])) { + $data['site_id'] = $data['item_options']['site_id']; + unset($data['item_options']['site_id']); + } + + $new_item = ee()->cartthrob->cart->add_item($data); + + if ($new_item) { + if ($value = element('license_number', $item)) { + $new_item->set_meta('license_number', true); + } + + // Price may be set by something else, so let's set it back ot the original order's price i.e. price multiplier + if (bool_string(ee()->TMPL->fetch_param('update_price')) && (float)element('price', $item) != (float)$new_item->price()) { + $new_item->update([ + 'price' => element('price', $item), + 'class' => 'default', ] ); - } - } - - // cartthrob_add_to_cart_end hook - if (ee()->extensions->active_hook('cartthrob_add_to_cart_end') === true) { - ee()->extensions->call('cartthrob_add_to_cart_end', $new_item); - - if (ee()->extensions->end_script === true) { - return; - } - } - - } - - if (ee()->cartthrob->cart->check_inventory()) { - ee()->cartthrob->cart->save(); - - return true; - } else { - return false; - } - } -} \ No newline at end of file + } + } + + // cartthrob_add_to_cart_end hook + if (ee()->extensions->active_hook('cartthrob_add_to_cart_end') === true) { + ee()->extensions->call('cartthrob_add_to_cart_end', $new_item); + + if (ee()->extensions->end_script === true) { + return; + } + } + } + + if (ee()->cartthrob->cart->check_inventory()) { + ee()->cartthrob->cart->save(); + } + + ee()->load->helper('url'); + redirect($return); + exit; + } +}