예제 #1
0
 function mailorder($orderid = null)
 {
     if (!$orderid) {
         return;
     }
     global $mainframe;
     $cfg = new sc_configuration();
     $tsep = $cfg->get('thousand_sep');
     $dsep = $cfg->get('decimal_sep');
     $decs = $cfg->get('decimals');
     $currency = $cfg->get('currency');
     $curralign = $cfg->get('curralign');
     $dateformat = $cfg->get('dateformat');
     $timeformat = $cfg->get('timeformat');
     $mode = $cfg->get("emailhtml");
     $usecontentasemail = $cfg->get("usecidasemail");
     // create html orderheader
     $db =& JFactory::getDBO();
     $query = "select #__sc_orders.*, #__sc_orders.total as gtotal from #__sc_orders where #__sc_orders.id='{$orderid}' ";
     $db->setQuery($query);
     $header = $db->loadObject();
     echo $db->getErrorMsg();
     $hhtml = "";
     // header html
     $hhtml .= "\n<br />" . JText::_('SC_ORDER');
     $hhtml .= "\n<br />" . date("{$dateformat} {$timeformat}", $header->orderdt);
     $hhtml .= "\n<br />{$header->name}";
     $hhtml .= "\n<br />{$header->email}";
     $hhtml .= "\n<br />" . nl2br($header->address);
     $hhtml .= "\n<br />{$header->codepostal}";
     $hhtml .= "\n<br />{$header->city}";
     $hhtml .= "\n<br />{$header->telephone}";
     $hhtml .= "\n<br />{$orderid}";
     // now get the tax rate based on the shipping region in the header
     $taxes = new taxes();
     $taxrate = $taxes->getTax($header->shipRegion);
     // create html order details block
     $odetails = new orderdetail();
     $detailslist = $odetails->getDetailsByOrderId($orderid);
     $dhtml = "<p>";
     // detail html
     $dhtml .= "<table width='100%' border='1'>\n";
     $dhtml .= "<tr><th>" . JText::_('SC_CODE') . "</th><th>" . JText::_('SC_DESCRIPTION') . "</th><th>" . JText::_('SC_PRICE_PER_UNIT') . "</th><th>" . JText::_('SC_QUANTITY') . "</th><th>" . JText::_('SC_TOTAL') . "</th></tr>";
     foreach ($detailslist as $detail) {
         $dhtml .= "<tr><td>{$detail->prodcode}</td>\n";
         $dhtml .= "<td>{$detail->shorttext} - {$detail->option}</td>\n";
         $dhtml .= "<td>" . number_format($detail->unitprice, $decs, $dsep, $tsep) . "</td>\n";
         $dhtml .= "<td>{$detail->qty}</td>\n";
         $dhtml .= "<td><strong>" . number_format($detail->qty * $detail->unitprice, $decs, $dsep, $tsep) . "</strong></td>\n";
     }
     if ($taxrate > 0) {
         $dhtml .= "<tr><td colspan='2'><td colspan='2'>" . JText::_('SC_TAX') . "</td><td>" . number_format($header->tax, $decs, $dsep, $tsep) . "</td>";
     }
     $ship['enabled'] = $cfg->get('shippingenabled');
     if ($ship['enabled']) {
         $dhtml .= "<tr><td colspan='2'><td colspan='2'>" . JText::_('SC_SHIPPING_REGION') . "</td>";
         $dhtml .= "<td colspan='1'>" . $header->shipRegion . "</td></tr>";
         $dhtml .= "<tr><td colspan='2'><td colspan='2'>" . JText::_('SC_SHIPPING_COST') . "</td>";
         $dhtml .= "<td colspan='3'>" . $header->shipCost . "</td></tr>";
     }
     $dhtml .= "<tr><td colspan='2'><td colspan='2'>" . JText::_('SC_TOTAL') . "</td>";
     $dhtml .= "<td>" . number_format($header->gtotal + $header->tax + $header->shipCost, $decs, $dsep, $tsep) . "</td></tr>\n";
     $dhtml .= "</table>\n";
     $dhtml .= "</p>";
     $emailsubject = JText::_('SC_ORDER') . " " . JText::_('SC_FOR') . " " . number_format($header->gtotal, $decs, $dsep, $tsep) . " " . JText::_('SC_FROM') . " " . $header->name;
     if ($usecontentasemail == 1) {
         $contentemail = $cfg->get("emailcid");
         $query = "select introtext from #__content where id = '{$contentemail}'";
         $db->setQuery($query);
         $emailcontent = $db->loadResult();
         $fields = new fields();
         $fieldslist = $fields->getPublishedFields();
         // the custom fields defined for this system
         $thefields = unserialize($header->customfields);
         // the fields filled by customers
         foreach ($fieldslist as $key => $customfield) {
             $emailcontent = str_replace("#" . $customfield->name . "#", $thefields[$customfield->name], $emailcontent);
             // replace custom tags with the field names
         }
         $emailcontent = str_replace("#orderheading#", $hhtml, $emailcontent);
         // replace the headertag with header html
         $emailcontent = str_replace("#orderdetails#", $dhtml, $emailcontent);
         // replace detail tag with detail html
         $emailcontent = str_replace("#orderid#", $orderid, $emailcontent);
         // replace orderid tag with the order ID
         $emailbody = $emailcontent;
     } else {
         $emailbody = $hhtml . $dhtml;
         // simply add one after the other without processing anything else
     }
     $mailengine = $cfg->get("mailengine");
     if ($mailengine == "alternative") {
         // some servers do NOT like to send to an array of addresses
         // so as an alternative way we send the emails one by one
         $from = $mainframe->getCfg('mailfrom');
         $fromname = $mainframe->getCfg('fromname');
         $recipient = trim($header->email);
         // customer email
         $subject = stripslashes($emailsubject);
         $body = $emailbody;
         $mode = $mode;
         // send to customer
         $rs = JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
         // now send the eventual copies
         $emailcopies = $cfg->get('email_copies');
         // the complete address list is already trimmed
         $aemailcopies = explode("\r\n", $emailcopies);
         foreach ($aemailcopies as $key => $emailaddress) {
             $copyrecipient = trim($emailaddress);
             // trim each address from any \n ...
             $rs = JUtility::sendMail($from, $fromname, $copyrecipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
         }
     } else {
         $mailer =& JFactory::getMailer();
         // Build e-mail message format
         $mailer->setSender(array($mainframe->getCfg('mailfrom'), $mainframe->getCfg('fromname')));
         $mailer->setSubject(stripslashes($emailsubject));
         $mailer->setBody($emailbody);
         $mailer->IsHTML($mode);
         $emailcopies = $cfg->get('email_copies');
         // the complete address list is already trimmed
         $aemailcopies = explode("\n", $emailcopies);
         // Add recipients
         $mailer->addRecipient(trim($header->email));
         // add the copies
         foreach ($aemailcopies as $key => $emailaddress) {
             $mailer->addRecipient(trim($emailaddress));
             // trim each address from any \n ...
         }
         // Send the Mail
         $rs = $mailer->Send();
     }
     return $rs;
 }
예제 #2
0
 function checkout($orderid, $ship = null)
 {
     // it uses the simple way to upload a cart with contents to paypal as explained here:
     // https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_cart_upload#id08A3F700OYK
     // data available December 28, 2009.
     //get PayPal configuration
     $cfg = new sc_configuration();
     $reselleremail = $cfg->get("reselleremail");
     $ppcurrency = $cfg->get("paypalcurrency");
     $environment = $cfg->get("ppenvironment");
     // live or sandbox
     $ctax = new taxes();
     $taxrate = $ctax->getTax(@$ship['region']);
     if (!$reselleremail) {
         echo "Reseller email is not entered, please add this to the configuration first. PayPal cannot be used!";
         return;
     }
     // add the details to the order
     $gtotal = 0;
     //define the grand total
     $pptax = 0;
     // define the tax for paypal
     if ($environment == 0) {
         // live
         $html = "<form action='https://www.paypal.com/cgi-bin/webscr' method='post' name ='ppform' target='paypal'>";
     } else {
         // sandbox
         $html = "<form action='https://www.sandbox.paypal.com/cgi-bin/webscr' method='post' name ='ppform' target='paypal'>";
     }
     $html .= "<input type=\"{$this->debugshow}\" name=\"cmd\" value=\"_cart\">";
     $html .= "<input type=\"{$this->debugshow}\" name=\"upload\" value=\"1\">";
     $html .= "<input type=\"{$this->debugshow}\" name=\"business\" value=\"{$reselleremail}\">";
     $html .= "<input type=\"{$this->debugshow}\" name=\"currency_code\" value=\"{$ppcurrency}\">";
     $html .= "<input type=\"{$this->debugshow}\" name=\"rm\" value=\"2\">";
     $fieldnumber = 0;
     // PayPal field numbering variable
     $odetails = new orderdetail();
     $lst = $odetails->getDetailsByOrderId($orderid);
     foreach ($lst as $product) {
         // create a post field and field value for PayPal
         if ($product->total > 0) {
             // price positive, so standard product to be paid for
             $fieldnumber = $fieldnumber + 1;
             //increment the field number (could also be done with $fieldnumber++)
             $html .= "<input type='{$this->debugshow}' name='item_name_" . $fieldnumber . "' value='" . $product->shorttext . " (" . $product->prodcode . ") " . $product->option . "'>";
             $html .= "<input type='{$this->debugshow}' name='amount_" . $fieldnumber . "' value='" . $product->unitprice . "'>";
             $html .= "<input type='{$this->debugshow}' name='quantity_" . $fieldnumber . "' value='" . $product->qty . "'>";
         } else {
             $html .= "<input type='{$this->debugshow}' name='discount_amount_cart' value='" . abs($product->total) . "'>";
         }
         $gtotal += $product->total;
     }
     if ($taxrate > 0) {
         // taxes to be applied!
         // check if taxes should be paid on shipping
         $taxonshipping = $cfg->get("taxonshipping");
         if ($taxonshipping == 1) {
             // tax is calculated on shipping cost
             $pptax = $gtotal * $taxrate + $ship['cost'] * $taxrate;
         } else {
             $pptax = $gtotal * $taxrate;
         }
     }
     if ($pptax > 0) {
         //either one or both of the taxes have to be applied, so we add the tax field for PP
         $html .= "<input type=\"{$this->debugshow}\" name=\"tax_cart\" value=\"" . number_format($pptax, 2, ".", "") . '">';
         //
     }
     if ($ship['enabled']) {
         $html .= "<input type=\"{$this->debugshow}\" name=\"shipping_1\" value=\"" . $ship['cost'] . "\">";
     }
     $html .= "<input type=\"{$this->debugshow}\" name=\"custom\" value=\"{$orderid}\">";
     // these are the return urls to go to when coming back from paypal
     $successurl = JURI::base(false) . "index.php?option=com_caddy&action=paysuccess";
     $failurl = JURI::base(false) . "index.php?option=com_caddy&action=payfail";
     $html .= "<input type=\"{$this->debugshow}\" name=\"cancel_return\" value=\"{$failurl}\">";
     $html .= "<input type=\"{$this->debugshow}\" name=\"return\" value=\"{$successurl}\">";
     $html .= JText::_('SC_WE_USE_PAYPAL');
     // PayPal requires you use their logo to check out. Check the PayPal site for other button types
     // look here for more buttons from PayPal https://www.paypal.com/newlogobuttons
     // look here for the rules of usage of the paypal logos and pay buttons:
     //https://www.paypalobjects.com/WEBSCR-640-20110401-1/en_US/pdf/merchant_graphic_guidelines.pdf
     /** customizers, do your stuff here!
     You may add all kinds of fields now to the paypal "cart" to customize your heading in PayPal and so on.
     None of these novelties have been added here, but if you want to customize the appearance of your presence in Paypal,
     Here is the place.
     
     */
     $html .= '<p>
     <input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" align="left" style="margin-right:7px;"> <span style="font-size:11px; font-family: Arial, Verdana;">The safer, easier way to pay.</span>
     <p>';
     // additional PayPal info
     // be careful to 'escape' any " with \ !
     /**
             $html .="<p>
     <!-- PayPal Logo --><table border=\"0\" cellpadding=\"10\" cellspacing=\"0\" align=\"center\"><tr><td align=\"center\"></td></tr>
     <tr><td align=\"center\"><a href=\"#\" onclick=\"javascript:window.open('https://www.paypal.com/cgi-bin/webscr?cmd=xpt/Marketing/popup/OLCWhatIsPayPal-outside','olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=350');\">
     <img  src=\"https://www.paypal.com/en_US/i/bnr/vertical_solution_PPeCheck.gif\" border=\"0\" alt=\"Solution Graphics\"></a></td></tr></table><!-- PayPal Logo -->        
             </p>";
     */
     // otherwise we could use a simple submit button:
     //$html .='<input type="submit" value="PayPal">  ';
     $html .= "</form>";
     // if you want to add more text here
     // add it here like this:
     // $html .= "Your text here";
     // *before* the line below
     echo $html;
     // display the html.
 }