Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Help with code error

    Using a shopping component on joomla 1.6 and its spitting out a code error on the checkout.

    "Warning: Invalid argument supplied for foreach() in /home/........../../......./html/.........../components/com_shoppingmatters/plugins/GeneralShipping/plugin.GeneralShipping.php on line 250"

    the code line in question is :-
    Code:
    foreach($row as $row){
    if someone can help asap please the site is peventsp.com and its on the checkout of the ticket shop.

    M A Chappell

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    241
    Thanks
    1
    Thanked 57 Times in 56 Posts
    PHP Code:
    foreach($row as $r
    You cannot use the same variable name before and after 'as'.

    As i can see, you can actually use the same variable name before and after 'as' (i don't recommend it). Add the following before foreach and check if the error remains.

    PHP Code:
    if (is_array($row))
    {
            foreach(
    $row as $r)


  • #3
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    same error no change

  • #4

  • #5
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <?php
    /**
     * Shopping Matters is a commercial shopping cart. In its early stages it 
     * will be distrubuted for free, and later it will become available for a 
     * nominal fee.
     * 
     * Shopping Matters has been/is developed by Cole Diffin, From Netmatters.
     * 
     * Netmatters aims to provide you with documentation and support for this 
     * product as well as continued updates.
     * 
     * From the Author:
     * Hi Everyone, I would like to take this chance to say that this is my
     * first public release component. typically I design and test everything 
     * myself and then provide very specfic documentation to the limited 
     * number of users.  Therefore in the past I have never had many issues 
     * with bugs etc, as people are doing and using exactly how i have told 
     * them to. What I'm getting at here is that this shopping car will be 
     * flawed, I am aware of that. I ask that if you are reading this as you 
     * are implementing a fix, please contribute it back to me, so that I can 
     * include it for a future release making the component more stable.
     * 
     * @package 	ShoppingMatters
     * @author 		Cole - Netmatters Internet Marketing
     * @version 	$Id: plugin.GeneralShipping.php 123 2011-05-04 01:56:23Z cole $
     * @license     GNU/GPL, see LICENSE.php or http://www.gnu.org/copyleft/gpl.html 
     * @copyright	(C) 2010 Netmatters Internet Marketing / All Rights Reserved
     * @link		http://shop.netmatters.co.nz/
     */
    
    // Check to ensure this file is included in Joomla!
    defined('_JEXEC') or die( 'Restricted access' );
    class PluginGeneralShipping{
    	var $type='shipping';											// For ordering Purposes Only in backend
    	var $name = 'General Shipping'; 										//the name of the Plugin as It will Appear in the backend
    	var $description = "Handles shipping providing Rates and carriers"; 	//the Description of the Plugin as It will Appear in the backend
    	var $published = 0;											//Leave this set to 0, it will get changed depending on admin config
    	
    	/**
    	 * Constructor, plugin is constructed at script runtime 
    	 * if it is enabled, it does not garentee it will be executed.
    	 */
    	function __construct(){
    
    	}
    	
    	function getShippingId(){
    		
    		$sql="SELECT id FROM #__sm_plugins WHERE name LIKE '$this->name'";
    		$db=JFactory::getDBO();
    		$db->setQuery($sql);
    		return $db->loadResult();
    	}
    	
    	
    	function orderView($order){
    		$shipping = explode("||",$order->order->shipping);
    		$pluginsids=explode("||",$order->order->plugin_id);
    		
    		if($pluginsids[0]==$this->getShippingId()){
    			$sql = "SELECT r.name as name, r.packing_fee as packing_fee, c.name as carrier, r.cost as cost FROM #__sm_generalshipping_rates as r JOIN #__sm_generalshipping_carriers as c ON r.carrier_id=c.id WHERE r.id=$shipping[1] LIMIT 1";
    			$db = $order->order->_db;
    			$db->setQuery($sql);
    			$row = $db->loadObject();
    			
    			?>
    			<div class='col width-30'> 
    				<fieldset class="adminform">
    					<legend><?php echo JText::_('SM_GS_DETAILS')?></legend>
    					<table class="admintable">
    						<tr>
    							<td class='key'>
    								<?php echo JText::_('SM_GS_SHIPPER')?>
    							</td>
    							<td>
    								<?php echo JText::_($row->carrier)?>
    								
    							</td>
    						</tr>
    						<tr>
    							<td class='key'>
    								<?php echo JText::_('SM_GS_RATE')?>
    							</td>
    							<td>
    								<?php echo JText::_($row->name)?>
    								
    							</td>
    						</tr>
    						<tr>
    							<td class='key'>
    								<?php echo JText::_('SM_GS_PACKINGFEE')?>
    							</td>
    							<td>
    								<?php echo JText::_(Builder::money($row->packing_fee))?>
    								
    							</td>
    						</tr>
    						<tr>
    							<td class='key'>
    								<?php echo JText::_('SM_PRODUCT_PRICE')?>
    							</td>
    							<td>
    								<?php echo JText::_(Builder::money($row->cost))?>
    								
    							</td>
    						</tr>
    					</table>
    				</fieldset>
    			</div>
    			<?php 
    		}
    		
    	}
    	
    	/**
    	 * Productview this function is called when the admin product edit page is viewed
    	 * @param String $product a copy of the ProductTable class
    	 */
    	function productView($product){
    		$sql = "SELECT weight FROM #__sm_generalshipping_products WHERE product_id=$product->id";
    		$db = JFactory::getDBO();
    		$db->setQuery($sql);
    		$result=$db->loadResult();
    
    		?>
    		<script>
    		function checkfornumber(contents,box) {
    			if (((contents / contents) != 1) && (contents != 0)){
    				alert("<?php echo JText::_("Please enter only a number into the xxx box")?>".replace("xxx", box));
    			}
    			return false;
    		}
    		</script>
    		<div class='col width-100'> 
    			<fieldset class="adminform">
    				<legend><?php echo JText::_('SM_PLUGIN_GS')?></legend>
    				<table class="admintable">
    					<tr>
    						<td class='key'>
    							<span class="editlinktip hasTip" title="<?php echo JText::_('SM_WEIGHT')?>::<?php echo JText::_('SM_GS_WEIGHT_DESC')?>">
    								<?php echo JText::_('SM_WEIGHT')?>
    							</span>
    						</td>
    						<td><?php $js = " onBlur=\"checkfornumber(this.value,'".JText::_('SM_WEIGHT')."') \""?>
    							<?php echo Builder::inputBox('gsweight', $result, false,'gsweight', false, JText::_('SM_WEIGHT'), JText::_('SM_GS_WEIGHT_DESC'),$js )?>
    						</td>
    					</tr>
    
    				</table>
    			</fieldset>
    		</div>
    		<?php 
    		
    	}
    	/**
    	 * When the product is saved, the product data is passed here to process any data that was made available using the product view hook.
    	 * @param unknown_type $row
    	 * @return unknown_type
    	 */
    	function productProcess($row){
    		$mainframe = JFactory::getApplication();
    		
    		$db = &JFactory::GetDBO();
    		$weight = JRequest::getVar('gsweight',-1);
    		if($weight==='')
    			$weight=-1.0;
    		$weight=floatVal(preg_replace("/[^0-9\.-]+/",'',$weight));
    		if ($weight>=0){
    			if($weight===0.0)
    				$mainframe->enqueueMessage(JText::_('SM_GS_ZERO_VALUE'),'notice');
    			$sql="SELECT COUNT(*) FROM #__sm_generalshipping_products WHERE product_id=$row->id";
    			$db->setQuery($sql);
    			if($db->loadResult()){
    				$sql= "UPDATE #__sm_generalshipping_products SET weight='$weight' WHERE product_id=$row->id";
    				$db->setQuery($sql);
    				if (!$db->query()) {
    					JError::raiseError(500, $db->getErrorMsg() );
    				}
    			}else{
    				$sql= "INSERT INTO #__sm_generalshipping_products (product_id,weight) VALUES('$row->id', '$weight')";
    				$db->setQuery($sql);
    				if (!$db->query()) {
    					JError::raiseError(500, $db->getErrorMsg() );
    				}
    			}
    		}else{
    			$sql="SELECT COUNT(*) FROM #__sm_generalshipping_products WHERE product_id=$row->id";
    			$db->setQuery($sql);
    			if($db->loadResult()){
    				$sql = "DELETE FROM #__sm_generalshipping_products WHERE product_id=$row->id";
    				$$db->setQuery($sql);
    				if(!$db->query()){
    					JError::raiseError(500, $db->getErrorMsg());
    				}
    			}
    			$mainframe->enqueueMessage(JText::_('SM_GS_NO_VALUE'),'notice');
    		}
    	}
    
    	/**
    	 * pass it the current cart it calculates the available options and returns these options as a array of strings
    	 * each option returned (In the array) must follow these rules
    	 * [0] A select tag with a name of 'shipping' and a value of 'plugin_id||rate_id||carrier_name||rate_price||cart_total_inc_rate'
    	 * [1] the shipping carrier name
    	 * [2] the shipping rate name
    	 * [3] the shipping cost
    	 * @param $cart The current cart
    	 */
    	function calculateShipCost($country,$postcode){
    		$cart = new ShoppingMatters_Cart();
    		$db = JFactory::getDBO();
    		$shippingOptions=array();
    		$totalWeight=0;
    		
    		/*
    		 * logic for options takes place here.
    		 */
    		
    		//calculate total weight
    		foreach($cart->cart_items as $ci){
    			$sql = "SELECT weight as weight FROM #__sm_generalshipping_products WHERE product_id=$ci->id";
    			$db->setQuery($sql);
    			$totalWeight += floatval($db->loadResult())*floatval($ci->quantity);
    		}
    		
    		//get tax rate
    		global $config;
    		$tax = $config->get('tax_amt');
    		
    		$tax=str_replace("%", "", $tax);
    		if ($tax>1) {
    			$tax=$tax/100;
    			$tax=$tax+1;
    		}
    		//calculate available rates based on weight, country and postcode.
    		$sql = "	SELECT c.id AS rate_id, c.name AS rate_name, c.cost+c.packing_fee AS cost, c.tax AS tax, car.name AS carrier_name
    					FROM `#__sm_generalshipping_rates` AS c
    					JOIN `#__sm_generalshipping_ratecountry` AS rc ON c.id=rc.rate_id 
    					JOIN `#__sm_generalshipping_carriers` AS car ON c.carrier_id = car.id
    					WHERE country_id LIKE '$country' 
    					AND weight_start<=$totalWeight
    					AND weight_end>=$totalWeight
    					AND postcode_start<=$postcode
    					AND postcode_end>=$postcode
    					AND c.published =1
    					AND car.published =1";
    		$db->setQuery($sql);
    		$rows=$db->loadObjectList();
    		$plugin_id=$this->getShippingId();
    		foreach($rows as $row){
    
    			$money1 = ($row->tax?(float)$row->cost*$tax:(float)$row->cost);
    			$money = Builder::money($money1);
    			$total = Builder::money($cart->total+$money1);
    			$temp[0]="<input type='radio' name='shipping' value=\"$plugin_id||$row->rate_id||$row->carrier_name||$money||$total\" />";
    			$temp[1]=$row->carrier_name;
    			$temp[2]=$row->rate_name;
    			$temp[3]=$money;
    			$shippingOptions[]=$temp;
    		}
    		
    		return $shippingOptions;
    	}
    	
    	/** 
    	 * If a value is returned by this function, then it is displayed on the product 
    	 * view page as a shipping cost. 
    	 * Only really usefull as for fixed price shipping rates
    	 * 
    	 * @return the cost of the product to ship
    	 * @param $productid the id of the product
    	 */
    	function productShipCost($productid){
    
    		return false;
    	}
    	
    
    	/**
    	 * PluginEdit functon called when plugin is edited/configured from plugin section
    	 * This hook has all the plugin configurtion options
    	 *
    	 * Dont forget to pass the $cid (plugin Id) to this 
    	 *
    	 * There is no hook for plugin Edit Save so you have to save anything you do using this method
    	 */
    	function pluginEdit($cid){
    		global $config;
    		
    		//Toolbar options ;)
    		JToolBarHelper::title(JText::_("SM_PLUGIN_GS"),'SMplugins.png');
    		//JToolBarHelper::save();
    		
    		
    		$plugaction=JRequest::getCmd('plug_action');
    		//What you want to do?
    		switch(@$plugaction){
    			case 'country':
    				require_once(dirname(__FILE__).DS."task.country.php");
    				break;
    			case 'shipper':
    				require_once(dirname(__FILE__).DS."task.shipper.php");
    				break;
    			case 'rate':
    				require_once(dirname(__FILE__).DS."task.rate.php");
    				break;
    			default:
    				$link = "index.php?option=$config->option&section=$config->section";
    				JToolBarHelper::back('sm_back',$link);
    				//the Javascript below overrides the default tool bar button action
    				?>
    				<script type="text/javascript">
    				function submitbutton(task){
    					if(task=='cancel'){
    						document.adminForm.task.value=task;
    		
    					}else{
    						document.adminForm.plug_action.value=task;
    					}
    					submitform();
    				}
    				</script>
    				<div class='col width-100' id='cpanel'>
    					
    					<form name='adminForm' action='index.php' method='post'>
    						<div style="float:left;">
    							<div class="icon ">
    							<a title="<?php echo JText::_("SM_PLUGIN_GS_COUNTRY"); ?>" href="index.php?option=com_shoppingmatters&amp;section=<?php echo $config->section; ?>&amp;task=edit&amp;plug_action=country&amp;cid[]=<?php echo $cid ?>">
    								<img src="components/com_shoppingmatters/images/icons/icon-48-SM-GS-country.png" alt="<?php echo JText::_('SM_PLUGIN_GS_COUNTRY');?>" align="middle" name="image" border="0" />
    								<span style="display:block;padding-top:0px;width:108px;"><?php echo JText::_("SM_PLUGIN_GS_COUNTRY"); ?></span>
    							</a>
    							</div>
    						</div>
    						<div style="float:left;">
    							<div class="icon ">
    							<a title="<?php echo JText::_("SM_PLUGIN_GS_COUNTRY"); ?>" href="index.php?option=com_shoppingmatters&amp;section=<?php echo $config->section; ?>&amp;task=edit&amp;plug_action=shipper&amp;cid[]=<?php echo $cid ?>">
    								<img src="components/com_shoppingmatters/images/icons/icon-48-SM-GS-country.png" alt="<?php echo JText::_('SM_PLUGIN_GS_COUNTRY');?>" align="middle" name="image" border="0" />
    								<span style="display:block;padding-top:0px;width:108px;"><?php echo JText::_("SM_PLUGIN_GS_SHIPPER"); ?></span>
    							</a>
    							</div>
    						</div>
    						<div style="float:left;"> 
    							<div class="icon ">
    							<a title="<?php echo JText::_("SM_PLUGIN_GS_COUNTRY"); ?>" href="index.php?option=com_shoppingmatters&amp;section=<?php echo $config->section; ?>&amp;task=edit&amp;plug_action=rate&amp;cid[]=<?php echo $cid ?>">
    								<img src="components/com_shoppingmatters/images/icons/icon-48-SM-GS-country.png" alt="<?php echo JText::_('SM_PLUGIN_GS_COUNTRY');?>" align="middle" name="image" border="0" />
    								<span style="display:block;padding-top:0px;width:108px;"><?php echo JText::_("SM_PLUGIN_GS_RATE"); ?></span>
    							</a>
    							</div>
    						</div>							
    						
    						
    						
    						
    						<input type="hidden" name="option" value="<?php echo $config->option; ?>" />	
    						<input type="hidden" name="section" value="<?php echo $config->section; ?>" />
    						<input type="hidden" name="task" value="edit" />
    						<input type="hidden" name="plug_action" value="" />
    						<input type="hidden" name="cid[]" value="<?php echo $cid ?>" />
    						<?php echo JHTML::_( 'form.token' ); ?>
    					</form>
    					
    				</div>
    				<div style="clear:both"></div>
    				<?php 
    				break;
    		}
    	}
    	
    	/*
    	 * Non Hook Functions
    	 * 
    	 * Any other methods/functions you need can be here
    	 */
    	
    
    	/** 
    	 * This fucntion is called if not entry is found in the plugin table, i.e. it is not installed yet.
    	 * You should do your own check to make sure tables do not already exist etc
    	 * 
    	 * Anything that is required to setup this plugin should be performed here
    	 */
    	function install(){
    		
    		$db = JFactory::getDBO();
    		$sql = file_get_contents(dirname(__FILE__).DS."install.sql");
    		$db->setQuery($sql);
    		$db->queryBatch();
    		
    		
    	}
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •