Hi, thank you for this module. I was wondering whether somebody is already working on a Drupal 7 port. Martin.

Comments

MPeli’s picture

StatusFileSize
new68.05 KB
new8.72 KB

I have tried to convert these functions:

  • uc_price_per_rolepermission()
  • uc_price_per_role_menu()
  • uc_price_per_role_theme()
  • uc_price_per_role_settings_form()
  • theme_uc_price_per_role_settings_form()

This is my first try to create a module :) So be patient please.

MPeli’s picture

StatusFileSize
new80.66 KB
new9.55 KB

I have made some progress.

MPeli’s picture

StatusFileSize
new10.24 KB

Attached port allows you to set different prices for different roles. I am stuck and do not know how to continue, especially with part "Optional prices".

longwave’s picture

Title: Will there be a Drupal 7 port? » Drupal 7 port
Status: Active » Needs review

I realised I've neglected Price Per Role for some time, so many thanks for posting this; I'll review it when I find some free time, or maybe someone else can step in to help out with a review as well.

After a quick look at the code just now, it would be helpful if you could ensure the Drupal coding standards are followed - use two spaces instead of tabs, and run your code through Coder module - and also if you could post patch file(s) instead of zips.

MPeli’s picture

StatusFileSize
new73.33 KB
new79.91 KB
new11.97 KB

A new development version is attached. I have run it through Coder module. As soon as I learn how to create a patch I will do it. Sorry for the zip file. Would it be possible to create official release? Something like Ubercart Price Per Role 7.x-alpha1? I think it would speed up the whole development process.

  • block Pricing selection is functional
  • option prices are partly functional
  • many php notices come up

Thanks, Martin.

MPeli’s picture

StatusFileSize
new12.52 KB

I have made some progress.

This function is not being executed and I do not know exactly why.
uc_price_per_role_cart_item($op, &$item)

longwave’s picture

I think the hook has been renamed in Ubercart 7.x-3.x, so the function should now be called uc_price_per_role_uc_cart_item.

I will create a 7.x-3.x-dev branch once I've found some time to review and commit your code. Thank you for your work on this!

MPeli’s picture

StatusFileSize
new12.52 KB

Thanks! You are right. The function has been renamed. A new version is attached.

shadowmihai’s picture

subscribe

shadowmihai’s picture

Is there any further development on this module? I can help test on my site(s) (but I cannot program... php illiterate, really...)

pglatz’s picture

Thanks for starting the 7 port; this is a module I really need. I was able to create a role and add a different price for a wholesale user. Terrific!

I found a few of issues I wanted to point out:

1) Calls to install/uninstall the schema are not required in the .install files in Drupal 7, and will generate an error. Here's what I did:

uc_price_per_role_install()
remove call to drupal_install_schema()

uc_price_per_role_uninstall()
remove call to drupal_uninstall_schema()

2) When I create a product, I see these notices:
Notice: Undefined property: stdClass::$roleindependent_sell_price in uc_price_per_role_node_prepare() (line 330 of uc_price_per_role\uc_price_per_role.module).
Notice: Undefined property: stdClass::$role_prices in uc_price_per_role_form_alter() (line 180 of uc_price_per_role\uc_price_per_role.module).
Notice: Undefined offset: 1 in uc_price_per_role_form_alter() (line 182 of uc_price_per_role\uc_price_per_role.module).
Notice: Undefined offset: 2 in uc_price_per_role_form_alter() (line 182 of uc_price_per_role\uc_price_per_role.module).
Notice: Undefined offset: 3 in uc_price_per_role_form_alter() (line 182 of uc_price_per_role\uc_price_per_role.module).
Notice: Undefined property: stdClass::$nid in uc_product_get_shipping_type() (line 495 of ubercart\shipping\uc_quote\uc_quote.module).
Notice: Undefined property: stdClass::$nid in uc_product_get_shipping_type() (line 495 of ubercart\shipping\uc_quote\uc_quote.module).

3) I then created a wholesaler role, and enabled it in the config. This took care of some of the notices; this is what I see now:

Notice: Undefined property: stdClass::$roleindependent_sell_price in uc_price_per_role_node_prepare() (line 330 of uc_price_per_role\uc_price_per_role.module).
Notice: Undefined property: stdClass::$role_prices in uc_price_per_role_form_alter() (line 180 of uc_price_per_role\uc_price_per_role.module).
Notice: Undefined property: stdClass::$nid in uc_product_get_shipping_type() (line 495 of ubercart\shipping\uc_quote\uc_quote.module).
Notice: Undefined property: stdClass::$nid in uc_product_get_shipping_type() (line 495 of ubercart\shipping\uc_quote\uc_quote.module).

I don't have the time today to dig much further, but I am a module developer, and might be able to give some suggestions. I'm fairly new to 7 but am trying to use it for all new work.

If this isn't going to be an official port yet, you can always create your own repository for free at github, if you are interested in working with others on this. Much easier to coordinate than zip files!

Good work, it is working fine for me. The notices are the only problem I'm seeing right now, and they can probably be eliminated with a few simple variable checks.

hozt’s picture

Thanks for doing the work on this.

I was getting a notice when viewing a product about an invalid index. I fixed this by changing line #360

- if (user_access('access price selection block') && $_SESSION['price_role'] && isset($prices[$_SESSION['price_role']])) {
+ if (user_access('access price selection block') && isset($_SESSION['price_role']) && isset($prices[$_SESSION['price_role']])) {
MPeli’s picture

StatusFileSize
new12.48 KB

Hi,

I have tried to create a repository at github - https://github.com/MPeli/Ubercart-Price-Per-Role Unfortunately, I was not able to upload any files. When I try to upload something a get error 404.

#180

- $role_prices = $form['#node']->role_prices;    
+ if(isset($form['#node']->role_prices)) {
+         $role_prices = $form['#node']->role_prices;
+ }

#330

- // Reload original price for editing.
- $node->sell_price = $node->roleindependent_sell_price;
+ if(isset($node->roleindependent_sell_price)) {
+     // Reload original price for editing.
+     $node->sell_price = $node->roleindependent_sell_price;
+ } 
hozt’s picture

This is getting closer to working. There are a couple of remaining issues:

1) After you enter a role based price on a product and save the product all works well. If you edit the product again the role price will be blank. It looks like this is not a problem for attribute based pricing. Changing line #296 made it work for me:

#296
- $result = db_query("SELECT nid, rid, price FROM {uc_price_per_role_prices} WHERE vid IN(:vids)", array(':vids' => array_keys($nodes)));
+ $result = db_query("SELECT nid, rid, price FROM {uc_price_per_role_prices} WHERE nid IN(:nids)", array(':nids' => array_keys($nodes)));

2) The option to add additional roles prices does not show up for any custom product classes. I am not sure what the fix for this one is because the form_id for a custom product class will be something besides "product_node_form". Can we check for something else to confirm that we are editing a product type?

- if ($form_id == 'product_node_form') {
+ if (is_array($form['base'])) { // this works, but there must be a better way to check if we are editing a product

MPeli’s picture

Hi,

I have made some changes have a look at the new version https://github.com/MPeli/Ubercart-Price-Per-Role

I do not face the problem you described in point number 1) that is why I did not implement suggested changes. Do you use the latest version of Ubercart?

I modified function uc_price_per_role_node_load() as well.

Martin.

duaelfr’s picture

I have done a pull request on github to correct a tiny mistake
I will try your module now

Thank you for this great work

duaelfr’s picture

It seems to work well despite of the multiples notices.

I will pull a patch for it in a few seconds

eusofzay’s picture

Why don't you list it as a dev version atleast.

eusofzay’s picture

Component: Miscellaneous » Code
Category: task » bug

I am getting this error when create a new product. If I have 5 roles then this notice is displayed 5 times.

Notice: Undefined offset: 1 in uc_price_per_role_form_alter() (line 188 of /home/hl7org/public_html/sites/all/modules/uc_price_per_role/uc_price_per_role.module).

eusofzay’s picture

Notice: Undefined property: stdClass::$role_prices in uc_price_per_role_node_insert() (line 333 of /home/hl7org/public_html/sites/all/modules/uc_price_per_role/uc_price_per_role.module).

davisben’s picture

I have rolled a patch against master that incorporates the latest code from MPeli's github repo with a fix for #19. I couldn't reproduce #20, anyone else seeing that error?

longwave - would you be interested in adding a co-maintainer for the 7.x branch?

davisben’s picture

StatusFileSize
new31.45 KB

Oops, forgot the patch.

longwave’s picture

Category: bug » task
Status: Needs review » Fixed

Huge thanks to everyone who's contributed to this. I've created a 7.x branch, based on #22 with the following changes:

  • Re-added hook_uninstall()
  • Added hook_update_last_removed()
  • Fixed permission name in hook_permission()
  • Removed old uc_price() context arrays
  • Added missing uc_currency_format() in option price formatting
  • Added hook_node_delete() and hook_node_revision_delete()
  • Fixed some comments
  • Fixed error reported in #20

Migrate integration is untested and probably needs work.

Download immediately from git, or wait a few hours for the 7.x-1.x-dev package to be built.

Status: Fixed » Closed (fixed)

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

jcgarsan’s picture

Hi guys!
First at all, good job!!!!
I'm trying to configure this module in Drupal 7x + Ubercart 3x, and I have this error:

Notice: Undefined index: #value en uc_price_per_role_form_alter() (line 213 of /var/www/tienda/sites/all/modules/uc_price_per_role/uc_price_per_role.module).

So, it appears one error for each product I have in the store. Any suggestion?

Many thanks!!!

duaelfr’s picture

@jcgarsan
Sorry but I have no IDE nor Git on this computer to provide a patch.

In the file uc_price_per_role.module
Replace the line 213

$qty = intval($form['qty']['#value']);

By

if (isset($form['qty']['#value'])) {
  $qty = intval($form['qty']['#value']);
}
conkdg’s picture

Subscribe

jcgarsan’s picture

Hi DuaelFr,
I've tried your trip but it doesn't work. Now it appears this error:

Notice: Undefined variable: qty in uc_price_per_role_form_alter() (line 217 de /var/www/tiendaleds/sites/all/modules/uc_price_per_role/uc_price_per_role.module).

I think the problem is in the database table, where it doesn't appear the "qty" colum, may it be possible?

Many thanks for your help!!

duaelfr’s picture

It is not a real bug but just a warning from PHP.

Try replacing

if (isset($form['qty']['#value'])) {
  $qty = intval($form['qty']['#value']);
}

By

if (isset($form['qty'])) {
  $qty = intval($form['qty']['#value']);
}

The modules' database tables are not supposed to have a "qty" column. This field might be in the "add to cart" form to allow the user to add more than one product to his cart but this option may be disabled in your shop.

jcgarsan’s picture

Hi DuaelFr,
I see... so that's not a bug... so maybe, it'd be necessary to check the other functions and find out why this function fails. I've made your last modification and the warning is still there... If that's a warning, is there any possibility to avoid it?
I'll try to take a look around and follow the 'qty' variable, in order to get more information.

Once again, thanks for your help and if you have any suggestion more or any idea to test, tell me!!

Thanks!!!

PS: i'm a newbie in Drupal.... :S

duaelfr’s picture

Hi,
Warnings can be hidden by editing the error_level var in php.ini
While warnings are not errors, your site will be flly functional if you hide them.

jcgarsan’s picture

Hi friends,
I'm not sure but I think I've found a solution. I think the problem is the #value tag. Can anyone try to confirm if this mod works fine?

Initial modification:
if (isset($form['qty'])) {
$qty = intval($form['qty']['#value']);
}
My modification:
if (isset($form['qty'])) {
$qty = intval($form['qty']['#default_value']);
}

What do you think about??

duaelfr’s picture

The result will depend on your uc configuration.

If quantity field is a textfield or a select box (I don't remember) so the correct key will be #default_value
If the field is hidden, the correct key will be #value

http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....

jcgarsan’s picture

Hi all!!
DuaelFr, many thanks for your help. I think the "problem" has been solved using the key #default_value, as well as you mention, my quantity field is a textfield.
Once again, thank you and good job!!!

jcgarsan