Login
Register

VirtueMart

WooCommerce

Others

Docs

Support

Blog

About

Forum

IMPORTANT ANNOUNCEMENT: Plugin development ceased, all plugins made available freely (GPL)

With great sadness we have to announce that we are ceasing development of all our VirtueMart, WooCommerce and Joomla plugins. Effective immediately, all our plugins -- even those that were paid downloads -- are made available for free from our homepage (GPL license still applies), but we cannot and will not provide any support anymore.

It has been a great pleasure to be part of the thriving development communities of VirtueMart as well as WooCommerce. However, during the last year it became painstakingly clear that in addition to a full-time job, a young family and several other time-consuming hobbies at professional level (like being a professional singer) the plugin development and the support that it requires is not sustainable and is taking its toll. It has been an honor, but it is now time to say good bye!

×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Problem to create custom field 26 May 2015 09:56 #1

  • mediafaune
  • mediafaune's Avatar Topic Author
Dear Reinhold,
I just made a custom field "Dangerous" and define products dangerous by this custom field.
Now the problem is that I want use "Dangerous" in my rules. But how can i get the value of my custom field "Dangerous" ?

I use your plugin extension to create this, I send you the code Dangerous.php:
<?php

defined ('_JEXEC') or die('Restricted access');

if (!class_exists ('VmPlugin')) {
	require(JPATH_VM_PLUGINS . DS . 'vmplugin.php');
}

class plgVmShipmentRulesDangerous extends VmPlugin {

	function onVmShippingRulesGetCartValues(&$cartvals, $cart, $products, $method, $cart_prices) {
		$cartvals['Dangerous'] = VALUE OF DANGEROUS;		
	}
	function onVmShippingRulesRegisterCustomFunctions() {}
}

My question is : How can I get the "VALUE OF DANGEROUS"?
Best regards.

Problem to create custom field 26 May 2015 17:48 #2

  • mediafaune
  • mediafaune's Avatar Topic Author
Hi again,
I did a print_r($cart) and found a variable like this:
[customfields] -> Dangerous 1
How can I get this field? I already tried $cart->customfields, it doesn't works.

Somebody could help me?

Best regards.

Problem to create custom field 28 May 2015 00:11 #3

Dear Mediafaune,
First of all, you need to be aware that the plugin calculates shipping costs based on CART characteristics. In particular, the onVmShippingRulesGetCartValues is passed the whole cart and the list of products to be considered (e.g. when there is a evaluate_for_categories(....) call, the onVmShippingRulesGetCartValues function will be called to get the cart variables for just the products that have the desired categories. The $cart will always be the full cart, though. So to get the calculations right, you really need to use the $products list rather than the $cart.

Second, each member of the $products list has an array of all customfields, so if you want to set the variable Dangerous to true (value 1), then you need to loop through all products, for each product loop through all customfields of that product and if the customfield is the "Dangerous" customfield, then check the value of the custom field. I would write the code like:
function onVmShippingRulesGetCartValues(&$cartvals, $cart, $products, $method, $cart_prices) {
  $cartvals['dangerous'] = false;
  foreach ($products as $p) {
    foreach ($p->customfields as $cf) {
      if ($cf->custom_title=="Dangerous" and $cf->customfield_value==1) {
        $cartvals['dangerous'] = true;
      }
    }
  }
}

This should give you an idea how you can adjust the code if you use other custom field values.

Best regards,
Reinhold

Problem to create custom field 01 Jun 2015 11:42 #4

  • mediafaune
  • mediafaune's Avatar Topic Author
Dear Reinhold,

First of all, thanks you for helping.
I've tried your code but the field $p->customfields seems to be a field and NOT an array.
So I've just change the code like this
$cartvals['dangerous'] = false;
		foreach ($products as $p) {
			if(preg_match("#Dangerous#", $p->customfields)){
				$cartvals['dangerous'] = true;
			}
		}

And now it works well. But may be there is another solution to find thoses fields in customfields?
Best regards.

[SOLVED] Problem to create custom field 02 Jun 2015 00:49 #5

Problem solved.

[SOLVED] Problem to create custom field 03 Jun 2015 17:30 #6

  • mediafaune
  • mediafaune's Avatar Topic Author
Problem solved.
  • Page:
  • 1