Jump to content

fRAiLtY-

Members
  • Posts

    53
  • Joined

  • Last visited

Everything posted by fRAiLtY-

  1. Excuse my ignorance, and thanks for the response, however it's just a simple 1 page script. It's an internal project for our business that is never going to develop into a web app and isn't accessible to the world wide web. It's just a form, with 2 steps: Step 1, enter job number Step 2, enter consignment number and update onclick. An MVC approach for this seems a bit overkill, but please feel free to correct me. I just need to rework what I've done into a functioning 2 step form. There's no users or anything of the sort, it utilises a barcode scanner.
  2. Hi, I have written the below code and am trying to figure out the best way of making it into a 2 step form as currently it doesn't work as one. The 2 steps are as follows: 1) 1 text input with "find job" button, indicated by lines. 2) Once find job has been clicked it takes you to the results set where you have 2 options, to enter a number or tick a box. The resulting actions from clicking "Update" is still to be coded, but I've got a bit stuck where it comes to putting it into steps. Any help is appreciated. <?php /** * Despatcher * * @file index.php * @package Despatcher v1.0 (despatcher) * @category Core */ ini_set('error_reporting', E_ALL); ?> <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Despatcher®</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="css/normalize.min.css"> <link rel="stylesheet" href="css/main.css"> <script src="js/vendor/modernizr-2.6.2.min.js"></script> </head> <body> <div id="page"> <?php // Check for post if($_SERVER['REQUEST_METHOD'] === 'POST'){ // Set some variables for the server $host = "xxxxxxx"; $port = 'xxxx'; $dbname = "xxxx"; $db_username = "xxxx"; $db_password = "xxxxx"; $dsn = "sqlsrv:Server=$host,$port;Database=$dbname;"; // Connect $db = new PDO($dsn, $db_username, $db_password); // Step 2 if(!isset($_POST['update'])) { // Query try { $sql = 'SELECT * FROM MainJobDetails WHERE JobNo = ?'; $q = $db->prepare($sql); $q->execute(array($_POST['jobnumber'])); // Return results while($row = $q->fetch(PDO::FETCH_ASSOC)) { echo '<h2>Scan the barcode on the label or click "Local Delivery"</h2>'; echo '<form id="update" action="" method="post">'; echo '<table class="results"><tr><th>'; echo 'Customer'; echo '</th><th>'; echo 'Description'; echo '</th><th>'; echo 'Consignment #'; echo '</th><th>'; echo 'Local Delivery'; echo '</th></tr><tr><td>'; echo $row['InvoiceCustomerName']; echo '</td><td>'; echo $row['JobDesc']; echo '</td><td>'; echo '<input type="text" name="consignment" id="consignment"/>'; echo '</td><td>'; echo '<input type="checkbox" name="local" id="local"/>'; echo '</td></tr></table><br />'; echo '<button type="submit" id="updatebutton" class="blue button"/>Update details</button></form>'; return; } } catch(PDOException $e) { echo $e->getMessage(); } } elseif(isset($_POST['update'])) { "Thanks"; } } ?> <!--[if lt IE 7]> <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p> <![endif]--> <p>Scan the job bag</p> <form id="jobnumber" method="post" action=""> <input type="text" name="jobnumber" id="jobnumber"/><br /> <div id="go-button"> <button type="submit" class="blue button"/>Find Job</button> </div> </form> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script> <script src="js/plugins.js"></script> <script src="js/main.js"></script> </body> </html>
  3. Currently I just pdo_mysql and the standard MSSQL modules installed. I can connect using mssql_* functions but it doesn't handle prepared statements I think. I tried PDO_DBLIB but this hasn't been developed since 2005 and doesn't work with my versions of software due to it's age.
  4. Hi all, Got some code which works, it's been extended then extended again over the past few months, and I'm just wondering if there's a tidier or more efficient way of putting altogether perhaps in less functions maybe or anything really. If anyone can provide some advise or feel free to move it around that would be a massive help. I like things to be neat and tidy and this certainly isn't. public function getMatrixData($requiredAttributeIds = null, $product = null, $stock) { Varien_Profiler::start('CONFIGURABLE:' . __METHOD__); $this->_usedProducts = '_cache_instance_products'; if ($this->getProduct($product)->hasData($this->_usedProducts)) { if (is_null($requiredAttributeIds) and is_null($this->getProduct($product)->getData($this->_configurableAttributes))) { $this->getConfigurableAttributes($product); Varien_Profiler::stop('CONFIGURABLE:' . __METHOD__); return $this->getProduct($product)->getData($this->_usedProducts); } $usedProducts = array(); $collection = $this->getUsedProductCollection($product)->addAttributeToSelect('*')->addFieldToFilter('name', array( 'like' => '%' . $stock . '%' ))->addAttributetoSort('size', 'DESC'); if (is_array($requiredAttributeIds)) { foreach ($requiredAttributeIds as $attributeId) { $attribute = $this->getAttributeById($attributeId, $product); if (!is_null($attribute)) $collection->addAttributeToFilter($attribute->getAttributeCode(), array( 'notnull' => 1 )); } } foreach ($collection as $item) { $usedProducts[] = $item; } $this->getProduct($product)->setData($this->_usedProducts, $usedProducts); } Varien_Profiler::stop('CONFIGURABLE:' . __METHOD__); return $this->getProduct($product)->getData($this->_usedProducts); } public function getAltMatrixData($requiredAttributeIds = null, $product = null, $stock) { Varien_Profiler::start('CONFIGURABLE:' . __METHOD__); $this->_usedProducts = '_cache_instance_products'; if ($this->getProduct($product)->hasData($this->_usedProducts)) { if (is_null($requiredAttributeIds) and is_null($this->getProduct($product)->getData($this->_configurableAttributes))) { $this->getConfigurableAttributes($product); Varien_Profiler::stop('CONFIGURABLE:' . __METHOD__); return $this->getProduct($product)->getData($this->_usedProducts); } $usedProducts = array(); $collection = $this->getUsedProductCollection($product)->addAttributeToSelect('*')->addFieldToFilter('name', array( 'like' => '%' . $stock . '%' )); if (is_array($requiredAttributeIds)) { foreach ($requiredAttributeIds as $attributeId) { $attribute = $this->getAttributeById($attributeId, $product); if (!is_null($attribute)) $collection->addAttributeToFilter($attribute->getAttributeCode(), array( 'notnull' => 1 )); } } foreach ($collection as $item) { $usedProducts[] = $item; } $this->getProduct($product)->setData($this->_usedProducts, $usedProducts); } Varien_Profiler::stop('CONFIGURABLE:' . __METHOD__); return $this->getProduct($product)->getData($this->_usedProducts); } public function getTable($product = false, $stock) { if (!$product) return false; $childProducts = $this->getMatrixData(null, $product, $stock); $x = array(); $r = ''; $sizes = array(); foreach ($childProducts as $children) { $size = $children->getAttributeText('size'); $x[$children->getAttributeText('quantity')][$size] = array( 'id' => $children->getId(), 'price' => number_format($children->getPrice(), '2'), 'name' => $children->getName() ); if (!in_array($size, $sizes)) { $sizes[] = $size; } } ksort($x); $r .= '<table id="' . strtolower(str_replace(' ', '-', $stock)) . '" class="matrix"><tr><th></th>'; foreach ($sizes as $size) { $r .= '<th>' . $size . '</th>'; } $r .= '</tr>'; foreach ($x as $quantity => $data) { $i = 1; $r .= '<tr><th id=' . $quantity . '>' . $quantity . '</th>'; foreach ($sizes as $size) { if (isset($data[$size])) { $item = $data[$size]; $r .= '<td id=' . $quantity . ' class="col' . $i++ . '"><a href="/checkout/cart/add?product=' . $item['id'] . '" title="Add ' . $item['name'] . ' to basket">£' . $item['price'] . '</a></td>'; } else { $r .= '<td id=' . $quantity . ' class="col' . $i++ . '">-</td>'; } } $r .= '</tr>'; } $r .= '</table>'; $r .= '<p class="note"><strong>Note:</strong> Prices in this table do not include additional options as specified above!</p>'; return $r; } public function getAltTable($product = false, $stock) { if (!$product) return false; $childProducts = $this->getMatrixData(null, $product, $stock); $x = array(); $r = ''; $sizes = array(); foreach ($childProducts as $children) { $size = $children->getAttributeText('size'); $x[$children->getAttributeText('quantity')][$size] = array( 'id' => $children->getId(), 'price' => number_format($children->getPrice(), '2'), 'name' => $children->getName() ); if (!in_array($size, $sizes)) { $sizes[] = $size; } } function bannerSizeSort($a,$B) { $pattern = '/(\d+(\.\d+)?)ft x (\d+(\.\d+)?)ft/'; if (preg_match($pattern, $a, $n1) && preg_match($pattern, $b, $n2)) { if ($n1[1] == $n2[1] && $n1[3] == $n2[3]) return 0; else if ($n1[1] > $n2[1] || ($n1[1] == $n2[1] && $n1[3] > $n2[3])) return 1; else return -1; } return 0; } usort($sizes, 'bannerSizeSort'); $r .= '<table id="banner" class="matrix"><tr><th></th>'; foreach ($x as $quantity => $data) { $r .= '<th id=' . $quantity . '>Each</th>'; } $r .= '</tr>'; foreach ($sizes as $size) { $i = 1; $r .= '<tr><th>' . $size . '</th>'; if (isset($data[$size])) { $item = $data[$size]; $r .= '<td id=' . str_replace(array(".", ","," "), "", $size) . ' class="col' . $i++ . '"><a href="/checkout/cart/add?product=' . $item['id'] . '" title="Add ' . $item['name'] . ' to basket">£' . $item['price'] . '</a></td>'; } else { $r .= '<td id=' . str_replace(array(".", ","," "), "", $size) . ' class="col' . $i++ . '">-</td>'; } $r .= '</tr>'; } $r .= '</tr>'; $r .= '</table>'; $r .= '<p class="note"><strong>Note:</strong> Prices in this table do not include additional options as specified above!</p>'; return $r; } public function getAlt2Table($product = false, $stock) { if (!$product) return false; $childProducts = $this->getAltMatrixData(null, $product, $stock); $x = array(); $r = ''; $sizes = array(); foreach ($childProducts as $children) { $size = $children->getAttributeText('size'); $x[$children->getAttributeText('quantity')][$size] = array( 'id' => $children->getId(), 'price' => number_format($children->getPrice(), '2'), 'name' => $children->getName() ); if (!in_array($size, $sizes)) { $sizes[] = $size; } } natsort($sizes); $r .= '<table id="label" class="matrix"><tr><th></th>'; ksort($x); foreach ($x as $quantity => $data) { $r .= '<th id=' . $quantity . '>' . $quantity . '</th>'; } $r .= '</tr>'; foreach ($sizes as $size) { $i = 1; $r .= '<tr><th>' . $size . '</th>'; foreach ($x as $quantity => $data) { $item = $data[$size]; $r .= '<td id=' . str_replace(" ","",$size) . ' class="col' . $i++ . '"><a href="/checkout/cart/add?product=' . $item['id'] . '" title="Add ' . $item['name'] . ' to basket">£' . $item['price'] . '</a></td>'; } } $r .= '</tr>'; $r .= '</table>'; $r .= '<p class="note"><strong>Note:</strong> Prices in this table do not include additional options as specified above!</p>'; return $r; }
  5. From what I can see, the only driver that works with PHP on Linux is this: http://www.microsoft.com/en-us/download/details.aspx?id=28160 Does that seem right? Then hopefully I can take advantage of PDO to better prepare the queries. I'll look at some of the other suggestions too. Cheers!
  6. Hi all, Thanks for the responses, I should have provided more context. Ultimately, it's an imperfect solution to an unavoidable problem. Our Linux web server running Magento has to link to our in-house MIS server running MSSQL. There is nothing there that can change, hence the mssql_* usage. Initially the checkCustomer method was very small, now it's grown significantly. It hooks into standard Magento event observers and is triggered when the "Place Order" is pressed, it works in the following way: 1) Gets details about the current order, and the customer involved. 2) Connects to the external MSSQL database, uses the name and first line of the address to check for existance in the database. If a match is found, then fine. 3) If not, it takes the first letters of both the first and surname, adds 0's to make it up to 6 characters long and iterates over until no match is found in the database, then adds the customer with those details. Our customer naming convention is this way, i.e Joe Bloggs becomes JB00001 unless that exists, then increment up until it doesn't. If it adds a customer I log it and e-mail myself. 4) It then iterates over the custom options selected on the product, looks for additional days (Our options follow this convention: Selected option +1day) so it plucks the integer out for each instance of the option, adds them up, then adds them to a pre-determined number, then adds that to the days function ending up with a lead-time. As I write it, it sounds confusing, but it's actually quite simple! Cheers.
  7. Hi guys, I've managed to cobble together a PHP script which works perfectly, there are no faults or errors and it does exactly as intended. However I asked for some code critique and was advised that I could chop it up into smaller methods rather than one monster method to make it better or more efficient, as it's been added to quite regularly over the last few weeks, now it's finished I want to tidy it up. Can anyone provide some amendments or advice on how to make it a bit more streamline or tidy by perhaps creating additional methods with what I have or similar. Many thanks <?php class Tharstern_TharCustomer_Model_Observer { protected function despatchDate($startdate, $businessdays, $dateformat = 'c') { //vars $i = 1; $holidays = array("02-01-2012", "06-04-2012", "09-04-2012", "07-05-2012", "04-06-2012", "05-06-2012", "28-06-2012", "27-08-2012", "25-12-2012", "26-12-2012"); //start date depends on time >11pm +1day if(date('H') >= 11) { $dayx = strtotime($startdate. '+1 day'); } else $dayx = strtotime($startdate); $businessdays = ceil($businessdays); //loop over get preliminary date while($i < $businessdays) { $day = date('N',$dayx); $date = date('d-m-Y',$dayx); if($day < 6 && !in_array($date,$holidays)) $i++; $dayx = strtotime($date.' +1 day'); } //if preliminary date is weekend/bank holiday iterate over until neither $day = date('N',$dayx); $date = date('d-m-Y',$dayx); while($day >= 6 || in_array($date,$holidays)) { $dayx = strtotime($date.' +1 day'); $day = date('N',$dayx); $date = date('d-m-Y',$dayx); } //return final date for despatch return date($dateformat, $dayx); } public function checkCustomer($observer) { // connect to Tharstern $cnx = mssql_connect('xxxxxxx'); mssql_select_db('TharData'); // get customers billing name and email address $session = Mage::getSingleton('customer/session'); $customer = $session->getCustomer(); // get details $order = $observer->getEvent()->getOrder(); $orderId = $observer->getEvent()->getOrder()->getIncrementId(); $invAdd = $observer->getEvent()->getOrder()->getBillingAddress(); $productsCollection = $observer->getEvent()->getOrder()->getItemsCollection(); foreach($productsCollection as $_products) { if ($allOptions = $_products->getData('product_options')) { $options = unserialize($allOptions); if (isset($options['options'])) { $optionDays = 0; foreach ($options['options'] as $optionValues) { if ($optionValues['value']) { $_printValue = isset($optionValues['print_value']) ? $optionValues['print_value'] : strip_tags($optionValues['value']); $values = explode(', ', $_printValue); foreach ($values as $value) { preg_match('/(\d+)/', $value, $option); if(!isset($option[0]) || $option[0] == 24) { $extraDays = 0; } else $extraDays = $option[0]; $optionDays += $extraDays; } } } } } } $items = $order->getAllVisibleItems(); foreach ($items as $item) { $product = Mage::getModel('catalog/product')->load($item->getProductId()); $turnaround = $product->getAttributeText('turnaround'); preg_match('/(\d+)/', $turnaround, $base); if(!isset($base[0]) || $base[0] == 24) { $baseDays = 0; } else $baseDays = $base[0]; $finalDespatchDate = $this->despatchDate(date('d-m-Y'), $optionDays + $baseDays); } // check if a company is specified otherwise use the billing name $identifier = $customer->getName(); //if(isset($customer->getCompany())){ //$identifier = $customer->getCompany(); //} // query database and check for customers existence $check = mssql_query("SELECT Customers.Code, Customers.Name, Customers.Address, Customers.Town, Customers.County, Customers.Postcode, CustomerContacts.Email, Customers.Ref3 FROM Customers INNER JOIN CustomerContacts ON Customers.Name=CustomerContacts.Name WHERE Customers.Name ='".$identifier."' AND CustomerContacts.Email ='".$customer->getEmail()."' AND Ref3 = 'Advantage' AND Address = '".$invAdd->getStreet(1)."' AND Postcode = '".$invAdd->getPostcode()."' GROUP BY Customers.Code, Customers.Name, Customers.Address, Customers.Town, Customers.County, Customers.Postcode, CustomerContacts.Email, Customers.Ref3"); // check results if(mssql_num_rows($check) == 1) { // echo customer code $row = mssql_fetch_array($check); $tharCode = $row['Code']; // Mage_Core db connection to update order column if applicable $write = Mage::getSingleton('core/resource')->getConnection('core_write'); $write->query("UPDATE sales_order SET customer_tharstern_code = '".$tharCode."', final_despatch_date = '".$finalDespatchDate."' WHERE increment_id = '".$orderId."' LIMIT 1"); if(!$check) { error_log("Error checking Tharstern for customer",1,"xxxxxxx"); } } elseif(mssql_num_rows($check) == 0) { // get initials and uppercase them if necessary $initials = ''; foreach(explode(' ', $customer->getName()) as $word) { $initials .= strtoupper($word[0]); } // set integer and string values to bendart 6-digit convention $codeNum = 0; $codeStr = $initials.'0001'; // iterate through results until no match is found do { $codeNum++; $codeStr = $initials . str_pad($codeNum, 4, '0', STR_PAD_LEFT); $query = mssql_query("SELECT * FROM Customers WHERE Code = '".$codeStr."'"); } while(mssql_num_rows($query) == 1); // Mage_Core db connection to update order column with new customers code $write = Mage::getSingleton('core/resource')->getConnection('core_write'); $write->query("UPDATE sales_order SET customer_tharstern_code = '".$tharCode."', final_despatch_date = '".$finalDespatchDate."' WHERE increment_id = '".$orderId."' LIMIT 1"); // add customer to Tharstern for processing $addCustomer = mssql_query("INSERT INTO Customers(Code,Name,Address,Town,County,Postcode,Ref1,Ref2,Ref3,PostingAccount) VALUES ('".$codeStr."','".$customer->getName()."','".$invAdd->getStreet(1)."','".$invAdd->getCity()."','".$invAdd->getRegion()."','".$invAdd->getPostcode()."','Web Sales','Retail','Advantage','CASHCU'); INSERT INTO CustomerContacts(ParentCustomer,Name,Email,EmailName,PrimaryContact,GMDisabled) VALUES ('".$codeStr."','".$customer->getName()."','".$customer->getEmail()."','".$customer->getName()." (".$customer->getEmail().")','1','1')"); // check result and e-mail if(!$addCustomer) { error_log("Error adding customer to Tharstern",1,"tom@bendart.co.uk"); } else { // write new customer details to csv for logging purposes. $csv = $_SERVER['DOCUMENT_ROOT']."/var/log/newcustomersadded.csv"; $handle = fopen($csv, 'a'); $data = "\n".date ('Y-m-d H:i:s').",".$orderId.",".$codeStr.",".$customer->getName(); fwrite($handle, $data); fclose($handle); mail('xxxx,'New Customer', 'New Customer Created: '.$codeStr); } } } }
  8. Hi, I have x amount of tables, and a drop-down with x values in. The tables are auto-generated based on the values in the drop-downs, so if there's 4 drop-down selections there's 4 tables. What I want to do is show/hide each table depending on the selection, so if drop-down selection 1 is selected, show table 1 and so on. Here's an example page. There are 4 seperate drop-down entities but I'm only interested in the 3rd one, select paper. This is #attribute129. Once that drop-down is changed to another value I want my tables below to reflect that. Example: http://dev4.printpartnerships.com/flyer-printing Top table is 300gsm Gloss, bottom table is 400gsm Matt. When those options are selected in the drop-down I want the corresponding table only to show. Here's what I have so far but it just hides both of them <script type="text/javascript"> jQuery.noConflict(); jQuery(document).ready(function(){ jQuery('#attribute129').change(function(){ jQuery('#matrix-container').hide().eq($(this).val()).show() }); }); </script> Hopefully someone can figure it out? Cheers.
  9. Hi guys, I've got a situation where, for example, file1.php contains a method call and the echo'ing of a table. file2.php contains the method and is what processes and ultimately produces the data and sends it back to file1.php for formatting. I need to mix this up a bit by adding the table echo's to file2.php but retain the "call" in file1.php. Here's my 2 files so to speak currently: File1.php - the table view and call <?php $childProducts = Mage::getModel('catalog/product_type_configurable')->getMatrix(null, $_product); $x = array(); foreach ($childProducts as $children) { $x[$children->getAttributeText('quantity')][$children->getAttributeText('size')] = array('id'=>$children->getId(), 'price'=>number_format($children->getPrice(),'2'), 'name'=>$children->getName()); } ksort( $x ); echo '<table class="matrix"><tr><th></th>'; foreach( array_keys(current($x)) as $size ) { echo '<th>'.$size.'</th>'; } echo '</tr>'; foreach( $x as $quantity => $data ) { echo '<tr><th>'.$quantity.'</th>'; foreach( $data as $item ) { echo '<td><a href="/checkout/cart/add?product='.$item[id].'" title="Add '.$item[name].' to basket">£'.$item[price].'</a></td>'; } echo '</tr>'; } echo '</table>'; ?> File2.php - the method that processes <?php class OrganicInternet_SimpleConfigurableProducts_Catalog_Model_Product_Type_Configurable extends Mage_Catalog_Model_Product_Type_Configurable { /** * Retrieve array of "subproducts" for 300gsm flyers based on standard getUsedProducts * * @param array * @param Mage_Catalog_Model_Product $product * @return array */ public function getMatrix($requiredAttributeIds = null, $product = null) { Varien_Profiler::start('CONFIGURABLE:'.__METHOD__); if ($this->getProduct($product)->hasData($this->_usedProducts)) { if (is_null($requiredAttributeIds) and is_null($this->getProduct($product)->getData($this->_configurableAttributes))) { // If used products load before attributes, we will load attributes. $this->getConfigurableAttributes($product); // After attributes loading products loaded too. Varien_Profiler::stop('CONFIGURABLE:'.__METHOD__); return $this->getProduct($product)->getData($this->_usedProducts); } $usedProducts = array(); $collection = $this->getUsedProductCollection($product) ->addAttributeToSelect('*') ->addFieldToFilter('name', array('like' => '%300gsm Flyers%')); //->groupByAttribute('size'); $x = $collection->getSize(); // ->addFilterByRequiredOptions(); if (is_array($requiredAttributeIds)) { foreach ($requiredAttributeIds as $attributeId) { $attribute = $this->getAttributeById($attributeId, $product); if (!is_null($attribute)) $collection->addAttributeToFilter($attribute->getAttributeCode(), array('notnull'=>1)); } } foreach ($collection as $item) { $usedProducts[] = $item; } $this->getProduct($product)->setData($this->_usedProducts, $usedProducts); } Varien_Profiler::stop('CONFIGURABLE:'.__METHOD__); return $this->getProduct($product)->getData($this->_usedProducts); } } ?> I need the tabular part, from x = array downwards from File1.php to be part of File2.php, however I need to retain the $childProducts = Mage.... part in File1.php and pass any necessary data through to the method, however which ever way I try it I end up with errors about undefined methods etc. Visually I will see no difference on screen as it should still create the same table in the same way, however I'm going to be using AJAX to produce a new table on select so need the table as part of the method. Any help is greatly appreciated as I keep breaking it! Cheers.
  10. Ah OK gotcha. One last thing, I'm working on a Magento platform which uses prototype. Is prototype "just another" library like jQuery or mootools, and as such a good option to try and work within this or is it not the case? I've read that libraries can conflict with each other and have used jQuery noConflict in the past to great effect, but am wondering if I have the choice to start with it might be be an idea to try and avoid the conflicts? Cheers
  11. So if I read what you're saying is right, and referring back to my original post, if I want to pass a different value to PHP for data retrieval it's AJAX I'll need, not jQuery? My table is prepoluated with "default" values, however on select of a drop-down will pass a value to a PHP to potentially change the data in that table. Cheers.
  12. Hi thorpe, Thanks for the response. So just to confirm, going on my description jQuery is the solution, not AJAX? I find the 2 a bit confusing that's all as to their differences! Cheers.
  13. Hi guys, Here's my dev page: http://dev4.printpartnerships.com/flyer-printing Thanks to the awesome help I got in the PHP part I've got that table displaying correctly underneath the drop-downs, it's dynamically created. As you can see, I have 4 drop-down boxes. The third one is where you choose the paper, although you can't operate it until you've filled the other 2 out. Once you select an option in there, for example 300gsm stock, I need the table to change. Now, currently I use a function called getFlyers300gsm in my PHP so rather than having a function for every paper stock I was hoping I could have a function called getMatrix() or similar in PHP that passes a variable to the function depending on the value of that dropdown, thus manipulating the table and reloading it. So to summarise, table loads a default set of figures on page load, drop-down box is changed, value is passed to PHP and table is reloaded. I'm not sure whether this is jQuery or Javascript or AJAX so forgive me if this post needs to be moved, I have little experience in JS. The PHP part of the equation I believe I can handle, it's just this part stumps me. If anyone can give me some help I'd greatly appreciate it. Cheers.
  14. Thanks xyph all done and I understand how to feed more info into the array now for use later on. Between you and Russell you've saved me hours, so thanks very much! I'll mark this as solved now!
  15. Hi xyph, If I do this: foreach ($childProducts as $children) { $size = $children->getAttributeText('size'); $quantity = $children->getAttributeText('quantity'); $price = "£".number_format($children->getPrice(),'2'); $x[$quantity][$size] = $price; echo $children->getId(); } It echo's all the ID's of the children as expected. How do I move this down into the lower foreach where the price is echo'd? Cheers.
  16. Hi xyph, Many thanks once again, awesome. One last thing, whilst in the .$price. cell can I get the ID of that child item. Reason is I want to add the product to the cart if they click on the price but I need the child ID to do it. I've tried $children->getId(), $price->getId() but get non-object errors, what's the var for accessing the child in that loop? getId() get's the ID and I can make it get the ID of the main parent product, but can't access the child, even though it's the child price displayed. Cheers
  17. Hi xyph, That's awesome mate, works great. Code's even shorter too! Only thing that didn't work was your variables assigned to $children[0] so I put mine back on, $children->getPrice() and it works a treat! Thanks guys!
  18. Sorry it's because I'm working on it. Works fine now. Cheers.
  19. Thanks Russel, He's really helped me but I'm a bit stuck now! I've made a mistake and need to swap my axis but I don't think it's as simple as I make it out to be. Here is my code with lots of help from Russell: <?php // get stock to determine matrix $childProducts = Mage::getModel('catalog/product_type_configurable')->getFlyers300gsm(null, $_product); // set array $x = array(); // loop children and set vars foreach ($childProducts as $children) { $size = $children->getAttributeText('size'); $quantity = $children->getAttributeText('quantity'); $price = "£".number_format($children->getPrice(),'2'); $x[] = array($size,$quantity,$price); } $rows = array(); // associative array, key index will be A7 etc.. $rows[0] = array(); // initial rows would be column names, so the key will just be 0 foreach ($x as $column) { if (!in_array($column[1],$rows[0])) { $rows[0][] = $column[1]; // append the column name } } // sort the column titles now sort($rows[0],SORT_NUMERIC); // then get count of this new column title array $count = count($rows[0]); // now just loop through the $x array, and fill in the place values foreach ($x as $row) { $rowTtl = $row[0]; $rowQty = $row[1]; $rowVal = $row[2]; if (!isset($rows[$rowTtl])) $rows[$rowTtl] = array_pad(array(),$count,0); $rows[$rowTtl][array_search($rowQty,$rows[0])] = $rowVal; } // display table ?> <table class="matrix"> <?php // set header rows and padder cell $top = array_shift($rows); echo "<th></th>"; // display header row x-axis foreach ($top as $topRow) { echo "<th>{$topRow}</th>"; } // set header columns and populate foreach ($rows as $rowName => $columns) { echo "<tr><th>{$rowName}</th>"; foreach ($columns as $cell) { echo "<td>{$cell}</td>"; } echo "</tr>"; } ?> </table> And here's the URL: http://dev4.printpartnerships.com/flyer-printing You can see the tables too wide, given we're likely to add more quantities in the future I need some scalability so want to swap the x and y axis round, but can't figure it out. Can anyone help please? I'm so close now! Cheers.
  20. Russell, That's awesome, I've got the data in a number of different ways. I've added you to MSN as per your signature, can you pop online and I'll show you what I've got?! I think I can cut down on some code and produce a cleaner script. Here's my function that gets the data: <?php // get 300gsm flyers only $childProducts = Mage::getModel('catalog/product_type_configurable')->getFlyers300gsm(null, $_product); foreach ($childProducts as $_300gsm) { $size = $_300gsm->getAttributeText('size'); $quantity = $_300gsm->getAttributeText('quantity'); $price = $_300gsm->getPrice(); } ?> The foreach loop iterates through all the 300gsm flyers, I've assigned variables to the crucial parts I need for the matrix, would this cut down on what's necessary in your code Russell making it a bit cleaner? Perhaps I'm trying to format it wrong. Cheers.
  21. CKPD: You're spot on, yes. That's exactly what I want to do. xyth: Unfortunately not, I'm working with Magento so it is what is. I can probably mix and match the data a bit to get it how you want it, I understand it's probably not ideal. Basically I have one parent entity which has many child entities. Each of these children has 3 attributes assigned to them; size, quantity and price. I have "got" all these children and listed their attributes so I'm left with a list as of my last post. I now need to convert that into a matrix table. Any ideas? Cheers.
  22. Hi, It's taken from a database and in it's unchanged form looks like this: A7,25,25.0000 A7,50,25.3000 A7,100,26.2000 A7,250,29.2000 A7,500,37.2000 A7,1000,57.2000 A7,2500,63.2000 A7,5000,70.7500 A7,10000,95.2800 A7,15000,138.8000 A7,20000,175.8500 A7,25000,223.5000 In the format size,quantity,price. How can I convert this into the array xyth mentioned or even directly into a matrix. I've got to sort of group on the size and show the quantity->price values somehow?
  23. Hi xyph, I can get the information in a number of ways, what way is preferable to perform what I need? Cheers.
  24. Sorry xyph. For example, I have 10 sizes: CC, A7, A6, A5, A4, A3, SJ, DL, CD, WB And 10 Quantities: 25, 50 100, 250, 500, 1000, 2500, 5000, 10000 Each product has these attributes assigned to them, a size and a quantity and as such has a price. For example 25 A7's are £25. Therefore, I would have quantities along the top and sizes down the side in a grid style as above. Does this help?
  25. Unfortunately the small piece of wrong and not-working code I have is on my work machine local server. It's the logic and the procedure I can't really grasp, I'm using Magento but that's largely irrelevant as I can't get my head round the methodology in producing such a table?? Cheers.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.