The patch:
- Adds a markup widget. After creating field_cost for variation, change this field's widget to 'Price with Cost'. Select the necessary fields from widget settings.
- On variation edit page, when a value for `Markup`, or `Cost` field is changed, a UX is presented to let the user know of altered values.

See attached

Comments

gauravjeet created an issue. See original summary.

gauravjeet’s picture

StatusFileSize
new7.06 KB
new6.86 MB
new5.01 MB

travis-bradbury’s picture

Status: Active » Needs work

Thanks, Gaurav. Looks great so far.

(function ($, Drupal) {
  'use strict';

  /**
   * @file
   * Defines sale price based off product price, cost and markup.
   */

Shouldn't the @file doc be at the top of the file?

      var markupElement = '<label for="markup-percentage" class="markup-field-label">Markup percentage</label>';
      markupElement += '<input type="text" size="10" id="markup-percentage" class="form-text ' + markupClass + '">';
      markupElement += '<span class="field-suffix">%</span>';

Why not add this element in the widget? Then we can use the form api instead of manually adding markup that is the responsibility of the theme.

          if (!isNaN(value)) {
            $(priceNumber)
              .val(value)
              .css('background-color', '#f0ff00');

            setTimeout(function(){
              $(priceNumber).css('background-color', '#fcfcfa');
            }, 500);
          }

Toggle a class here instead of setting the colour directly.

          if (!isNaN(value)) {
            $markup
              .val(value)
              .css('background-color', '#f0ff00');

            setTimeout(function(){
              $markup.css('background-color', '#fcfcfa');
            }, 500);
          }
        }

The code is duplicated in the event listener for $price. How about passing $markup or $priceNumber into a function that does the animation?

// \Drupal::logger('abcd')->notice('<pre>' . print_r($element, TRUE) . '</pre>');

This debugging code should be removed.

gauravjeet’s picture

Status: Needs work » Needs review
StatusFileSize
new7.49 KB
new4.02 KB
new4.08 KB

@Travis
I've made edits to the patch. New patch attached with interdiff.

Attaching the markup field within $form of widget will not allow putting cost and markup together and thats not going to be a nice UX. Placing the markup field depends on the #weight property and thats not going to same for every site. screenshot attached for reference.

https://www.drupal.org/files/issues/Screen%20Shot%202018-01-12%20at%2017.03.49.png

gauravjeet’s picture

Version: » 8.x-1.x-dev

Add version tag

travis-bradbury’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.