From 95c8810f4b30ffa1fa97908e66454367c57b7e95 Mon Sep 17 00:00:00 2001 From: Eric Lamb Date: Mon, 5 Jun 2023 11:00:15 -0700 Subject: [PATCH 1/4] updates to use const for creating constants (removed define) --- system/user/addons/cartthrob_order_loader/addon.setup.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/user/addons/cartthrob_order_loader/addon.setup.php b/system/user/addons/cartthrob_order_loader/addon.setup.php index 9418e33..de0a87e 100644 --- a/system/user/addons/cartthrob_order_loader/addon.setup.php +++ b/system/user/addons/cartthrob_order_loader/addon.setup.php @@ -1,7 +1,7 @@ 'Foster Made', From cbd2c1cfb2100b2ca8938b0930f28c643be18ed2 Mon Sep 17 00:00:00 2001 From: Eric Lamb Date: Mon, 5 Jun 2023 11:00:45 -0700 Subject: [PATCH 2/4] adds public display to constructor updates method to use camel case syntax --- .../cartthrob_order_loader/pi.cartthrob_order_loader.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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..820f08d 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 @@ -4,8 +4,7 @@ class Cartthrob_order_loader { - - function __construct() + public function __construct() { ee()->load->add_package_path(PATH_THIRD.'cartthrob/'); ee()->load->library('cartthrob_loader'); @@ -16,7 +15,7 @@ public function load() { ee()->load->model("order_model"); - $order_items = ee()->order_model->get_order_items(ee()->TMPL->fetch_param('entry_id')); + $order_items = ee()->order_model->getOrderItems(ee()->TMPL->fetch_param('entry_id')); if (!$order_items) { return false; From 9d0d65de3f6b7895d0c61e4263e6217c0b14f047 Mon Sep 17 00:00:00 2001 From: Eric Lamb Date: Mon, 5 Jun 2023 11:33:36 -0700 Subject: [PATCH 3/4] removes site_id as option for cart item (can be overridden so is bad) adds return param --- .../pi.cartthrob_order_loader.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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 820f08d..a86cfc6 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 @@ -15,6 +15,7 @@ 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) { @@ -61,6 +62,11 @@ public function load() $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) { @@ -90,10 +96,10 @@ public function load() if (ee()->cartthrob->cart->check_inventory()) { ee()->cartthrob->cart->save(); - - return true; - } else { - return false; } + + ee()->load->helper('url'); + redirect($return); + exit; } } \ No newline at end of file From c593e6b47c2e9ad8e5bb871ca53ca55a84edb829 Mon Sep 17 00:00:00 2001 From: Shawn Maida Date: Thu, 15 Jun 2023 22:58:27 -0400 Subject: [PATCH 4/4] Upgrade for CT8 --- .php-cs-fixer.cache | 1 + .php-cs-fixer.php | 34 ++++ README.md | 11 +- automation/make_addon.command | 26 +-- build/cartthrob_order_loader_2.0.0.zip | Bin 2801 -> 2862 bytes RELEASE.MD => documentation/build.md | 26 +-- documentation/changelog.md | 5 + documentation/release.md | 20 +++ package.json | 2 +- .../cartthrob_order_loader/addon.setup.php | 12 +- .../pi.cartthrob_order_loader.php | 170 +++++++++--------- 11 files changed, 178 insertions(+), 129 deletions(-) create mode 100644 .php-cs-fixer.cache create mode 100644 .php-cs-fixer.php rename RELEASE.MD => documentation/build.md (51%) create mode 100644 documentation/changelog.md create mode 100644 documentation/release.md 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 c7bf3ea7389f4afadcc403a5d14a0b69a3307e2b..ad9688a7166b583f14e7c9538bebcc854a7981a4 100644 GIT binary patch literal 2862 zcmWIWW@h1H0D*~H&WC{+P(p=4h9NnzsH7yLC_gDazbGZOC_X1Y5kwj38R!}47grXS zq~_{}hHx@4Z#>nVvf^}iN@)c*10%~#FUi$ zyka7464{CxRPJQhggs~>4giJZ2JE2;3RMnIGgq&S>rv3GV_uMxa z?sqwC<$K4Hni1MCSNP+j*FWEVUsP4C%g_8kEjo4eigd?7d7T=Aj`r?(TexM+z8{z` z8|3m{d8Yol{j=@nxOb|3s@NTKDx;mvdS=O8mAtt}>R*OzT@<|1XmSCQ#*~8{*xIdx!S$YXKX8tyw+5^?xsE{p(CQ^Q|Iyi(0GClnIw!Tt8o5U;E?F z58bZhPw$%^Ft0y!;RU~I&_YGSC4O60@I3TnD)rqlqXzBj5}TyJHt#bRP5dQ;p?>JnyV{5 zo%!CdUv2p{uWvuz{*I47q1!oW^EvBmuMUTPkmtb-|-g{>^jQ8YuOSk11|O zsfJWdgq7$ahrsV8^KN}DhO}+4P%IujJ zSFRAgI%Qv?e_WEWj>fzvEqz=aA7<&yf9PQry=ja0dKazxZm{EmSL{4PxoV$0Gih@(os5(-)ej17bba;H z-k!U{_Btl|qJ^`%j%Y~D!~?yI-WPV?@ohVI*?;dTs2dXMfd zk#5}mP~2tSvrxrXQarq2aA=~e>c0JJS)^OgivEx!w{_R;iYPYN9 zo)s?S-hTH!)A6nqOAau{X=uEE^=R3q+oHvPpSZD|{ct7a5%=D<$&Yj%vaX%F@IB}H zV2|g~*M7eI(pxrRBj@Md<;QnLCT|QhFBkkOGKF8Q=#N>|(J6e#!=pF5Z9Q(!mg-fs zbY6Pu>n6VSY^zUfzE>duQY4w-szk)-UFrZB=Q1GPCnjgX)40Mh2_baqpNV|H1jgkJs^BMH56b z-Z1F?&F)|;zq#n{+5`I+J}7-tBWS7nk2%1bkx7mjSG_L*Z2<@{ymbUIu@^e%tpHX? zD*&yIz-N;t1F}tVMA`&x5s+@30g818NwE&zIv{K-X4?SSliI+_nwa1OdlG6ZcJ;uP z0?;v7+gzZyMN~$p?F5KpfUaOz(zu3tj=^X(0Nn;^HDFB*2)ChDl*n##XQo;}5vVqC Vxs;U+7)T6kK&S+C%Qtoq4*>WeKV<*_ delta 1648 zcmZwHdpOg390%|p*8JRNTOT0`+0w#=kt8N&+{smosoe#*a$&H0sf?yp&V0T z24Gg`yazU7-Xqms9)Zf zfe-+I&4K_x02CQ(B1EbPAoN!+^o$rF0QtIJfJm?JK*!tJ*XxRN7hD!)FEIn(wk$fx zTdD+hTuHY+4oM z9B9Di9KwCle-e$?-hPKHeUE0fCoIjb=W#b)I{3&RyoFY7ZyO4!)VoXL;qaJp^WLJ?X0@eF z{D0zK2n0N%P>wfYwU*670H7(#@DQR<)wSk5TGzkhKi5nq36O@wg<*Rc?Lav7aiQ>v_5rbc)CNbc!!cQUYET-P#dZ zyJ_6D1R9cles!*^D$BlVx;uwxTDugTFH);=(G2}WfpO^ zpl2-+{x`pnYE5j5JQ;aC5(hKW6t(nn(is&R9xhSPFSlbH+io^yu@OaUX% zGy1~+DX6dXC9~A`L^ZpfS^c5lQx>~{>%)2mrEAkVID&amZNkP+yu~sCpU!~s`L?cR z#v(@>Xa>bnP{plUEMKq7*PMgcqN9Dh?0qY1LEvI)z5E|7WULX{0UI|RxW5~-spk2E zw@waJw0BfiBjm1YWAaYZx}oI!6^!KE1#jbuun_mEa$CdC>eEdj&eGYuQMLVYR6V@aZ>H^H`14rF-bz$$A9J%zMxkzmF;vO(_tGhziCbNx zx73FgVn^PRe8}N;jW(BeSjOkX>$zsgt6DwOak_bNsCU1^KA2Hpo4ron7V~-NDOQQR zaeGcv*S0-}Yr0#8G}FGd*V!lAEOH?v^y0V;c`D+lGA!k0r4eLym^*W6t=llHQg=y{ zi7Za+im2VzQOiR#gb(8L%eqD9i)cU&24S93q4Dx%&{#>#VMWhaY!llETij}ao1-q0 z%T9>P46tTD%b4-91p{bkV4#G{P>GHipmiygXw@X7==pk7UdfXR?tfz+&!UiW$IOss zJ**p1EjznFdbF_`D(Q^45su(`@ikozn_JRE^iLomW6FhnOz>Yj^%M1SU+3;iAtEmH zTuK_-{0V(j@3fR+mZEi;GPD~)ZJK`N7*0}Fqjy)Y#0}Ak79w2^mh|p*`fvoAnp9Q3 zjYJuqtuS;{Snj`?3AT?lPJCs~OkYnO{VfOq`?iO^%_dFKT`wg~)@~tFwb*Ag=S+c| zYRef?5Pos6u0S&9KJMAVJ5vW60YRkDKUVY2{yq#ih=K6gX5c}E4YL_Rpe=-t_C~@N zn=t|&g7C@SNH)B77V(4d9bQjlq`%wpZ?PFuB9y-ysQ=Rk0FD8OjV0Cv2MTCTLX2P$ Y9D^mKEW8O2;` * 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 de0a87e..c906605 100644 --- a/system/user/addons/cartthrob_order_loader/addon.setup.php +++ b/system/user/addons/cartthrob_order_loader/addon.setup.php @@ -4,11 +4,11 @@ const CARTTHROB_ORDER_LOADER_VERSION = '2.0.0'; return [ - 'author' => '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 a86cfc6..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,105 +1,105 @@ load->add_package_path(PATH_THIRD.'cartthrob/'); - ee()->load->library('cartthrob_loader'); - ee()->load->library('number'); - } + 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"); + 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 = 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); - } - - if(isset($data['item_options']['site_id'])) { + $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'] + $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; - } - } + // 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(); - } + if (ee()->cartthrob->cart->check_inventory()) { + ee()->cartthrob->cart->save(); + } ee()->load->helper('url'); redirect($return); exit; - } -} \ No newline at end of file + } +}