VirtueMart

WooCommerce

Others

Docs

Support

Demo

Blog

About

Forum

We are currently unable to provide proper support!

For the last few months we have been very busy working on some huge, very time-consuming and time-sensitive projects, so our support was very limited and we were unable to provide proper support in our forums! We now have a huge backlog of requests from our customers, which we are trying to clear bit by bit. Unfortunately, this takes longer than we anticipated, so our response time is not yet up to par. We are trying our best to improve this situation as soon as possible.

Sorry for the inconvenience and thank you for your understanding!

Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: [SOLVED] Problem to create custom field

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

  • mediafaune
  • mediafaune's Avatar Topic Author
  • Offline
  • Posts: 7
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.

Please Log in or Create an account to join the conversation.

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

  • mediafaune
  • mediafaune's Avatar Topic Author
  • Offline
  • Posts: 7
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.

Please Log in or Create an account to join the conversation.

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

Please Log in or Create an account to join the conversation.

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

  • mediafaune
  • mediafaune's Avatar Topic Author
  • Offline
  • Posts: 7
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.

Please Log in or Create an account to join the conversation.

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

Problem solved.

Please Log in or Create an account to join the conversation.

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

  • mediafaune
  • mediafaune's Avatar Topic Author
  • Offline
  • Posts: 7
Problem solved.

Please Log in or Create an account to join the conversation.

  • Page:
  • 1

VM - Shopping cart

 x 

Cart empty

Login Formular