Closed (duplicate)
Project:
Ubercart Custom Price
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
6 Feb 2012 at 22:59 UTC
Updated:
5 Mar 2013 at 10:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
Luisvsm commentedI 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:
Comment #2
bensey commentedI'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.
Comment #3
rofsky commentedIt 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.
Comment #4
tr commented"needs review" is for when there's a patch.
Comment #5
Dylanotron commentedWhile 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.
Comment #6
symp commentedI 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!
Comment #7
pokadan commentedI'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.
Comment #8
Anonymous (not verified) commentedIf 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'];
}
}
}
Comment #9
jawi commentedI can use some support with this.
Comment #10
freelockDang. 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.
Comment #11
freelockOh, 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:
Comment #12
jawi commentedWhen 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
Comment #13
tonebari commentedThanks so much r_smylski for a quick solution. Sure looking forward to some more docs to bring us up to speed.
Comment #14
elamanProbably #1823112: Ubercart 3.2 Fix is duplicate, but first comment has the patch which could fix this problem. I'll put status as dublicate.