Дробное количество ubercart 3

ubercard 3.5 нашел решения с некоторыми коректировками
// making the product quantities FLOAT instead INTEGER Drupal 7, Ubercart 3.1
//// DATABASE CHANGES Four ubercart tables alterations are made from sql terminal (mysql -u ADMIN_USER -p , use DATABASE_NAME )
1) The UC_CART_PRODUCTS table intersect the UC_CARTS table and the UC_PRODUCTS table. The column ц╒Б┌╛е⌠qtyц╒Б┌╛б² is the one to ajust. Here is the MySQL statement that will modify the column to a FLOAT data type:

ALTER TABLE `uc_cart_products` MODIFY COLUMN `qty` FLOAT(6,2) UNSIGNED NOT NULL DEFAULT 0;

2) The UC_ORDERS table holds all the orders created. The column to adjust is ц╒Б┌╛е⌠product_countц╒Б┌╛б².

ALTER TABLE `uc_orders` MODIFY COLUMN `product_count` FLOAT(6,2) UNSIGNED NOT NULL DEFAULT 0; 3) The UC_PRODUCTS table contains a

default_qty field. This value gets inserted into both the product edit page and the product view page (for the customer). I think it would be a good idea to show the customer how many decimal places one may use.

ALTER TABLE `uc_products` MODIFY COLUMN `default_qty` FLOAT(6,2) UNSIGNED NOT NULL DEFAULT 1.00;

4) The UC_ORDER_PRODUCTS table intersects the UC_ORDERS table and the UC_PRODUCTS table. The column to adjust is the ц╒Б┌╛е⌠qtyц╒Б┌╛б² column. Here is the MySQL statement that will modify the column to a FLOAT data type:

ALTER TABLE `uc_order_products` MODIFY COLUMN `qty` FLOAT(6,2) UNSIGNED NOT NULL DEFAULT 0;

//// CODE CHANGES // FIRST uc_order -> uc_order.install //Change array elements in function to: /** * Increase maximum order item quantity. */

function uc_order_update_7003() {
db_change_field('uc_order_products', 'qty', 'qty', array(
'description' => 'The number of the same product ordered.',
'type' => 'float',
'precision' => 6,
'scale' => 1,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1.0,
));
}

// SECOND


uc_order
->
uc_order.install

In $schema['uc_order_products'] change:

'qty' => array(
'description' => 'The number of the same product ordered.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),

To:


'qty' => array(
'description' => 'The number of the same product ordered.',
'type' => 'float',
'precision' => 6,
'scale' => 1,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1.0,
),

// THIRD uc_product -> uc_product.module //For possibility of using 0.00 to 1.00 quantites in function uc_product_uc_update_cart_item change: (string 1052) p.s. С новыми версиями функция поменялась, я сменил на функцию на старую версию, пока все ок 🙂

</pre>
<pre class="php"><code><span class="php-keyword">function</span> <span class="php-function-or-constant"><a class="local active" title="Implements hook_uc_update_cart_item()." href="http://drupalcontrib.org/api/drupal/contributions%21ubercart%21uc_product%21uc_product.module/function/uc_product_uc_update_cart_item/7">uc_product_uc_update_cart_item</a></span>(<span class="php-variable">$nid</span>, <span class="php-variable">$data</span> = <span class="php-keyword">array</span>(), <span class="php-variable">$qty</span>, <span class="php-variable">$cid</span> = <span class="php-function-or-constant">NULL</span>) {
  <span class="php-keyword">if</span> (!<span class="php-variable">$nid</span>) {
    <span class="php-keyword">return</span> <span class="php-function-or-constant">NULL</span>;
  }
  <span class="php-variable">$cid</span> = !(<span class="php-function-or-constant">is_null</span>(<span class="php-variable">$cid</span>) || <span class="php-keyword">empty</span>(<span class="php-variable">$cid</span>)) ? <span class="php-variable">$cid</span> : <span class="php-function-or-constant"><a class="local" title="Returns the unique cart_id of the user." href="http://drupalcontrib.org/api/drupal/contributions%21ubercart%21uc_cart%21uc_cart.module/function/uc_cart_get_id/7">uc_cart_get_id</a></span>();
  <span class="php-keyword">if</span> (<span class="php-variable">$qty</span> < <span class="php-constant">1</span>) {
    <span class="php-function-or-constant"><a class="local" title="Removes an item from the cart." href="http://drupalcontrib.org/api/drupal/contributions%21ubercart%21uc_cart%21uc_cart.module/function/uc_cart_remove_item/7">uc_cart_remove_item</a></span>(<span class="php-variable">$nid</span>, <span class="php-variable">$cid</span>, <span class="php-variable">$data</span>);
  }
  <span class="php-keyword">else</span> {
    <span class="php-function-or-constant"><a class="local" title="Returns a new UpdateQuery object for the active database." href="http://drupalcontrib.org/api/drupal/drupal%21includes%21database%21database.inc/function/db_update/7">db_update</a></span>(<span class="php-string">'uc_cart_products'</span>)
      -><span class="php-function-or-constant"><a class="local" title="Multiple implementations exist." href="http://drupalcontrib.org/api/search/7/fields">fields</a></span>(<span class="php-keyword">array</span>(
      <span class="php-string">'qty'</span> => <span class="php-variable">$qty</span>, 
      <span class="php-string">'changed'</span> => <span class="php-function-or-constant"><a class="local" title="Time of the current request in seconds elapsed since the Unix Epoch." href="http://drupalcontrib.org/api/drupal/drupal%21includes%21bootstrap.inc/constant/REQUEST_TIME/7">REQUEST_TIME</a></span>,
    ))
      -><span class="php-function-or-constant"><a class="local" title="Multiple implementations exist." href="http://drupalcontrib.org/api/search/7/condition">condition</a></span>(<span class="php-string">'nid'</span>, <span class="php-variable">$nid</span>)
      -><span class="php-function-or-constant"><a class="local" title="Multiple implementations exist." href="http://drupalcontrib.org/api/search/7/condition">condition</a></span>(<span class="php-string">'cart_id'</span>, <span class="php-variable">$cid</span>)
      -><span class="php-function-or-constant"><a class="local" title="Multiple implementations exist." href="http://drupalcontrib.org/api/search/7/condition">condition</a></span>(<span class="php-string">'data'</span>, <span class="php-function-or-constant">serialize</span>(<span class="php-variable">$data</span>))
      -><span class="php-function-or-constant"><a class="local" title="Multiple implementations exist." href="http://drupalcontrib.org/api/search/7/execute">execute</a></span>();
  }
}


 


if ($qty < 1) {

 

CHANGE TO:


if ($qty == 0) {

// FOURTH uc_order -> uc_order.admin.inc //Not sure if it's necessary but just in case (string 1125)

if (!isset($product['remove']) && intval($product['qty']) > 0) {

CHANGE TO:


if (!isset($product['remove']) && ($product['qty']) > 0) {

//FIFTH uc_cart -> uc_cart.install //Not sure if it's necessary but just in case CHANGE TO FLOATS: (string 37)


'qty' => array(
'description' => 'The number of this product in the cart.',
'type' => 'float',
'precision' => 6,
'scale' => 1,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1.0,

AND (string 126)


function uc_cart_update_7001() {
db_change_field('uc_cart_products', 'qty', 'qty', array(
'description' => 'The number of this product in the cart.',
'type' => 'float',
'precision' => 6,
'scale' => 1,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1.0,
));
}

/*uc_store\uc_store.module*/ /*chenge */


function uc_store_validate_uc_quantity(&$element, &$form_state) {
if (!preg_match('/^\d+$/', $element['#value'])) {
form_error($element, t('The quantity must be a number.'));
}
elseif (empty($element['#allow_zero']) && !$element['#value']) {
form_error($element, t('The quantity cannot be zero.'));
}
}

/*on*/


function uc_store_validate_uc_quantity(&$element, &$form_state) {
if (!preg_match("/([0-9\.-]+)/", $element['#value'])) {
form_error($element, t('The quantity must be a number.'));
}
elseif (empty($element['#allow_zero']) && !$element['#value']) {
form_error($element, t('The quantity cannot be zero.'));
}
}

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *

Цей сайт використовує Akismet для зменшення спаму. Дізнайтеся, як обробляються ваші дані коментарів.