예제 #1
0
	/**
	 * @param \VirtueMartCart $cart
	 * @param int             $method
	 * @param array           $cart_prices
	 * @return bool
	 */
	protected function checkConditions ($cart, $method, $cart_prices) {

		static $result = array();

		if($cart->STsameAsBT == 0){
			$type = ($cart->ST == 0 ) ? 'BT' : 'ST';
		}else{
			$type = 'BT';
		}

		$address = $cart -> getST();

		if(!is_array($address)) $address = array();
		if(isset($cart_prices['salesPrice'])){
			$hashSalesPrice = $cart_prices['salesPrice'];
		} else {
			$hashSalesPrice = '';
		}


		if(empty($address['virtuemart_country_id'])) $address['virtuemart_country_id'] = 0;
		if(empty($address['zip'])) $address['zip'] = 0;

		$hash = $method->virtuemart_shipmentmethod_id.$type.$address['virtuemart_country_id'].'_'.$address['zip'].'_'.$hashSalesPrice;

		if(isset($result[$hash])){
			return $result[$hash];
		}
		$this->convert ($method);
		$orderWeight = $this->getOrderWeight ($cart, $method->weight_unit);

		$countries = array();
		if (!empty($method->countries)) {
			if (!is_array ($method->countries)) {
				$countries[0] = $method->countries;
			} else {
				$countries = $method->countries;
			}
		}


		$weight_cond = $this->testRange($orderWeight,$method,'weight_start','weight_stop','weight');
		$nbproducts_cond = $this->_nbproductsCond ($cart, $method);

		if(isset($cart_prices['salesPrice'])){
			$orderamount_cond = $this->testRange($cart_prices['salesPrice'],$method,'orderamount_start','orderamount_stop','order amount');
		} else {
			$orderamount_cond = FALSE;
		}

		$userFieldsModel =VmModel::getModel('Userfields');
		if ($userFieldsModel->fieldPublished('zip', $type)){
			if (!isset($address['zip'])) {
				$address['zip'] = '';
			}
			$zip_cond = $this->testRange($address['zip'],$method,'zip_start','zip_stop','zip');
		} else {
			$zip_cond = true;
		}

		if ($userFieldsModel->fieldPublished('virtuemart_country_id', $type)){

			if (!isset($address['virtuemart_country_id'])) {
				$address['virtuemart_country_id'] = 0;
			}

			if (in_array ($address['virtuemart_country_id'], $countries) || count ($countries) == 0) {

				//vmdebug('checkConditions '.$method->shipment_name.' fit ',$weight_cond,(int)$zip_cond,$nbproducts_cond,$orderamount_cond);
				vmdebug('shipmentmethod '.$method->shipment_name.' = TRUE for variable virtuemart_country_id = '.$address['virtuemart_country_id'].', Reason: Countries in rule '.implode($countries,', ').' or none set');
				$country_cond = true;
			}
			else{
				vmdebug('shipmentmethod '.$method->shipment_name.' = FALSE for variable virtuemart_country_id = '.$address['virtuemart_country_id'].', Reason: Country '.implode($countries,', ').' does not fit');
				$country_cond = false;
			}
		} else {
			vmdebug('shipmentmethod '.$method->shipment_name.' = TRUE for variable virtuemart_country_id, Reason: no boundary conditions set');
			$country_cond = true;
		}

		$allconditions = (int) $weight_cond + (int)$zip_cond + (int)$nbproducts_cond + (int)$orderamount_cond + (int)$country_cond;
		if($allconditions === 5){
			$result[$hash] = true;
			return TRUE;
		} else {
			$result[$hash] = false;
			//vmdebug('checkConditions '.$method->shipment_name.' does not fit ',(int)$weight_cond,(int)$zip_cond,(int)$nbproducts_cond,(int)$orderamount_cond,(int)$country_cond);
			return FALSE;
		}

		$result[$hash] = false;
		return FALSE;
	}
예제 #2
0
파일: paypal.php 프로젝트: ForAEdesWeb/AEW9
 /**
  * Check if the payment conditions are fulfilled for this payment method
  * @param VirtueMartCart $cart
  * @param int $activeMethod
  * @param array $cart_prices
  * @return bool
  */
 protected function checkConditions($cart, $activeMethod, $cart_prices)
 {
     //Check method publication start
     if ($activeMethod->publishup) {
         $nowDate = JFactory::getDate();
         $publish_up = JFactory::getDate($activeMethod->publishup);
         if ($publish_up->toUnix() > $nowDate->toUnix()) {
             return FALSE;
         }
     }
     if ($activeMethod->publishdown) {
         $nowDate = JFactory::getDate();
         $publish_down = JFactory::getDate($activeMethod->publishdown);
         if ($publish_down->toUnix() <= $nowDate->toUnix()) {
             return FALSE;
         }
     }
     $this->convert_condition_amount($activeMethod);
     $address = $cart->getST();
     $amount = $this->getCartAmount($cart_prices);
     $amount_cond = ($amount >= $activeMethod->min_amount and $amount <= $activeMethod->max_amount or $activeMethod->min_amount <= $amount and $activeMethod->max_amount == 0);
     $countries = array();
     if (!empty($activeMethod->countries)) {
         if (!is_array($activeMethod->countries)) {
             $countries[0] = $activeMethod->countries;
         } else {
             $countries = $activeMethod->countries;
         }
     }
     // probably did not gave his BT:ST address
     if (!is_array($address)) {
         $address = array();
         $address['virtuemart_country_id'] = 0;
     }
     if (!isset($address['virtuemart_country_id'])) {
         $address['virtuemart_country_id'] = 0;
     }
     if (in_array($address['virtuemart_country_id'], $countries) || count($countries) == 0) {
         if ($amount_cond) {
             return TRUE;
         }
     }
     return FALSE;
 }
예제 #3
0
 /**
  * @param \VirtueMartCart $cart
  * @param int             $method
  * @param array           $cart_prices
  * @return bool
  */
 protected function checkConditions($cart, $method, $cart_prices)
 {
     static $result = array();
     if ($cart->STsameAsBT == 0) {
         $type = $cart->ST == 0 ? 'BT' : 'ST';
     } else {
         $type = 'BT';
     }
     $address = $cart->getST();
     if (!is_array($address)) {
         $address = array();
     }
     if (isset($cart_prices['salesPrice'])) {
         $hashSalesPrice = $cart_prices['salesPrice'];
     } else {
         $hashSalesPrice = '';
     }
     if (empty($address['virtuemart_country_id'])) {
         $address['virtuemart_country_id'] = 0;
     }
     if (empty($address['zip'])) {
         $address['zip'] = 0;
     }
     $hash = $method->virtuemart_shipmentmethod_id . $type . $address['virtuemart_country_id'] . '_' . $address['zip'] . '_' . $hashSalesPrice;
     if (isset($result[$hash])) {
         return $result[$hash];
     }
     $this->convert($method);
     $orderWeight = $this->getOrderWeight($cart, $method->weight_unit);
     $countries = array();
     if (!empty($method->countries)) {
         if (!is_array($method->countries)) {
             $countries[0] = $method->countries;
         } else {
             $countries = $method->countries;
         }
     }
     $weight_cond = $this->testRange($orderWeight, $method, 'weight_start', 'weight_stop', 'weight');
     $nbproducts_cond = $this->_nbproductsCond($cart, $method);
     if (isset($cart_prices['salesPrice'])) {
         $orderamount_cond = $this->testRange($cart_prices['salesPrice'], $method, 'orderamount_start', 'orderamount_stop', 'order amount');
     } else {
         $orderamount_cond = FALSE;
     }
     $userFieldsModel = VmModel::getModel('Userfields');
     if ($userFieldsModel->fieldPublished('zip', $type)) {
         if (!isset($address['zip'])) {
             $address['zip'] = '';
         }
         $zip_cond = $this->testRange($address['zip'], $method, 'zip_start', 'zip_stop', 'zip');
     } else {
         $zip_cond = true;
     }
     if ($userFieldsModel->fieldPublished('virtuemart_country_id', $type)) {
         if (!isset($address['virtuemart_country_id'])) {
             $address['virtuemart_country_id'] = 0;
         }
         if (in_array($address['virtuemart_country_id'], $countries) || count($countries) == 0) {
             //vmdebug('checkConditions '.$method->shipment_name.' fit ',$weight_cond,(int)$zip_cond,$nbproducts_cond,$orderamount_cond);
             vmdebug('shipmentmethod ' . $method->shipment_name . ' = TRUE for variable virtuemart_country_id = ' . $address['virtuemart_country_id'] . ', Reason: Countries in rule ' . implode($countries, ', ') . ' or none set');
             $country_cond = true;
         } else {
             vmdebug('shipmentmethod ' . $method->shipment_name . ' = FALSE for variable virtuemart_country_id = ' . $address['virtuemart_country_id'] . ', Reason: Country ' . implode($countries, ', ') . ' does not fit');
             $country_cond = false;
         }
     } else {
         vmdebug('shipmentmethod ' . $method->shipment_name . ' = TRUE for variable virtuemart_country_id, Reason: no boundary conditions set');
         $country_cond = true;
     }
     $cat_cond = true;
     if ($method->categories or $method->blocking_categories) {
         if ($method->categories) {
             $cat_cond = false;
         }
         //vmdebug('hmm, my value',$method);
         //if at least one product is  in a certain category, display this shipment
         if (!is_array($method->categories)) {
             $method->categories = array($method->categories);
         }
         if (!is_array($method->blocking_categories)) {
             $method->blocking_categories = array($method->blocking_categories);
         }
         //Gather used cats
         foreach ($cart->products as $product) {
             if (array_intersect($product->categories, $method->categories)) {
                 $cat_cond = true;
                 //break;
             }
             if (array_intersect($product->categories, $method->blocking_categories)) {
                 $cat_cond = false;
                 break;
             }
         }
         //if all products in a certain category, display the shipment
         //if a product has a certain category, DO NOT display the shipment
     }
     $allconditions = (int) $weight_cond + (int) $zip_cond + (int) $nbproducts_cond + (int) $orderamount_cond + (int) $country_cond + (int) $cat_cond;
     if ($allconditions === 6) {
         $result[$hash] = true;
         return TRUE;
     } else {
         $result[$hash] = false;
         //vmdebug('checkConditions '.$method->shipment_name.' does not fit ',(int)$weight_cond,(int)$zip_cond,(int)$nbproducts_cond,(int)$orderamount_cond,(int)$country_cond);
         return FALSE;
     }
     $result[$hash] = false;
     return FALSE;
 }