Jump to content

Property Combination->minimal_quantity is not valid


Serial

Recommended Posts

Hi,

 

I did this tutorial : https://www.prestashop.com/forums/topic/93968-change-order-quantity-to-a-decimal-value/page-3 (answer of Mykhailo) because I want to set all my product quantities in meters (so in float).

 

I've a problem when I create a new combination. I specify minimum quantity for order at 0.50 but when i saved, i have this error : "Property Combination->minimal_quantity is not valid".

 

This is my code of AdminProductsController.php in function processProductAttribute() :

public function processProductAttribute()
	{
		// Don't process if the combination fields have not been submitted
		if (!Combination::isFeatureActive() || !Tools::getValue('attribute_combination_list'))
			return;

		if (Validate::isLoadedObject($product = $this->object))
		{
			if ($this->isProductFieldUpdated('attribute_price') && (!Tools::getIsset('attribute_price') || Tools::getIsset('attribute_price') == null))
				$this->errors[] = Tools::displayError('The price attribute is required.');
			if (!Tools::getIsset('attribute_combination_list') || Tools::isEmpty(Tools::getValue('attribute_combination_list')))
				$this->errors[] = Tools::displayError('You must add at least one attribute.');

			$array_checks = array(
				'reference' => 'isReference',
				'supplier_reference' => 'isReference',
				'location' => 'isReference',
				'ean13' => 'isEan13',
				'upc' => 'isUpc',
				'wholesale_price' => 'isPrice',
				'price' => 'isPrice',
				'ecotax' => 'isPrice',
				'quantity' => 'isUnsignedFloat',
				'weight' => 'isUnsignedFloat',
				'unit_price_impact' => 'isPrice',
				'default_on' => 'isBool',
				'minimal_quantity' => 'isUnsignedFloat',
				'available_date' => 'isDateFormat'
			);
			foreach ($array_checks as $property => $check)
				if (Tools::getValue('attribute_'.$property) !== false && !call_user_func(array('Validate', $check), Tools::getValue('attribute_'.$property)))
					$this->errors[] = sprintf(Tools::displayError('Field %s is not valid'), $property);

			if (!count($this->errors))
			{
				if (!isset($_POST['attribute_wholesale_price'])) $_POST['attribute_wholesale_price'] = 0;
				if (!isset($_POST['attribute_price_impact'])) $_POST['attribute_price_impact'] = 0;
				if (!isset($_POST['attribute_weight_impact'])) $_POST['attribute_weight_impact'] = 0;
				if (!isset($_POST['attribute_ecotax'])) $_POST['attribute_ecotax'] = 0;
				if (Tools::getValue('attribute_default'))
					$product->deleteDefaultAttributes();

				// Change existing one
				if (($id_product_attribute = (int)Tools::getValue('id_product_attribute')) || ($id_product_attribute = $product->productAttributeExists(Tools::getValue('attribute_combination_list'), false, null, true, true)))
				{
					if ($this->tabAccess['edit'] === '1')
					{
						if ($this->isProductFieldUpdated('available_date_attribute') && (Tools::getValue('available_date_attribute') != '' &&!Validate::isDateFormat(Tools::getValue('available_date_attribute'))))
							$this->errors[] = Tools::displayError('Invalid date format.');
						else
						{
							$product->updateAttribute((int)$id_product_attribute,
								$this->isProductFieldUpdated('attribute_wholesale_price') ? Tools::getValue('attribute_wholesale_price') : null,
								$this->isProductFieldUpdated('attribute_price_impact') ? Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact') : null,
								$this->isProductFieldUpdated('attribute_weight_impact') ? Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact') : null,
								$this->isProductFieldUpdated('attribute_unit_impact') ? Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact') : null,
								$this->isProductFieldUpdated('attribute_ecotax') ? Tools::getValue('attribute_ecotax') : null,
								Tools::getValue('id_image_attr'),
								Tools::getValue('attribute_reference'),
								Tools::getValue('attribute_ean13'),
								$this->isProductFieldUpdated('attribute_default') ? Tools::getValue('attribute_default') : null,
								Tools::getValue('attribute_location'),
								Tools::getValue('attribute_upc'),
								$this->isProductFieldUpdated('attribute_minimal_quantity') ? Tools::getValue('attribute_minimal_quantity') : null,
								$this->isProductFieldUpdated('available_date_attribute') ? Tools::getValue('available_date_attribute') : null, false);
								StockAvailable::setProductDependsOnStock((int)$product->id, $product->depends_on_stock, null, (int)$id_product_attribute);
								StockAvailable::setProductOutOfStock((int)$product->id, $product->out_of_stock, null, (int)$id_product_attribute);
						}
					}
					else
						$this->errors[] = Tools::displayError('You do not have permission to add this.');
				}
				// Add new
				else
				{
					if ($this->tabAccess['add'] === '1')
					{
						if ($product->productAttributeExists(Tools::getValue('attribute_combination_list')))
							$this->errors[] = Tools::displayError('This combination already exists.');
						else
						{
							$id_product_attribute = $product->addCombinationEntity(
								Tools::getValue('attribute_wholesale_price'),
								Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'),
								Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'),
								Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'),
								Tools::getValue('attribute_ecotax'),
								0,
								Tools::getValue('id_image_attr'),
								Tools::getValue('attribute_reference'),
								null,
								Tools::getValue('attribute_ean13'),
								Tools::getValue('attribute_default'),
								Tools::getValue('attribute_location'),
								Tools::getValue('attribute_upc'),
								Tools::getValue('attribute_minimal_quantity'),
								Array(),
								Tools::getValue('available_date_attribute')
							);
							StockAvailable::setProductDependsOnStock((int)$product->id, $product->depends_on_stock, null, (int)$id_product_attribute);
							StockAvailable::setProductOutOfStock((int)$product->id, $product->out_of_stock, null, (int)$id_product_attribute);
						}
					}
					else
						$this->errors[] = Tools::displayError('You do not have permission to').'<hr>'.Tools::displayError('edit here.');
				}
				if (!count($this->errors))
				{
					$combination = new Combination((int)$id_product_attribute);
					$combination->setAttributes(Tools::getValue('attribute_combination_list'));

					// images could be deleted before
					$id_images = Tools::getValue('id_image_attr');
					if (!empty($id_images))
						$combination->setImages($id_images);

					$product->checkDefaultAttributes();
					if (Tools::getValue('attribute_default'))
					{
						Product::updateDefaultAttribute((int)$product->id);
						if (isset($id_product_attribute))
							$product->cache_default_attribute = (int)$id_product_attribute;

						if ($available_date = Tools::getValue('available_date_attribute'))
							$product->setAvailableDate($available_date);
						else
							$product->setAvailableDate();
					}
				}
			}
		}
	}

In $array_checks, I specify that minimal_quantity is Unsigned Float.

 

In my definition of Product.php :

'minimal_quantity' => 			array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isUnsignedFloat'),

 So, i don't know why I have this error.

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

  • 1 year later...
  • 6 years later...
On 8/3/2016 at 5:18 AM, adel.mariam said:

I know this is an old post, but here's how I solved this

I updated the Combination.php . changed all quantities to float

 

Google search is giving me error of "Invalid floating point number in property "price" (in "offers")"

Any Idea How I solve it? I am sure it has something to do with pricing, I when I see the price at back office, i see many unwanted Zeros after decimal in retail and unite price.

 

 

 

 

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...