Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. function onVmShippingRulesGetCartValues(&$cartvals, $cart, $products, $method, $cart_prices) {
  2. //JFactory::getApplication()->enqueueMessage("plgVmShipmentRulesMatkakulut function onVmShippingRulesGetCartValues ", 'error');
  3. //vmDebug("plgVmShipmentRulesMatkakulut function onVmShippingRulesGetCartValues");
  4. /*
  5. if ($cart_prices) {
  6. // Called for the whole cart...
  7. } else {
  8. // Called when any of the scoping operators need the cart values for only a subset of products
  9. }
  10. */
  11. $cartvals['matkakulut'] = false;
  12.  
  13. $cartProducts = $cart->products;
  14. foreach ($cartProducts as $cart_item_id=>$product) {
  15. //JFactory::getApplication()->enqueueMessage("cart_item_id: " . $cart_item_id, 'error');
  16. $variantmods = isset($product -> customProductData)?$product -> customProductData:$product -> product_attribute;
  17.  
  18. if(empty($variantmods)){
  19. $productDB = VmModel::getModel('product')->getProduct($product->virtuemart_product_id);
  20. if($productDB){
  21. $product->customfields = $productDB->customfields;
  22. }
  23. }
  24. if(!is_array($variantmods)){
  25. $variantmods = json_decode($variantmods,true);
  26. }
  27.  
  28. //JFactory::getApplication()->enqueueMessage("variantmods: " . $variantmods, 'error');
  29.  
  30. $productCustoms = array();
  31. foreach( (array)$product->customfields as $prodcustom){
  32.  
  33. //We just add the customfields to be shown in the cart to the variantmods
  34. if(is_object($prodcustom)){
  35. if($prodcustom->is_cart_attribute and !$prodcustom->is_input){
  36. if(!is_array($variantmods[$prodcustom->virtuemart_custom_id])){
  37. $variantmods[$prodcustom->virtuemart_custom_id] = array();
  38. }
  39. $variantmods[$prodcustom->virtuemart_custom_id][$prodcustom->virtuemart_customfield_id] = false;
  40.  
  41. } else if(!empty($variantmods) and !empty($variantmods[$prodcustom->virtuemart_custom_id])){
  42.  
  43. }
  44. $productCustoms[$prodcustom->virtuemart_customfield_id] = $prodcustom;
  45. }
  46. } // end foreach( (array)$product->customfields as $prodcustom)
  47.  
  48. foreach ( (array)$variantmods as $custom_id => $customfield_ids) {
  49.  
  50. if(!is_array($customfield_ids)){
  51. $customfield_ids = array( $customfield_ids =>false);
  52. }
  53. } // end foreach ( (array)$variantmods as $custom_id => $customfield_ids)
  54.  
  55. foreach($customfield_ids as $customfield_id=>$params){
  56.  
  57. if(empty($productCustoms) or !isset($productCustoms[$customfield_id])){
  58. continue;
  59. }
  60. $productCustom = $productCustoms[$customfield_id];
  61. //The stored result in vm2.0.14 looks like this {"48":{"textinput":{"comment":"test"}}}
  62. //and now {"32":[{"invala":"100"}]}
  63. if (!empty($productCustom)) {
  64. //JFactory::getApplication()->enqueueMessage("productCustom : " . $productCustom, 'error');
  65. if ($productCustom->custom_title == "ASENNUS" && $productCustom-> customfield_price > 0) {
  66. $cartvals['matkakulut'] = true;
  67. }
  68. } // end if
  69. } // end foreach($customfield_ids as $customfield_id=>$params)
  70.  
  71. } // end foreach ($cartProducts as $cart_item_id=>$product)
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement