Jump to content

[solved] Default quantity based on product id?


mbp

Recommended Posts

Hi

 

I have changed the default quantity in my 1.5.6.2 Shop from 1item to 4items

 

I'm selling car tires so i want the customer to put 4items in the basket in the easiest way.

 

BUT there is one product that i would like to decide the default value of 1 instad. C

 

 

product.tpl around line 342

<input type="text" name="qty" id="quantity_wanted" class="text" value="4" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />

I have added an if statement in with the right value and prestashop underands this and puts 1 item in the basket, but the other value is alo showing. 

 

How come?

                {if $product->id==189}
                <input type="text" name="qty" id="quantity_wanted" class="text" value="1" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />
              {/if}
				<input type="text" name="qty" id="quantity_wanted" class="text" value="4" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />

error_problem.png

Edited by mbp (see edit history)
Link to comment
Share on other sites

Probably an {else} will do the job:

 

{if $product->id==189}
       <input type="text" name="qty" id="quantity_wanted" class="text" value="1" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />
{else}

       <input type="text" name="qty" id="quantity_wanted" class="text" value="4" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />

{/if}

 

Hope this helps,

pascal

Link to comment
Share on other sites

Probably an {else} will do the job:

 

{if $product->id==189}

       <input type="text" name="qty" id="quantity_wanted" class="text" value="1" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />

{else}

       <input type="text" name="qty" id="quantity_wanted" class="text" value="4" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />

{/if}

 

Hope this helps,

pascal

 

Thx i tried the else but forgot the if.

 

THX PascalVG :)

Link to comment
Share on other sites

  • 5 months later...

Probably an {else} will do the job:

 

{if $product->id==189}

       <input type="text" name="qty" id="quantity_wanted" class="text" value="1" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />

{else}

       <input type="text" name="qty" id="quantity_wanted" class="text" value="4" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />

{/if}

 

Hope this helps,

pascal

Hi , I am looking for a solution to set a default quantity of 1 when I insert a new product. By default is 0. I'm not talking about the minimal quantity but about the actual product quantity.

Link to comment
Share on other sites

Hi , I am looking for a solution to set a default quantity of 1 when I insert a new product. By default is 0. I'm not talking about the minimal quantity but about the actual product quantity.

 

Hi, this solution is for increasing the "add to cart quantity" from 1item to 4items at the product page in the front office.

Link to comment
Share on other sites

Hi George, try this:


 


 


in /classes/Product.php (make backup, or even better make override)


 


change function Add: (Sample code from 1.6.0.8).


Add the red code


 


 


public function add($autodate = true, $null_values = false)

{

  $newProd = 0;

  if (!$this->id)

    $newProd = 1;

 

  if (!parent::add($autodate, $null_values))

    return false;

 

  if ($this->getType() == Product::PTYPE_VIRTUAL)

  {

    StockAvailable::setProductOutOfStock((int)$this->id, 1);

    if ($this->active && !Configuration::get('PS_VIRTUAL_PROD_FEATURE_ACTIVE'))

      Configuration::updateGlobalValue('PS_VIRTUAL_PROD_FEATURE_ACTIVE', '1');

  }

  else

    StockAvailable::setProductOutOfStock((int)$this->id, 2);

 

  if ($newProd)

    StockAvailable::setQuantity($this->id, null, 1); // 1 = quantity wanted

 

 

  $this->setGroupReduction();

  Hook::exec('actionProductSave', array('id_product' => $this->id));

  return true;

}

 

 

Hope that does the trick,

pascal.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...