Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onVmShippingRulesGetCartValues(&$cartvals, $cart, $products, $method, $cart_prices) {
- //JFactory::getApplication()->enqueueMessage("plgVmShipmentRulesMatkakulut function onVmShippingRulesGetCartValues ", 'error');
- //vmDebug("plgVmShipmentRulesMatkakulut function onVmShippingRulesGetCartValues");
- /*
- if ($cart_prices) {
- // Called for the whole cart...
- } else {
- // Called when any of the scoping operators need the cart values for only a subset of products
- }
- */
- $cartvals['matkakulut'] = false;
- $cartProducts = $cart->products;
- foreach ($cartProducts as $cart_item_id=>$product) {
- //JFactory::getApplication()->enqueueMessage("cart_item_id: " . $cart_item_id, 'error');
- $variantmods = isset($product -> customProductData)?$product -> customProductData:$product -> product_attribute;
- if(empty($variantmods)){
- $productDB = VmModel::getModel('product')->getProduct($product->virtuemart_product_id);
- if($productDB){
- $product->customfields = $productDB->customfields;
- }
- }
- if(!is_array($variantmods)){
- $variantmods = json_decode($variantmods,true);
- }
- //JFactory::getApplication()->enqueueMessage("variantmods: " . $variantmods, 'error');
- $productCustoms = array();
- foreach( (array)$product->customfields as $prodcustom){
- //We just add the customfields to be shown in the cart to the variantmods
- if(is_object($prodcustom)){
- if($prodcustom->is_cart_attribute and !$prodcustom->is_input){
- if(!is_array($variantmods[$prodcustom->virtuemart_custom_id])){
- $variantmods[$prodcustom->virtuemart_custom_id] = array();
- }
- $variantmods[$prodcustom->virtuemart_custom_id][$prodcustom->virtuemart_customfield_id] = false;
- } else if(!empty($variantmods) and !empty($variantmods[$prodcustom->virtuemart_custom_id])){
- }
- $productCustoms[$prodcustom->virtuemart_customfield_id] = $prodcustom;
- }
- } // end foreach( (array)$product->customfields as $prodcustom)
- foreach ( (array)$variantmods as $custom_id => $customfield_ids) {
- if(!is_array($customfield_ids)){
- $customfield_ids = array( $customfield_ids =>false);
- }
- } // end foreach ( (array)$variantmods as $custom_id => $customfield_ids)
- foreach($customfield_ids as $customfield_id=>$params){
- if(empty($productCustoms) or !isset($productCustoms[$customfield_id])){
- continue;
- }
- $productCustom = $productCustoms[$customfield_id];
- //The stored result in vm2.0.14 looks like this {"48":{"textinput":{"comment":"test"}}}
- //and now {"32":[{"invala":"100"}]}
- if (!empty($productCustom)) {
- //JFactory::getApplication()->enqueueMessage("productCustom : " . $productCustom, 'error');
- if ($productCustom->custom_title == "ASENNUS" && $productCustom-> customfield_price > 0) {
- $cartvals['matkakulut'] = true;
- }
- } // end if
- } // end foreach($customfield_ids as $customfield_id=>$params)
- } // end foreach ($cartProducts as $cart_item_id=>$product)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement