I updated Ubercart to the latest version then ran update.php. since then none of the PHP in the custom price field gets run.

Is anyone else having this issue?

CommentFileSizeAuthor
#12 25-8-2012 17-19-15.png108.81 KBjawi
#12 25-8-2012 17-26-58.png108.5 KBjawi

Comments

Luisvsm’s picture

I also tried updating to the latest dev version of Ubercart Custom Price, and it's running on Drupal 7.

And the code that I am using is:

if(is_numeric(preg_replace('/[^-0-9.]/i', '', $item->data['attributes'][2]))){
     $item->price = $item->display_price = preg_replace('/[^-0-9.]/i', '', $item->data['attributes'][2]);
}else{
     $item->price = 0;
     $item->display_price = 0;
}
bensey’s picture

I'm having this problem too.

It seems that in Ubercart 7.x-3.0-rc4 they have removed the hook hook_uc_cart_item() which this module uses to adjust prices. Until it is updated I believe it will not work with Ubercart rc4.

rofsky’s picture

It looks like the hook has been replaced with the cart item controller in : uc_cart/uc_cart.controller.inc

class UcCartItemController extends UcOrderProductController {

public function attachLoad(&$items, $revision_id = FALSE) {
foreach ($items as &$item) {
$product = uc_product_load_variant($item->nid, $item->data);
// Merge in fields from the product.
foreach ($product as $key => $value) {
$item->$key = $value;
}
$item->module = $item->data['module'];
}
parent::attachLoad($items, $revision_id);
}
}

looking at it now in efforts to replace the hook in the uc_custom price module with the appropriate code for the new controller class.

tr’s picture

Status: Needs review » Active

"needs review" is for when there's a patch.

Dylanotron’s picture

While the solution would be to extend UcCartItemController in uc_custom_price, modifying UcCartItemController with the out-dated uc_custom_price_uc_cart_item adds custom pricing to cart/order item.

public function attachLoad(&$items, $revision_id = FALSE) {
    foreach ($items as &$item) {
      $product = uc_product_load_variant($item->nid, $item->data);
      // Merge in fields from the product.
      $code = isset($product->custom_code) ? $product->custom_code : '';
      $code = str_replace('$item->price =','$product->display_price = $product->price =',$code);
      if (!empty($code)) {
        $eval_code = token_replace($code, array('product' => $product, 'uc_cart_item' => $item));
        eval($eval_code);
      }
      foreach ($product as $key => $value) {
        $item->$key = $value;
      }
      $item->module = $item->data['module'];
    }
    parent::attachLoad($items, $revision_id);
  }
symp’s picture

I have tried placing this code under the uc_custom_price_uc_cart_item function in the uc custom price module, however it causes my entire site to not load.

Can anyone offer some help on this?

Thanks in advance.

*EDIT*

Solved by placing the code snippet under the file located in uc_cart, my mistake!

pokadan’s picture

I've modiffied uc_cart.controller.inc under uc_cart with the hacky
public function attachLoad(&$items, $revision_id = FALSE)
Still nothing happens for me.
I set $item->price = 0; to test but all prices get added as usual to the total amount of cart.

Anonymous’s picture

If you wanted to keep it totally contained in custom price, no modifying core ubercart files, the following will create an overriding class for uc_cart_items:

function uc_custom_price_entity_info_alter(&$entity_info) {
$entity_info['uc_cart_item']['controller class'] = 'CustomPriceCartItemController';
}

class CustomPriceCartItemController extends UcCartItemController {
public function attachLoad(&$items, $revision_id = FALSE) {
// call original attachLoad first - if called after it will override anything done here
parent::attachLoad($items, $revision_id);
foreach ($items as &$item) {
$product = uc_product_load_variant($item->nid, $item->data);
// Merge in fields from the product.
$code = isset($product->custom_code) ? $product->custom_code : '';
$code = str_replace('$item->price =','$product->display_price = $product->price =',$code);
if (!empty($code)) {
$eval_code = token_replace($code, array('product' => $product, 'uc_cart_item' => $item));
eval($eval_code);
}
foreach ($product as $key => $value) {
$item->$key = $value;
}
$item->module = $item->data['module'];
}
}
}

jawi’s picture

I can use some support with this.

freelock’s picture

Dang. Why change the API for pricing now, with all new activity going on in Commerce?

Adding the code from #8 to uc_custom_price.module does fix this for me.

freelock’s picture

Oh, with one major caveat -- in my case I'm grabbing a price from a textfield attribute. You would think you could do this with a rule, but no.

Using uc_custom_price, attribute data is still stored in $item->data. However, when viewing the node, $item->data is a serialized array with stuff you don't need -- it only becomes an array when added to a cart.

So the upshot of this is you need to detect the type before setting price:

$item->price = is_array($item->data) ? $item->data['attributes'][8] : 0;
jawi’s picture

StatusFileSize
new108.5 KB
new108.81 KB

When we are using the costum price fields, the attribute more price doesn't display and these more prices aren't added.

We are using this rule with a custom discount field:

$item->price = floor((float)$item->list_price - (float)$item->list_price*(float)$item->field_disount_percentage['und'][0]['value']/100 + $item->price);

When using the standard rule:
$item->price = $item->price;
The attribute more price are ok!

Any idea how comes?

http://31.3.101.171/~idc/?q=nieuw_kantoormeubilair/bureau-bravo-c

tonebari’s picture

Thanks so much r_smylski for a quick solution. Sure looking forward to some more docs to bring us up to speed.

elaman’s picture

Status: Active » Closed (duplicate)

Probably #1823112: Ubercart 3.2 Fix is duplicate, but first comment has the patch which could fix this problem. I'll put status as dublicate.