-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mvgucht
committed
Nov 19, 2014
1 parent
e727ffc
commit 8216ce0
Showing
17 changed files
with
304 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* @category Checkout | ||
* @author PHPro ([email protected]) | ||
*/ | ||
|
||
/** | ||
* Class DPD_Shipping_Helper_Data | ||
*/ | ||
|
@@ -105,10 +106,11 @@ public function getGoogleMapsCenter() | |
* @param $message | ||
* @param $level | ||
*/ | ||
public function log($message,$level){ | ||
public function log($message, $level) | ||
{ | ||
$allowedLogLevel = Mage::getStoreConfig('carriers/dpdparcelshops/log_level'); | ||
if($level <= $allowedLogLevel){ | ||
Mage::log($message,$level,'dpd.log'); | ||
if ($level <= $allowedLogLevel) { | ||
Mage::log($message, $level, 'dpd.log'); | ||
} | ||
} | ||
|
||
|
@@ -119,11 +121,12 @@ public function log($message,$level){ | |
* @param $folder | ||
* @param $name | ||
*/ | ||
public function generatePdfAndSave($pdfString, $folder, $name){ | ||
public function generatePdfAndSave($pdfString, $folder, $name) | ||
{ | ||
$io = new Varien_Io_File(); | ||
$io->setAllowCreateFolders(true); | ||
$io->open(array('path' => Mage::getBaseDir('media')."/dpd/".$folder)); | ||
$io->streamOpen($name.'.pdf', 'w+'); | ||
$io->open(array('path' => Mage::getBaseDir('media') . "/dpd/" . $folder)); | ||
$io->streamOpen($name . '.pdf', 'w+'); | ||
$io->streamLock(true); | ||
$io->streamWrite($pdfString); | ||
$io->streamUnlock(); | ||
|
@@ -135,7 +138,8 @@ public function generatePdfAndSave($pdfString, $folder, $name){ | |
* | ||
* @return bool | ||
*/ | ||
public function isMageEnterprise() { | ||
public function isMageEnterprise() | ||
{ | ||
return Mage::getConfig()->getModuleConfig('Enterprise_Enterprise') && Mage::getConfig()->getModuleConfig('Enterprise_AdminGws') && Mage::getConfig()->getModuleConfig('Enterprise_Checkout') && Mage::getConfig()->getModuleConfig('Enterprise_Customer'); | ||
} | ||
|
||
|
@@ -148,7 +152,7 @@ public function isMageEnterprise() { | |
public function getLanguageFromStore($storeId) | ||
{ | ||
$locale = Mage::app()->getStore($storeId)->getConfig('general/locale/code'); | ||
$localeCode = explode('_' , $locale); | ||
$localeCode = explode('_', $locale); | ||
|
||
return strtoupper($localeCode[0]); | ||
} | ||
|
@@ -159,13 +163,43 @@ public function getLanguageFromStore($storeId) | |
* @param $shipment | ||
* @return int | ||
*/ | ||
public function calculateTotalShippingWeight($shipment){ | ||
public function calculateTotalShippingWeight($shipment) | ||
{ | ||
$weight = 0; | ||
$shipmentItems = $shipment->getAllItems(); | ||
foreach ($shipmentItems as $shipmentItem) { | ||
$weight = $weight + $shipmentItem->getWeight(); | ||
$orderItem = $shipmentItem->getOrderItem(); | ||
if(!$orderItem->getParentItemId()){ | ||
$weight = $weight + ($shipmentItem->getWeight() * $shipmentItem->getQty()); | ||
} | ||
} | ||
|
||
return $weight; | ||
} | ||
|
||
/** | ||
* Check if on Onestepcheckout page or if Onestepcheckout is the refferer | ||
* | ||
* @return bool | ||
*/ | ||
public function getIsOnestepCheckout() | ||
{ | ||
if (strpos(Mage::helper("core/url")->getCurrentUrl(), 'onestepcheckout') !== false || strpos(Mage::app()->getRequest()->getHeader('referer'), 'onestepcheckout') !== false) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Return our custom js when the check for onestepcheckout returns true. | ||
* | ||
* @return string | ||
*/ | ||
public function getOnestepCheckoutJs() | ||
{ | ||
if ($this->getIsOnestepCheckout()) { | ||
return 'dpd/onestepcheckout_shipping.js'; | ||
} | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* @category Checkout | ||
* @author PHPro ([email protected]) | ||
*/ | ||
|
||
/** | ||
* Class DPD_Shipping_Model_Adminhtml_DpdGrid | ||
*/ | ||
|
@@ -111,21 +112,35 @@ protected function _generateLabelAndReturnLabel($order, $shipment) | |
{ | ||
$parcelshop = false; | ||
$billingAddress = $order->getBillingAddress(); | ||
$recipient = array( | ||
'name1' => $billingAddress->getFirstname() . " " . $billingAddress->getLastname(), | ||
'street' => $billingAddress->getStreet(1) . " " . $billingAddress->getStreet(2), | ||
'country' => $billingAddress->getCountry(), | ||
'zipCode' => $billingAddress->getPostcode(), | ||
'city' => $billingAddress->getCity() | ||
); | ||
$shippingAddress = $order->getShippingAddress(); | ||
if (strpos($order->getShippingMethod(), 'parcelshop') !== false) { | ||
$parcelshop = true; | ||
} | ||
if ($parcelshop) { | ||
$recipient = array( | ||
'name1' => $billingAddress->getFirstname() . " " . $billingAddress->getLastname(), | ||
'name2' => $billingAddress->getCompany(), | ||
'street' => $billingAddress->getStreet(1) . " " . $billingAddress->getStreet(2), | ||
'country' => $billingAddress->getCountry(), | ||
'zipCode' => $billingAddress->getPostcode(), | ||
'city' => $billingAddress->getCity() | ||
); | ||
} | ||
else{ | ||
$recipient = array( | ||
'name1' => $shippingAddress->getFirstname() . " " . $shippingAddress->getLastname(), | ||
'name2' => $shippingAddress->getCompany(), | ||
'street' => $shippingAddress->getStreet(1) . " " . $shippingAddress->getStreet(2), | ||
'country' => $shippingAddress->getCountry(), | ||
'zipCode' => $shippingAddress->getPostcode(), | ||
'city' => $shippingAddress->getCity() | ||
); | ||
} | ||
$labelWebserviceCallback = Mage::getSingleton('dpd/webservice')->getShippingLabel($recipient, $order, $shipment, $parcelshop); | ||
|
||
if ($labelWebserviceCallback) { | ||
Mage::helper('dpd')->generatePdfAndSave($labelWebserviceCallback->parcellabelsPDF, 'orderlabels', $order->getIncrementId(). "-" .$labelWebserviceCallback->shipmentResponses->parcelInformation->parcelLabelNumber); | ||
return $order->getIncrementId(). "-" .$labelWebserviceCallback->shipmentResponses->parcelInformation->parcelLabelNumber; | ||
Mage::helper('dpd')->generatePdfAndSave($labelWebserviceCallback->parcellabelsPDF, 'orderlabels', $order->getIncrementId() . "-" . $labelWebserviceCallback->shipmentResponses->parcelInformation->parcelLabelNumber); | ||
return $order->getIncrementId() . "-" . $labelWebserviceCallback->shipmentResponses->parcelInformation->parcelLabelNumber; | ||
} else { | ||
return false; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* @category Checkout | ||
* @author PHPro ([email protected]) | ||
*/ | ||
|
||
/** | ||
* Class DPD_Shipping_Model_Observer | ||
*/ | ||
|
@@ -102,4 +103,45 @@ public function sales_order_shipment_save_before($observer) | |
$shipment->setTotalWeight($weight); | ||
} | ||
} | ||
|
||
/** | ||
* If the checkout is a Onestepcheckout and dpdselected is true, we need to copy the address on submitting | ||
* | ||
* @param $observer | ||
*/ | ||
public function checkout_submit_all_after($observer) | ||
{ | ||
if (Mage::helper('dpd')->getIsOnestepCheckout()) { | ||
$quote = Mage::getSingleton('checkout/session')->getQuote(); | ||
$address = $quote->getShippingAddress(); | ||
if ($address->getShippingMethod() == "dpdparcelshops_dpdparcelshops" && (bool)$quote->getDpdSelected()) { | ||
$address->unsetAddressId() | ||
->unsetTelephone() | ||
->setSaveInAddressBook(0) | ||
->setFirstname('DPD ParcelShop: ') | ||
->setLastname($quote->getDpdCompany()) | ||
->setStreet($quote->getDpdStreet()) | ||
->setCity($quote->getDpdCity()) | ||
->setPostcode($quote->getDpdZipcode()) | ||
->setCountryId($quote->getDpdCountry()) | ||
->save(); | ||
} | ||
$quote->setDpdSelected(0); | ||
} | ||
} | ||
|
||
/** | ||
* If Billing/Shipping address was changed, reset the DPD shipping Method. | ||
* | ||
* @param $observer | ||
*/ | ||
public function controller_action_predispatch_onestepcheckout_ajax_save_billing($observer) | ||
{ | ||
if (Mage::helper('dpd')->getIsOnestepCheckout()) { | ||
$quote = Mage::getSingleton('checkout/session')->getQuote(); | ||
if ($quote->getDpdSelected()) { | ||
$quote->setDpdSelected(0); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* @category Checkout | ||
* @author PHPro ([email protected]) | ||
*/ | ||
|
||
/** | ||
* Class DPD_Shipping_Model_Returnlabels | ||
*/ | ||
|
@@ -29,27 +30,43 @@ protected function _construct() | |
public function generateLabelAndSave($orderId) | ||
{ | ||
$order = Mage::getModel('sales/order')->load($orderId); | ||
$billingAddress = $order->getBillingAddress(); | ||
$recipient = array( | ||
'name1' => $billingAddress->getFirstname() . " " . $billingAddress->getLastname(), | ||
'street' => $billingAddress->getStreet(1) . " " . $billingAddress->getStreet(2), | ||
'country' => $billingAddress->getCountry(), | ||
'zipCode' => $billingAddress->getPostcode(), | ||
'city' => $billingAddress->getCity() | ||
); | ||
if (strpos($order->getShippingMethod(), 'parcelshop') !== false) { | ||
$parcelshop = true; | ||
} | ||
if ($parcelshop) { | ||
$billingAddress = $order->getBillingAddress(); | ||
$recipient = array( | ||
'name1' => $billingAddress->getFirstname() . " " . $billingAddress->getLastname(), | ||
'name2' => $billingAddress->getCompany(), | ||
'street' => $billingAddress->getStreet(1) . " " . $billingAddress->getStreet(2), | ||
'country' => $billingAddress->getCountry(), | ||
'zipCode' => $billingAddress->getPostcode(), | ||
'city' => $billingAddress->getCity() | ||
); | ||
} else { | ||
$shippingAddress = $order->getShippingAddress(); | ||
$recipient = array( | ||
'name1' => $shippingAddress->getFirstname() . " " . $shippingAddress->getLastname(), | ||
'name2' => $shippingAddress->getCompany(), | ||
'street' => $shippingAddress->getStreet(1) . " " . $shippingAddress->getStreet(2), | ||
'country' => $shippingAddress->getCountry(), | ||
'zipCode' => $shippingAddress->getPostcode(), | ||
'city' => $shippingAddress->getCity() | ||
); | ||
} | ||
$returnlabel = Mage::getSingleton('dpd/webservice')->getReturnLabel($recipient); | ||
if(!$returnlabel){ | ||
if (!$returnlabel) { | ||
return false; | ||
} | ||
//convertstring to pdf and save | ||
Mage::helper('dpd')->generatePdfAndSave($returnlabel->parcellabelsPDF, 'returnlabel', $order->getIncrementId() ."-". $returnlabel->shipmentResponses->parcelInformation->parcelLabelNumber); | ||
Mage::helper('dpd')->generatePdfAndSave($returnlabel->parcellabelsPDF, 'returnlabel', $order->getIncrementId() . "-" . $returnlabel->shipmentResponses->parcelInformation->parcelLabelNumber); | ||
|
||
//save labeldata for admin display | ||
$returnLabelObject = new DPD_Shipping_Model_Returnlabels; | ||
$returnLabelObject | ||
->setLabelNumber($returnlabel->shipmentResponses->parcelInformation->parcelLabelNumber) | ||
->setLabelPdfUrl( $order->getIncrementId() ."-".$returnlabel->shipmentResponses->parcelInformation->parcelLabelNumber . ".pdf") | ||
->setLabelInstructionsUrl( $order->getIncrementId() ."-".$returnlabel->shipmentResponses->parcelInformation->parcelLabelNumber . "-instructions.pdf") | ||
->setLabelPdfUrl($order->getIncrementId() . "-" . $returnlabel->shipmentResponses->parcelInformation->parcelLabelNumber . ".pdf") | ||
->setLabelInstructionsUrl($order->getIncrementId() . "-" . $returnlabel->shipmentResponses->parcelInformation->parcelLabelNumber . "-instructions.pdf") | ||
->setOrderId($orderId) | ||
->save(); | ||
return $returnLabelObject->getId(); | ||
|
@@ -73,11 +90,11 @@ public function sendEmail($order, $returnId) | |
$transactionalEmail = Mage::getModel('core/email_template') | ||
->setDesignConfig(array('area' => 'frontend', 'store' => $order->getStoreId())); | ||
foreach ($attachments as $pdf_attachment) { | ||
if (!empty($pdf_attachment) && file_exists(Mage::getBaseDir('media')."/dpd/returnlabel/".$pdf_attachment)) { | ||
if (!empty($pdf_attachment) && file_exists(Mage::getBaseDir('media') . "/dpd/returnlabel/" . $pdf_attachment)) { | ||
$transactionalEmail | ||
->getMail() | ||
->createAttachment( | ||
file_get_contents(Mage::getBaseDir('media')."/dpd/returnlabel/".$pdf_attachment), | ||
file_get_contents(Mage::getBaseDir('media') . "/dpd/returnlabel/" . $pdf_attachment), | ||
Zend_Mime::TYPE_OCTETSTREAM, | ||
Zend_Mime::DISPOSITION_ATTACHMENT, | ||
Zend_Mime::ENCODING_BASE64, | ||
|
@@ -101,12 +118,13 @@ public function sendEmail($order, $returnId) | |
* | ||
* @param $returnId | ||
*/ | ||
public function deleteEntryAndAttachments($returnId){ | ||
public function deleteEntryAndAttachments($returnId) | ||
{ | ||
$returnLabel = Mage::getModel('dpd/returnlabels')->load($returnId); | ||
$attachments = array($returnLabel->getLabelPdfUrl(), $returnLabel->getLabelInstructionsUrl()); | ||
foreach ($attachments as $pdf_attachment) { | ||
$file = Mage::getBaseDir('media')."/dpd/returnlabels/".$pdf_attachment; | ||
if(file_exists($file)){ | ||
$file = Mage::getBaseDir('media') . "/dpd/returnlabels/" . $pdf_attachment; | ||
if (file_exists($file)) { | ||
unlink($file); | ||
} | ||
} | ||
|
@@ -120,41 +138,39 @@ public function deleteEntryAndAttachments($returnId){ | |
* @param $returnId | ||
* @return string | ||
*/ | ||
public function generateInstructionsPdf($orderId, $returnId){ | ||
public function generateInstructionsPdf($orderId, $returnId) | ||
{ | ||
$returnlabel = Mage::getModel('dpd/returnlabels')->load($returnId); | ||
$pdf = Zend_Pdf::load(Mage::getBaseDir('skin') . DS . 'adminhtml' . DS . 'default' . DS . 'default' . DS . 'dpd' . DS . 'returnlabel' . DS . 'instructions.pdf'); | ||
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); | ||
$page = $pdf->pages[0]; | ||
$page->setFont($font, 15); | ||
if(Mage::getStoreConfig('design/email/logo') && strpos(Mage::getStoreConfig('design/email/logo'),'.gif') === false && Mage::getVersion() >= "1.7"){ | ||
$uploadDir = Mage_Adminhtml_Model_System_Config_Backend_Email_Logo::UPLOAD_DIR; | ||
$fullFileName = Mage::getBaseDir('media') . DS . $uploadDir . DS . Mage::getStoreConfig('design/email/logo'); | ||
$image = Zend_Pdf_Image::imageWithPath($fullFileName); | ||
$imgWidthPts = $image->getPixelWidth() * 72 / 96; | ||
$imgHeightPts = $image->getPixelHeight() * 72 / 96; | ||
$x1 = 50; | ||
$y1 = 687; | ||
$page->drawImage($image, $x1, $y1, $x1 + $imgWidthPts, $y1 + $imgHeightPts); | ||
} | ||
elseif(Mage::getVersion() < "1.7"){ | ||
try{ | ||
$fullFileName = Mage::getBaseDir('skin') . DS . 'frontend' . DS .'default' . DS . 'default' . DS . Mage::getStoreConfig('design/header/logo_src'); | ||
if (Mage::getStoreConfig('design/email/logo') && strpos(Mage::getStoreConfig('design/email/logo'), '.gif') === false && Mage::getVersion() >= "1.7") { | ||
$uploadDir = Mage_Adminhtml_Model_System_Config_Backend_Email_Logo::UPLOAD_DIR; | ||
$fullFileName = Mage::getBaseDir('media') . DS . $uploadDir . DS . Mage::getStoreConfig('design/email/logo'); | ||
$image = Zend_Pdf_Image::imageWithPath($fullFileName); | ||
$imgWidthPts = $image->getPixelWidth() * 72 / 96; | ||
$imgWidthPts = $image->getPixelWidth() * 72 / 96; | ||
$imgHeightPts = $image->getPixelHeight() * 72 / 96; | ||
$x1 = 50; | ||
$y1 = 687; | ||
$page->drawImage($image, $x1, $y1, $x1 + $imgWidthPts, $y1 + $imgHeightPts); | ||
} | ||
catch(Exception $e){ | ||
} elseif (Mage::getVersion() < "1.7") { | ||
try { | ||
$fullFileName = Mage::getBaseDir('skin') . DS . 'frontend' . DS . 'default' . DS . 'default' . DS . Mage::getStoreConfig('design/header/logo_src'); | ||
$image = Zend_Pdf_Image::imageWithPath($fullFileName); | ||
$imgWidthPts = $image->getPixelWidth() * 72 / 96; | ||
$imgHeightPts = $image->getPixelHeight() * 72 / 96; | ||
$x1 = 50; | ||
$y1 = 687; | ||
$page->drawImage($image, $x1, $y1, $x1 + $imgWidthPts, $y1 + $imgHeightPts); | ||
} catch (Exception $e) { | ||
Mage::helper('dpd')->log('Instructions PDF: No logo found or incorrect file format', Zend_Log::INFO); | ||
} | ||
} | ||
else{ | ||
} else { | ||
Mage::helper('dpd')->log('Instructions PDF: No logo found or incorrect file format', Zend_Log::INFO); | ||
} | ||
$page->drawText(implode(' ',str_split($returnlabel->getLabelNumber(), 4)), '321', '215'); | ||
$page->drawText(implode(' ', str_split($returnlabel->getLabelNumber(), 4)), '321', '215'); | ||
$order = Mage::getResourceModel('sales/order_collection')->addAttributeToSelect('increment_id')->addAttributeToFilter('entity_id', array('eq' => $orderId))->getFirstItem(); | ||
Mage::helper('dpd')->generatePdfAndSave($pdf->render(),'returnlabel',$order->getIncrementId().'-'.$returnlabel->getLabelNumber()."-instructions"); | ||
Mage::helper('dpd')->generatePdfAndSave($pdf->render(), 'returnlabel', $order->getIncrementId() . '-' . $returnlabel->getLabelNumber() . "-instructions"); | ||
} | ||
} |
Oops, something went wrong.