Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
1.0.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuravel committed Feb 2, 2016
1 parent 49fd285 commit 111f4ad
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 340 deletions.
14 changes: 0 additions & 14 deletions app/code/community/Talkable/SocialReferrals/Block/Affiliate.php

This file was deleted.

This file was deleted.

189 changes: 90 additions & 99 deletions app/code/community/Talkable/SocialReferrals/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
class Talkable_SocialReferrals_Helper_Data extends Mage_Core_Helper_Abstract
{

//------------------+
// Default Settings |
//------------------+
//------------------------+
// Talkable Configuration |
//------------------------+

public function getSiteId()
{
Expand All @@ -22,120 +22,131 @@ public function getSiteId()

public function getIntegrationJsUrl()
{
$retval = $this->_getTextConfigValue("general/integration_js_url");

if ($retval == "") {
return "//d2jjzw81hqbuqv.cloudfront.net/integration/talkable-1.0.min.js";
} else {
if ($retval = $this->_getTextConfigValue("general/integration_js_url")) {
return $retval;
} else {
return Mage::getConfig()
->loadModulesConfiguration("config.xml")
->getNode("default/socialreferrals/general")
->integration_js_url;
}
}

//------------------------+
// Post-Checkout Campaign |
//------------------------+
//--------------------+
// Talkable Campaigns |
//--------------------+

/**
* @return bool Whether or not Post-Checkout Integration is enabled
* @return bool Whether or not Talkable Integration is enabled
*/
public function isPurchaseEnabled()
public function isEnabled()
{
return $this->_getBoolConfigValue("purchase/enabled");
return (
$this->isInviteEnabled() ||
$this->isPostPurchaseEnabled() ||
$this->isAdvocateDashboardEnabled() ||
$this->isFloatingWidgetPopupEnabled()
);
}

public function getPurchaseCampaignTags()
/**
* @return bool Whether or not Post Purchase Integration is enabled
*/
public function isPostPurchaseEnabled()
{
return $this->_getListConfigValue("purchase/campaign_tags");
return $this->_getBoolConfigValue("campaigns/post_purchase");
}

public function getPurchaseData($order)
/**
* @return bool Whether or not Invite Integration is enabled
*/
public function isInviteEnabled()
{
$retval = array(
"order_number" => $order->getIncrementId(),
"order_date" => $order->getCreatedAt(),
"subtotal" => $order->getSubtotal(),
"coupon_code" => $order->getCouponCode(),
"customer_id" => $order->getCustomerId(),
"email" => $order->getCustomerEmail(),
"first_name" => $order->getCustomerFirstname(),
"last_name" => $order->getCustomerLastname(),
"items" => array(),
);

foreach ($order->getAllVisibleItems() as $product) {
$retval["items"][] = array(
"product_id" => $product->getSku(),
"price" => $product->getPrice(),
"quantity" => $product->getQtyOrdered(),
"title" => $product->getName(),
);
}

return $retval;
return $this->_getBoolConfigValue("campaigns/invite");
}

//-----------------+
// Invite Campaign |
//-----------------+

/**
* @return bool Whether or not Standalone Integration is enabled
* @return bool Whether or not Advocate Dashboard Integration is enabled
*/
public function isAffiliateEnabled()
public function isAdvocateDashboardEnabled()
{
return $this->_getBoolConfigValue("affiliate/enabled");
return $this->_getBoolConfigValue("campaigns/advocate_dashboard");
}

public function getAffiliateCampaignTags()
/**
* @return bool Whether or not Floating Widget Popup Integration is enabled
*/
public function isFloatingWidgetPopupEnabled()
{
return $this->_getListConfigValue("affiliate/campaign_tags");
return $this->_getBoolConfigValue("campaigns/floating_widget_popup");
}

public function getAffiliateIframeOptions()
//-------------+
// Origin Data |
//-------------+

public function getPurchaseData($order)
{
return $this->_getIntegrationIframeOptions("affiliate");
$shippingAddress = $order->getShippingAddress();
$countryName = Mage::getModel("directory/country")
->loadByCode($shippingAddress->getCountryId())
->getName();

$shippingFields = array_filter(array(
implode(", ", $shippingAddress->getStreet()),
$shippingAddress->getCity(),
$shippingAddress->getRegion(),
$shippingAddress->getPostcode(),
$countryName,
));

$retval = array(
"customer" => array(
"email" => $order->getCustomerEmail(),
"first_name" => $order->getCustomerFirstname(),
"last_name" => $order->getCustomerLastname(),
"customer_id" => $order->getCustomerId(),
),
"purchase" => array(
"order_number" => $order->getIncrementId(),
"order_date" => $order->getCreatedAt(),
"subtotal" => $this->_normalizeAmount($order->getSubtotal()),
"coupon_code" => $order->getCouponCode(),
"items" => array(),
"shipping_zip" => $shippingAddress->getPostcode(),
"shipping_address" => implode(", ", $shippingFields),
),
);

foreach ($order->getAllVisibleItems() as $product) {
$retval["purchase"]["items"][] = array(
"product_id" => $product->getSku(),
"price" => $this->_normalizeAmount($product->getPrice()),
"quantity" => strval(round($product->getQtyOrdered())),
"title" => $product->getName(),
);
}

return $retval;
}

public function getAffiliateData()
public function getCustomerData()
{
$helper = Mage::helper("customer");

if ($helper->isLoggedIn()) {
$customer = $helper->getCustomer();
return array("affiliate_member" => array(
return array(
"email" => $customer->getEmail(),
"first_name" => $customer->getFirstname(),
"last_name" => $customer->getLastname(),
"customer_id" => $customer->getId(),
));
);
} else {
$emptyObject = new stdClass();
return array("affiliate_member" => $emptyObject);
return new stdClass();
}
}

//--------------------+
// Dashboard Campaign |
//--------------------+

/**
* @return bool Whether or not Dashboard Integration is enabled
*/
public function isDashboardEnabled()
{
return $this->_getBoolConfigValue("dashboard/enabled");
}

public function getDashboardCampaignTags()
{
return $this->_getListConfigValue("dashboard/campaign_tags");
}

public function getDashboardIframeOptions()
{
return $this->_getIntegrationIframeOptions("dashboard");
}

//---------+
// Private |
//---------+
Expand All @@ -145,34 +156,14 @@ private function _getBoolConfigValue($path)
return (bool) Mage::getStoreConfig("socialreferrals/" . $path);
}

private function _getListConfigValue($path)
{
return array_filter(array_map("trim", explode(",", Mage::getStoreConfig("socialreferrals/" . $path))));
}

private function _getTextConfigValue($path)
{
return trim(Mage::getStoreConfig("socialreferrals/" . $path));
}

private function _getIntegrationIframeOptions($path)
private function _normalizeAmount($value)
{
$width = $this->_getTextConfigValue($path . "/iframe_width");
$width = strpos($width, "%") !== false ? $width : (int) $width;

$height = $this->_getTextConfigValue($path . "/iframe_height");
$height = strpos($height, "%") !== false ? $height : (int) $height;

$container = $this->_getTextConfigValue($path . "/iframe_container");

return array(
"responsive" => $this->_getBoolConfigValue($path . "/iframe_responsive"),
"iframe" => array(
"container" => $container ? $container : "talkable-container",
"width" => $width ? $width : "100%",
"height" => $height ? $height : 960,
),
);
return number_format((float) $value, 2, ".", "");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Talkable_SocialReferrals_Model_Observer extends Mage_Core_Model_Abstract

public function customerDashboardLink(Varien_Event_Observer $observer)
{
if (Mage::helper("socialreferrals")->isDashboardEnabled()) {
if (Mage::helper("socialreferrals")->isAdvocateDashboardEnabled()) {
$observer->getEvent()->getLayout()->getUpdate()->addHandle("customer_dashboard_handle");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Talkable_SocialReferrals_Customer_DashboardController extends Mage_Core_Co

public function indexAction()
{
if (Mage::helper("socialreferrals")->isDashboardEnabled()) {
if (Mage::helper("socialreferrals")->isAdvocateDashboardEnabled()) {
$this->loadLayout();
$this->renderLayout();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Talkable_SocialReferrals_IndexController extends Mage_Core_Controller_Fron

public function indexAction()
{
if (Mage::helper("socialreferrals")->isAffiliateEnabled()) {
if (Mage::helper("socialreferrals")->isInviteEnabled()) {
$this->loadLayout();
$this->renderLayout();
} else {
Expand Down
32 changes: 8 additions & 24 deletions app/code/community/Talkable/SocialReferrals/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<config>
<modules>
<Talkable_SocialReferrals>
<version>0.1.8</version>
<version>1.0.0</version>
</Talkable_SocialReferrals>
</modules>

Expand Down Expand Up @@ -80,31 +80,15 @@
<socialreferrals>
<general>
<site_id></site_id>
<integration_js_url>//d2jjzw81hqbuqv.cloudfront.net/integration/talkable-1.0.min.js</integration_js_url>
<integration_js_url>//d2jjzw81hqbuqv.cloudfront.net/integration/talkable-2.1.min.js</integration_js_url>
</general>

<purchase>
<enabled>0</enabled>
<campaign_tags>post-purchase</campaign_tags>
</purchase>

<affiliate>
<enabled>0</enabled>
<campaign_tags>invite</campaign_tags>
<iframe_responsive>1</iframe_responsive>
<iframe_container>talkable-container</iframe_container>
<iframe_width>100%</iframe_width>
<iframe_height>960</iframe_height>
</affiliate>

<dashboard>
<enabled>0</enabled>
<campaign_tags>dashboard</campaign_tags>
<iframe_responsive>1</iframe_responsive>
<iframe_container>talkable-container</iframe_container>
<iframe_width>100%</iframe_width>
<iframe_height>960</iframe_height>
</dashboard>
<campaigns>
<post_purchase>0</post_purchase>
<invite>0</invite>
<advocate_dashboard>0</advocate_dashboard>
<floating_widget_popup>0</floating_widget_popup>
</campaigns>
</socialreferrals>
</default>
</config>
Loading

0 comments on commit 111f4ad

Please sign in to comment.