Hello,

nice module!

I have created a module to disabled the quantity field and to block the quantity to one.
If I added many times a product "P" I have much as lines as quantity of this product in my cart.

Of course if I delete one line it delete all the lines about this product.

How to do to only delete the concerning line?

Thanks in advance. Sorry for my broken english

My module

<?php
function uc_bloc_qte_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'uc_cart_view_form') {
      
	  $i=-2;
	  
	  foreach ($form['items'] as $k => $item) {	
		$arr_nids=$item['nid'];
		$nid=$arr_nids['#value'];
		
	  	if($nid==237){		
	  		$form['items'][$i]['qty']['#disabled'] = true;
	}
		$i++;
      }
  }
}
?>

Comments

apaderno’s picture

Assigned: selinav » Unassigned
Status: Active » Fixed

It seems more a support request for another module, not for this one.

selinav’s picture

excuse-me for the bad category, I'd like to know how it is managed in your module to delete only the good item and not all the items which have a node linked.

Should I add a test on the op ?

Thanks

apaderno’s picture

The code implements hook_order(), and this is the implemented code:

/**
123	 * Implementation of hook_order().
124	 */
125	function uc_node_published_order($op, &$arg1, $arg2) {
126	  switch ($op) {
127	    case 'update':
128	      if ($arg2 == 'completed') {
129	        foreach ($arg1->products as $item) {
130	          $node = node_load($item->data['node_checkout_nid']);
131	          $types = array_keys(uc_node_checkout_product_map());
132	
133	          // Make sure we only affect uc_node_checkout related items.
134	          if (in_array($node->type, $types)) {
135	            // Publish the node.
136	            $node->status = 1;
137	            node_save($node);
138	
139	            watchdog(
140	              'uc_node_published', 'Set @type %title to published.',
141	              array(
142	                '@type' => node_get_types('name', $node),
143	                '%title' => $node->title,
144	              )
145	            );
146	          }
147	        }
148	      }
149	      elseif (($arg2 != 'completed') && ($arg1->order_status == 'completed')) {
150	        foreach ($arg1->products as $item) {
151	          $node = node_load($item->data['node_checkout_nid']);
152	          $types = array_keys(uc_node_checkout_product_map());
153	
154	          // Make sure we only affect uc_node_checkout related items.
155	          if (in_array($node->type, $types)) {
156	            // Unpublish the node.
157	            $node->status = 0;
158	            node_save($node);
159	
160	            watchdog(
161	              'uc_node_published', 'Set @type %title to unpublished.',
162	              array(
163	                '@type' => node_get_types('name', $node),
164	                '%title' => $node->title
165	              )
166	            );
167	          }
168	        }
169	      }
170	      break;
171	
172	    case 'delete':
173	      $search_wipe = function_exists('search_wipe');
174	
175	      foreach($arg1->products as $item) {
176	        $node = node_load($item->data['node_checkout_nid']);
177	        $types = array_keys(uc_node_checkout_product_map());
178	
179	        // Make sure we only affect uc_node_checkout related items.
180	        if (in_array($node->type, $types) && node_access('delete', $node)) {
181	          db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
182	          db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
183	
184	          // Call the node-specific callback.
185	          node_invoke($node, 'delete');
186	          node_invoke_nodeapi($node, 'delete');
187	
188	          // Remove this node from the search index if needed.
189	          if ($search_wipe) {
190	            search_wipe($node->nid, 'node');
191	          }
192	
193	          watchdog(
194	            'uc_node_published', '@type: deleted %title.',
195	            array(
196	              '@type' => $node->type,
197	              '%title' => $node->title,
198	            )
199	          );
200	        }
201	      }
202	      // Clear the page and block caches.
203	      cache_clear_all();
204	      break;
205	  }
206	}
207	
selinav’s picture

ok thanks, I have found the function in your module, but I don't understand why my hook form alter interfere with the order process.

Can you give me an advice please.

Thanks in advance

Status: Fixed » Closed (fixed)

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