Skip to content

Commit

Permalink
New Version 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
diptib10 committed Apr 25, 2017
1 parent 2765e3d commit a04aada
Show file tree
Hide file tree
Showing 29 changed files with 1,838 additions and 535 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:

package: validate_version
mkdir -p ./var/
cd ./extension && tar -cvf ../var/Affirm_Affirm-3.1.0.tgz *
cd ./extension && tar -cvf ../var/Affirm_Affirm-3.4.0.tgz *
cd ./build && ./magento-tar-to-connect.phar affirm_tar_to_connect_config.php

clean:
Expand Down
34 changes: 11 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![](docs/splash.png)](https://affirm.com)
[![](docs/splash.png)](https://affirm.com)

**Compatible with**

Expand Down Expand Up @@ -57,7 +57,12 @@ modman update Magento_Affirm
2. Copy to MAGENTO_ROOT
3. To install, run `make install`
4. To update, run `make update`


####To install using [magento-composer-installer](https://github.com/Cotya/magento-composer-installer)
```
composer require affirm/affirm-php
```

####Known Issue with SSH installation
If you are upgrading from 2.x to 3.x version of the extension via SSH, double promo banners may be displayed.
To fix the issue, remove the following to from the Magento directory:
Expand All @@ -68,31 +73,14 @@ MAGENTO_ROOT/app/design/frontend/base/default/template: affirmpromo
MAGENTO_ROOT/app/etc/modules: Affirm_AffirmPromo.xml
MAGENTO_ROOT/lib: Affirm
```



Configure
---------

**Payment Method**

1. Log in to your Magento Admin portal.
2. Visit System > Cache Management. Then, click _Flush Magento Cache_
2. Visit System > Configuration > Sales > Payment Methods > Affirm
3. Set the API URL. In a test environment, use ```https://sandbox.affirm.com```. On your live site, use ```https://api.affirm.com```.
4. Provide your 3 keys (merchant API key, secret key, financial product key)
5. Adjust the order total minimum and maximum options to control when Affirm is
shown to your customers.

![](docs/config.png)

**Promos**

1. Visit System > Configuration > Affirm Promos (under General)
2. Set the Promo Key and enable the extension.
3. (optional) Customize the size and position of your promos.

![](docs/promo-config.png)
Visit https://docs.affirm.com/Integrate_Affirm/Platform_Integration/Magento_Integration#configure_the_affirm payment_method for details


Developers
----------
Expand Down
75 changes: 75 additions & 0 deletions extension/app/code/community/Affirm/Affirm/Block/Product/List.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* OnePica
* NOTICE OF LICENSE
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Affirm
* @package Affirm_Affirm
* @copyright Copyright (c) 2014 One Pica, Inc. (http://www.onepica.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Affirm_Affirm_Block_Product_List extends Mage_Catalog_Block_Product_List
{
private $_minMPP = null;

private function _getMinMPP()
{
if($this->_minMPP == null) {
$this->_minMPP = $this->helper('affirm/promo_asLowAs')->getMinMPP();
if(empty($this->_minMPP)) {
$this->_minMPP = 0;
}
}

return $this->_minMPP;
}

public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix = '')
{
$html = parent::getPriceHtml($product, $product, $idSuffix);

if ($this->helper('affirm/promo_asLowAs')->isAsLowAsDisabledOnPLP()) {
return $html;
}

$mpp = $this->_getMinMPP();

$price = $product->getFinalPrice();
if ($price > $mpp) {
$categoryIds = $product->getCategoryIds();

$start_date = $product->getAffirmProductMfpStartDate();
$end_date = $product->getAffirmProductMfpEndDate();
if(empty($start_date) || empty($end_date)) {
$mfpValue = $product->getAffirmProductPromoId();
} else {
if(Mage::app()->getLocale()->isStoreDateInInterval(null, $start_date, $end_date)) {
$mfpValue = $product->getAffirmProductPromoId();
} else {
$mfpValue = "";
}
}

$productItemMFP = array(
'value' => $mfpValue,
'type' => $product->getAffirmProductMfpType(),
'priority' => $product->getAffirmProductMfpPriority() ?
$product->getAffirmProductMfpPriority() : 0
);

$mfpValue = $this->helper('affirm/promo_asLowAs')->getAffirmMFPValue(array($productItemMFP), $categoryIds);

$html .= '<div class="affirm-as-low-as" ' . (!empty($mfpValue) ? 'data-promo-id="' . $mfpValue . '"' : '') . ' data-amount="' . $this->helper('affirm/util')->formatCents($price) .'"></div>';
}

return $html;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ protected function _toHtml()
if ($this->helper('affirm/promo_asLowAs')->isAsLowAsDisabledOnCheckout()) {
return "";
}

$mpp = $this->helper('affirm/promo_asLowAs')->getMinMPP();
if (!empty($mpp)) {
if ($this->helper('checkout/cart')->getQuote()->getGrandTotal() < $mpp) {
return "";
}
}

return parent::_toHtml();
}

Expand All @@ -44,4 +52,64 @@ public function getCheckoutGrandTotal()
$total = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
return $this->helper('affirm/util')->formatCents($total);
}

/**
* Get MFP value
*
* @return string
*/
public function getMFPValue()
{
$cart = Mage::getModel('checkout/cart')->getQuote();
$productIds = array();
$productItemMFP = array();
$categoryItemsIds = array();
foreach ($cart->getAllVisibleItems() as $item) {
$productIds[] = $item->getProduct()->getId();
}

$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect(
array('affirm_product_promo_id', 'affirm_product_mfp_type', 'affirm_product_mfp_priority')
)
->addAttributeToFilter('entity_id', array('in' => $productIds));
$productItems = $products->getItems();

foreach ($cart->getAllVisibleItems() as $item) {
$product = $productItems[$item->getProduct()->getId()];
if (Mage::helper('affirm')->isPreOrder() && $item->getProduct()->getParentItem() &&
($item->getProduct()->getParentItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
) {
continue;
}

$start_date = $product->getAffirmProductMfpStartDate();
$end_date = $product->getAffirmProductMfpEndDate();
if(empty($start_date) || empty($end_date)) {
$mfpValue = $product->getAffirmProductPromoId();
} else {
if(Mage::app()->getLocale()->isStoreDateInInterval(null, $start_date, $end_date)) {
$mfpValue = $product->getAffirmProductPromoId();
} else {
$mfpValue = "";
}
}

$productItemMFP[] = array(
'value' => $mfpValue,
'type' => $product->getAffirmProductMfpType(),
'priority' => $product->getAffirmProductMfpPriority() ?
$product->getAffirmProductMfpPriority() : 0
);

$categoryIds = $product->getCategoryIds();
if (!empty($categoryIds)) {
$categoryItemsIds = array_merge($categoryItemsIds, $categoryIds);
}
}

$categoryIds = $product->getCategoryIds();

return Mage::helper('affirm/promo_asLowAs')->getAffirmMFPValue($productItemMFP, $categoryIds, $this->helper('checkout/cart')->getQuote()->getGrandTotal());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ protected function _toHtml()
if ($this->helper('affirm/promo_asLowAs')->isAsLowAsDisabledOnPDP()) {
return "";
}

$mpp = $this->helper('affirm/promo_asLowAs')->getMinMPP();
if (!empty($mpp)) {
if ($this->getProduct()->getFinalPrice() < $mpp) {
return "";
}
}

return parent::_toHtml();
}

Expand All @@ -54,4 +62,37 @@ public function getFinalPrice()
$price = $this->getProduct()->getFinalPrice();
return $this->helper('affirm/util')->formatCents($price);
}

/**
* Get MFP value
*
* @return string
*/
public function getMFPValue()
{
$product = $this->getProduct();

$categoryIds = $product->getCategoryIds();

$start_date = $product->getAffirmProductMfpStartDate();
$end_date = $product->getAffirmProductMfpEndDate();
if(empty($start_date) || empty($end_date)) {
$mfpValue = $product->getAffirmProductPromoId();
} else {
if(Mage::app()->getLocale()->isStoreDateInInterval(null, $start_date, $end_date)) {
$mfpValue = $product->getAffirmProductPromoId();
} else {
$mfpValue = "";
}
}

$productItemMFP = array(
'value' => $mfpValue,
'type' => $product->getAffirmProductMfpType(),
'priority' => $product->getAffirmProductMfpPriority() ?
$product->getAffirmProductMfpPriority() : 0
);

return $this->helper('affirm/promo_asLowAs')->getAffirmMFPValue(array($productItemMFP), $categoryIds);
}
}
14 changes: 12 additions & 2 deletions extension/app/code/community/Affirm/Affirm/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ class Affirm_Affirm_Helper_Data extends Mage_Core_Helper_Abstract
*/
protected $_disabledBackOrderedPdp;

/**
* Returns extension version
*
* @return string
*/
public function getExtensionVersion()
{
return (string)Mage::getConfig()->getNode()->modules->Affirm_Affirm->version;
}

/**
* Returns is disable for back ordered items
*
Expand Down Expand Up @@ -152,9 +162,9 @@ public function getModuleConfigVersion()
* @param Mage_Core_Model_Store $store
* @return string
*/
public function getApiUrl($store = null)
public function getApiUrl()
{
return Mage::getSingleton('affirm/credential')->getApiUrl($store);
return Mage::getSingleton('affirm/credential')->getApiUrl();
}

/**
Expand Down
Loading

0 comments on commit a04aada

Please sign in to comment.