Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support direct editing of a field ( eg Price ) where it varies by product #6

Closed
6 tasks done
bobbingwide opened this issue Sep 14, 2021 · 9 comments
Closed
6 tasks done
Assignees
Labels
enhancement New feature or request

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Sep 14, 2021

For some optional upgrades eg 4 Slat (20") wide Aluminium Staging (Moss) the price varies by product.
For these the bulk update logic is not appropriate.
We need to support individual update.

Requirements

  • Provide a method to update the individual fields per product.
  • Primarily for Price
  • Needs to support options with over 250 products attached
  • Update should check the before figure as well before applying the change.

Proposed solution

  • Option to indicate that updates are going to be performed for each product
  • Initially implement on Price only?
  • Display the Price as a text field
  • Field name should be keyed by the product ID
  • Form should contain a hidden field showing the current price.
  • Use this to determine whether or not to perform an update.

Estimated effort - 1 day

@bobbingwide bobbingwide self-assigned this Sep 15, 2021
@bobbingwide bobbingwide added the enhancement New feature or request label Sep 15, 2021
@bobbingwide
Copy link
Owner Author

Prototype of the form to Update by Product.
image

@bobbingwide
Copy link
Owner Author

Option to indicate that updates are going to be performed for each product

Having now developed the first version to perform either Bulk updates or Updates by product it's time to merge the solutions
so that the user can decide what to do when the results are first displayed.

Proposal is to move the Bulk Update fields to after the Results list.
Use can choose either Bulk Update or Update by product.

@bobbingwide
Copy link
Owner Author

image

I've made the changes
The Bulk update button uses the two textarea fields at the bottom.
The Update by product button checks the values for each product.

In this example we see the results displaying the Name field for Aluminium Polycarbonate Cold Frame 4' x 3'(double)
where there's only one product.
I was trying to change the Name to add a space before (double) and I noticed two problems

  1. Why is product count None?
  2. The single quote is escaped. Where is stripslashes needed?
Option name: Aluminium Polycarbonate Cold Frame 4' x 3'(double)
Product count: None!
Performing update by product for: Aluminium Polycarbonate Cold Frame 4' x 3'(double)

Setting field: Name

Skipping: 3698 Current: Aluminium Polycarbonate Cold Frame 4' x 3'(double) Match: Aluminium Polycarbonate Cold Frame 4\' x 3\'(double)

@bobbingwide
Copy link
Owner Author

  1. Why is product count: None ?

Answer: Typo in code. Undefined variable $IDS; should be $IDs

@bobbingwide
Copy link
Owner Author

Initially implement on Price only?

I did that, then added logic to display the Description field as textarea.

Display the Price as a text field

I think I should make the price a width of 10 and other textfields about 50.

@bobbingwide
Copy link
Owner Author

The logic needs to cater for strings which contain single quotes, double quotes and backslashes that need to be escaped in a variety of ways depending on how they're being displayed and accessed.

On input ( getting values from $_REQUEST) we need to call wp_unslash().

On display in a hidden field we need to call esc_attr() - to convert double quotes to &quot.

See also bobbingwide/oik-bwtrace#105

@bobbingwide
Copy link
Owner Author

bobbingwide commented Sep 18, 2021

It seems I can't enter backslashes for either Description or Name without a bit of fiddling.

  • A single backslash converts to nothing
  • A double backslash becomes a single backslash.

@bobbingwide
Copy link
Owner Author

It seems I can't enter backslashes for either Description or Name without a bit of fiddling.

This is all to do with wp_unslash() and the behaviour of get_post_meta and update_post_meta().

Basically, WordPress tries to help with the special characters: " ' and \

  • When performing an update you need to pass the slashed version.
  • But when comparing with the current value it should be the unslashed version.
  • and you have to consider using trim() as well.

See update_metadata() which unslashes the $meta_value.

@bobbingwide bobbingwide changed the title Support direct editing of new price where it varies by product Support direct editing of a field ( eg Price ) where it varies by product Sep 19, 2021
@bobbingwide
Copy link
Owner Author

This was delivered in v0.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant