PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 27, 2022

[FIXED] How can I set a price for custom text?

 October 27, 2022     prestashop, prestashop-1.7, price     No comments   

Issue

Is there a way to add price if the client add the custom text (the one inside the Options section when you add the product) in a product? or have I to add it by product combinations (adding a lot of combinations)?

With the input radio I can't control what the user will do and I can't set it as "required" because it must be a free choice.

 {block name='product_customization_form'}
    <form method="post" action="{$product.url}" enctype="multipart/form-data">
      <ul class="clearfix">
        {foreach from=$customizations.fields item="field"}
          <li class="product-customization-item">
            <label> {$field.label}</label>
            {if $field.type == 'text'}
              <textarea placeholder="{l s='Your message here' d='Shop.Forms.Help'}" class="product-message" maxlength="250" {if $field.required} required {/if} name="{$field.input_name}"></textarea>
              <small class="float-xs-right">{l s='250 char. max' d='Shop.Forms.Help'}</small>
              {if $field.text !== ''}
                  <h6 class="customization-message">{l s='Your customization:' d='Shop.Theme.Catalog'}
                      <label>{$field.text}</label>
                  </h6>
              {/if}



          </li>
        {/foreach}
      </ul>
      <div class="clearfix">
        <button class="btn btn-primary float-xs-right" type="submit" name="submitCustomizedData">{l s='Save Customization' d='Shop.Theme.Actions'}</button>
      </div>
    </form>
  {/block}

Solution

The best way to achieve this would be to have two product combinations:

  • With custom text (+$0)
  • Without custom text (+$1.00)

Next, add some custom Javascript code to your product page (the proper way would be via a module) that would do the following:

  1. Check if the customization textarea element is present on the page
  2. Check if it is empty or not
  3. If not, force the combination ID to the right ID (the "with customization" version)

That's it.

That way, the buyer won't have to select any option, they just have to fill a custom text if they would like to and the price will adjust automatically in their shopping cart.

I hope this helps!



Answered By - Bruno Leveque
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing