Skip to content

Commit

Permalink
SUPTRUSTEDSHOPS-145 - Merge SUPTRUSTEDSHOPS-122-trustedshops-widget i…
Browse files Browse the repository at this point in the history
…nto dev branch.
  • Loading branch information
symmetrics-nd committed Jan 9, 2014
2 parents 495dae5 + 28ed673 commit c71d198
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 168 deletions.
100 changes: 50 additions & 50 deletions build/app/code/community/Symmetrics/TrustedRating/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,22 @@
*/
class Symmetrics_TrustedRating_Helper_Data extends Mage_Core_Helper_Abstract
{
/**
* Some constants to test if buyerprotect widget is available.
*/
const BUYERPROTECT_MODULE_CONFIG_KEY = 'buyerprotect',
BUYERPROTECT_MODULE_NAME = 'Symmetrics_Buyerprotect';

/**
* @const CONFIG_STATUS_PATH system config path to status settings
*/
const CONFIG_STATUS_PATH = 'trustedrating/status';

/**
* SUPTRUSTEDSHOPS-122:
*/
const XML_PATH_SHOW_WIDGET = 'show_widget';

/**
* Flag indicates if rating button image underneath media already exists
*
Expand All @@ -62,16 +73,15 @@ class Symmetrics_TrustedRating_Helper_Data extends Mage_Core_Helper_Abstract
protected $_trustedRatingStores = null;

/**
* Alias of self::isTrustedRatingActive()
*
* @param int|null|Mage_Core_Model_Store $store Store instance or ID
* SUPTRUSTEDSHOPS-122:
*
* @return boolean
* @see self::isTrustedRatingActive()
*/
public function canShowWidget($store = null)
public function canShowWidget()
{
return $this->isTrustedRatingActive($store);
return $this->getTsId() &&
$this->getIsActive() &&
$this->getModuleConfig(self::XML_PATH_SHOW_WIDGET);
}

/**
Expand Down Expand Up @@ -124,25 +134,36 @@ public function getConfig($node, $key)
}

/**
* Get module specific config from system configuration
* Get configured language of module
*
* @param string $key config key
* @param null|int $storeId Store ID
*
* @return mixed
* @return string
*/
public function getModuleConfig($key)
public function getLanguage($storeId = null)
{
return $this->getConfig(self::CONFIG_STATUS_PATH, $key);
$language = Mage::getStoreConfig(
Symmetrics_TrustedRating_Model_Trustedrating::XML_PATH_TRUSTEDRATING_LANGUAGE,
$storeId
);

if (!$language) {
$language = Symmetrics_TrustedRating_Model_Trustedrating::DEFAULT_LANGUAGE;
}

return $language;
}

/**
* Get the "incluce orders since" setting from store config
* Get module specific config from system configuration
*
* @param string $key config key
*
* @return Zend_Date
* @return mixed
*/
public function getActiveSince()
public function getModuleConfig($key)
{
return $this->getConfig('trustedrating/data', 'active_since');
return $this->getConfig(self::CONFIG_STATUS_PATH, $key);
}

/**
Expand All @@ -156,24 +177,20 @@ public function getIsActive()
}

/**
* Get configured language of module
*
* @param null|int $storeId Store ID
* Get the trusted rating id from store config
*
* @param mixed $storeId ID of Store.
*
* @return string
*/
public function getLanguage($storeId = null)
public function getTsId($storeId = null)
{
$language = Mage::getStoreConfig(
Symmetrics_TrustedRating_Model_Trustedrating::XML_PATH_TRUSTEDRATING_LANGUAGE,
$storeId
);

if (!$language) {
$language = Symmetrics_TrustedRating_Model_Trustedrating::DEFAULT_LANGUAGE;
if ((null == $storeId) && Mage::app()->getStore()->isAdmin()) {
$excMessage = 'Can\'t determine TS ID in Admin scope without Store ID!';
Mage::logException(new Exception($excMessage));
}

return $language;
return Mage::getStoreConfig('trustedrating/data/trustedrating_id', $storeId);
}

/**
Expand Down Expand Up @@ -206,13 +223,13 @@ public function getCustomerEmail($shipmentId)

return $email;
}

/**
* Get language specific Trusted Shops rating URL
*
*
* @param null|string $rateType Rating type, now or laterg
* @param null|int|Mage_Core_Model_Store $store Store ID or language
*
*
* @return type
*/
public function getRatingUrl($rateType = 'rate_now', $store = null)
Expand Down Expand Up @@ -272,23 +289,6 @@ public function getRateLaterDaysInterval($store = null)
return Mage::getStoreConfig($path, $store);
}

/**
* Get the trusted rating id from store config
*
* @param mixed $storeId ID of Store.
*
* @return string
*/
public function getTsId($storeId = null)
{
if ((null == $storeId) && Mage::app()->getStore()->isAdmin()) {
$excMessage = 'Can\'t determine TS ID in Admin scope without Store ID!';
Mage::logException(new Exception($excMessage));
}

return Mage::getStoreConfig('trustedrating/data/trustedrating_id', $storeId);
}

/**
* Getter for TS' privacy link
*
Expand Down Expand Up @@ -369,13 +369,13 @@ public function isTrustedRatingActive($store = null)
return $store->getConfig(Symmetrics_TrustedRating_Model_Trustedrating::XML_PATH_TRUSTEDRATING_ACTIVE) &&
$store->getConfig(Symmetrics_TrustedRating_Model_Trustedrating::XML_PATH_TRUSTEDRATING_ID);
}

/**
* Get Base64 URL encoded string.
*
*
* @param string $data Data to encode
* @param bool $urlEncode Using urlencode or not
*
*
* @return string
* @see urlencode
* @see base64_encode
Expand Down
109 changes: 109 additions & 0 deletions build/app/code/community/Symmetrics/TrustedRating/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,115 @@ public function changeTrustedRatingStatus($observer)
Mage::getSingleton('core/session')->addNotice($returnString . $returnValue);
}

/**
* Checks the shippings which will get an email
*
* @return void
*/
public function checkSendRatingEmail()
{
$model = Mage::getModel('trustedrating/trustedrating');
if ($shipmentIds = $model->checkShippings()) {
$this->_sendTrustedRatingMails($shipmentIds);
}
}

/**
* Send mail and save entry to db
*
* @param array $shipmentIds Shipment IDs
*
* @return void
*/
private function _sendTrustedRatingMails($shipmentIds)
{
foreach ($shipmentIds as $shipmentId) {
$orderId = $this->getHelper()->getOrderId($shipmentId);
$order = Mage::getModel('sales/order')->load($orderId);
$this->_sendTransactionalMail($order);
$this->_saveShipmentIdToTable($shipmentId);
}
}

/**
* Generates the rating url by given order object.
*
* @param Mage_Sales_Model_Order $order Order object.
*
* @return string
*/
protected function _getRatingUrl($order)
{
$trustedRating = Mage::getSingleton('trustedrating/trustedrating');
$storeId = $order->getStoreId();
$tsId = $trustedRating->getTsId($storeId);
$params = array(
'buyerEmail' => base64_encode($order->getCustomerEmail()),
'shopOrderID' => base64_encode($order->getRealOrderId())
);
$ratingUrl = $trustedRating->getEmailRatingLink($storeId) . '_' . $tsId . '.html'
. '&' // Do not change, it's necessary for the TS systems to
// handle the query parameters correctly.
. http_build_query($params);

return $ratingUrl;
}

/**
* Generates the image url by given order object.
*
* @param Mage_Sales_Model_Order $order Order object.
*
* @return string
*/
protected function _getImageUrl($order)
{
$language = Mage::getStoreConfig(
Symmetrics_TrustedRating_Model_Trustedrating::CONFIG_LANGUAGE,
$order->getStoreId()
);

return Mage::getDesign()->getSkinUrl(
'images/bewerten_' . $language . '.gif', array('_area' => 'frontend')
);
}

/**
* Send transactional email to customer.
*
* @param Mage_Sales_Model_Order $order Order object.
*
* @return void
*/
public function _sendTransactionalMail($order)
{
Mage::getModel('core/email_template')->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_CONFIG_EMAIL_TEMPLATE, $order->getStoreId()),
Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY),
$order->getCustomerEmail(),
$order->getCustomerName(),
array(
'ratingUrl' => $this->_getRatingUrl($order),
'imageUrl' => $this->_getImageUrl($order)
),
$order->getStoreId()
);
}

/**
* Save shipping ID of customers which got an email to table
*
* @param int $shipmentId Shipping Id
*
* @return void
*/
private function _saveShipmentIdToTable($shipmentId)
{
$mailModel = Mage::getModel('trustedrating/mail');
$mailModel->setShippmentId($shipmentId)
->save();
}

/**
* Collect the data for sending to Trusted Shops
*
Expand Down
83 changes: 27 additions & 56 deletions build/app/code/community/Symmetrics/TrustedRating/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@
</trustedrating>
</updates>
</layout>
<translate>
<modules>
<Symmetrics_TrustedRating>
<files>
<trustedrating>Symmetrics_TrustedRating.csv</trustedrating>
</files>
</Symmetrics_TrustedRating>
</modules>
</translate>
</frontend>
<adminhtml>
<translate>
Expand Down Expand Up @@ -150,67 +159,29 @@
<url>https://www.trustedshops.de/ts/services/TsRating?wsdl</url>
<partnerpackage>symmetrics</partnerpackage>
</soapapi>
<trustedratingmail>
<emails>
<default>
<trustedrating_mail_de>
<execute>1</execute>
<template_code>Trusted Rating Notification E-Mail (DE)</template_code>
<template_type>2</template_type>
<template_subject>Waren Sie mit Ihrem Kauf bei {{var store.getFrontendName()}} zufrieden? Bitte bewerten Sie uns!</template_subject>
<text>app/locale/de_DE/template/trustedrating/email/trustedrating_email.html</text>
</trustedrating_mail_de>
<trustedrating_mail_en>
<execute>1</execute>
<template_code>Trusted Rating Notification E-Mail (EN)</template_code>
<template_type>2</template_type>
<template_subject>Are you satified with {{var store.getFrontendName()}}? Please write a review!</template_subject>
<text>app/locale/en_US/template/trustedrating/email/trustedrating_email.html</text>
</trustedrating_mail_en>
<trustedrating_mail_fr>
<execute>1</execute>
<template_code>Trusted Rating Notification E-Mail (FR)</template_code>
<template_type>2</template_type>
<template_subject>Etes-vous satisfait de votre achat chez {{var store.getFrontendName()}}? Donnez nous votre avis!</template_subject>
<text>app/locale/fr_FR/template/trustedrating/email/trustedrating_email.html</text>
</trustedrating_mail_fr>
<trustedrating_mail_es>
<execute>1</execute>
<template_code>Trusted Rating Notification E-Mail (ES)</template_code>
<template_type>2</template_type>
<template_subject>¿Está satisfecho con su compra en {{var store.getFrontendName()}}? ¡Haga una valoración!</template_subject>
<text>app/locale/es_ES/template/trustedrating/email/trustedrating_email.html</text>
</trustedrating_mail_es>
<trustedrating_mail_pl>
<execute>1</execute>
<template_code>Trusted Rating Notification E-Mail (PL)</template_code>
<template_type>2</template_type>
<template_subject>Czy jesteś zadowolony z zakupu i naszych usług? Tutaj możesz ocenić {{var store.getFrontendName()}}.</template_subject>
<text>app/locale/pl_PL/template/trustedrating/email/trustedrating_email.html</text>
</trustedrating_mail_pl>
</default>
</emails>
</trustedratingmail>
<trustedrating>
<trustedrating_email>
<days>3</days>
</trustedrating_email>
<status>
<trustedrating_active>0</trustedrating_active>
<reminder_interval><![CDATA[5]]></reminder_interval>
<show_widget><![CDATA[1]]></show_widget>
</status>
<rate_now_url>
<de>https://www.trustedshops.com/bewertung/bewerten</de>
<en>https://www.trustedshops.com/buyerrating/rate</en>
<fr>https://www.trustedshops.com/evaluation/evaluer</fr>
<es>https://www.trustedshops.com/evaluacion/evaluar</es>
<pl>https://www.trustedshops.com/evaluacion/evaluar</pl>
</rate_now_url>
<rate_later_url>
<en><![CDATA[https://www.trustedshops.com/reviews/rateshoplater.php]]></en>
</rate_later_url>
<privacy_url>
<de><![CDATA[http://www.trustedshops.de/datenschutz.html]]></de>
<en><![CDATA[http://www.trustedshops.eu/legal-notice-privacy.html]]></en>
<fr><![CDATA[http://www.trustedshops.fr/mentions-legales.html]]></fr>
<es><![CDATA[http://www.trustedshops.es/aviso-legal.html]]></es>
<pl><![CDATA[http://www.trustedshops.pl/dane-firmy-ochrona-danych.html]]></pl>
</privacy_url>
</trustedrating>
</default>
<crontab>
<jobs>
<trustedrating>
<schedule>
<cron_expr>4 4 * * *</cron_expr>
</schedule>
<run>
<model>trustedrating/observer::checkSendRatingEmail</model>
</run>
</trustedrating>
</jobs>
</crontab>
</config>
Loading

0 comments on commit c71d198

Please sign in to comment.