Skip to content

Commit

Permalink
Merge pull request #33 from Affirm/dev_v3.5
Browse files Browse the repository at this point in the history
Dev v3.5
  • Loading branch information
nandadubey authored Oct 5, 2017
2 parents 0239519 + 0ec8a5b commit ece7aae
Show file tree
Hide file tree
Showing 21 changed files with 303 additions and 153 deletions.
1 change: 0 additions & 1 deletion DEVELOPER-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ This project uses semantic versioning. When updating the extension, bump the
version in the following locations:

1. extension/app/code/community/Affirm/Affirm/etc/config.xml
1. extension/app/code/community/Affirm/AffirmPromo/etc/config.xml
1. build/affirm_tar_to_connect_config.php

To avoid drift, validate by executing `make validate_version`
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.4.0.tgz *
cd ./extension && tar -cvf ../var/Affirm_Affirm-3.5.0.tgz *
cd ./build && ./magento-tar-to-connect.phar affirm_tar_to_connect_config.php

clean:
Expand Down
6 changes: 3 additions & 3 deletions build/affirm_tar_to_connect_config.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
return array(
'base_dir' => realpath('../var/'),
'archive_files' => 'Affirm_Affirm-3.4.1.tgz',
'archive_files' => 'Affirm_Affirm-3.5.0.tgz',
'extension_name' => 'Affirm_Magento',
'skip_version_compare' => true,
'extension_version' => '3.4.1',
'archive_connect' => 'Affirm_Affirm-3.4.1.tgz',
'extension_version' => '3.5.0',
'archive_connect' => 'Affirm_Affirm-3.5.0.tgz',
'path_output' => realpath('../var/'),

'stability' => 'stable',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function getPriceHtml($product, $displayMinimalPrice = false, $idSuffix =
$mpp = $this->_getMinMPP();

$price = $product->getFinalPrice();
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
$price = Mage::getModel('bundle/product_price')->getTotalPrices($product,'min',1);
} else if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
$price = $product->getMinimalPrice();
}
if ($price > $mpp) {
$categoryIds = $product->getCategoryIds();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ protected function _toHtml()

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

return parent::_toHtml();
}

Expand All @@ -52,15 +51,67 @@ public function getProduct()
return $this->helper('catalog')->getProduct();
}

/**
* Get product id on PDP
*
* @return Mage_Catalog_Model_Product|null
*/
public function getProductId()
{
return $this->helper('catalog')->getProduct()->getId();
}

/**
* Get final price
*
* @return int
*/
public function getFinalPrice()
{
$price = $this->getProduct()->getFinalPrice();
return $this->helper('affirm/util')->formatCents($price);
$product = $this->getProduct();
if($product->getFinalPrice()) {
return $this->helper('affirm/util')->formatCents($product->getFinalPrice());
} else if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) {
$grouped_product_model = Mage::getModel('catalog/product_type_grouped');
$groupedParentId = $grouped_product_model->getParentIdsByChild($product->getId());
$_associatedProducts = $product->getTypeInstance(true)->getAssociatedProducts($product);

foreach($_associatedProducts as $_associatedProduct) {
if($price = $_associatedProduct->getPrice()) {
$price = $_associatedProduct->getPrice();
}
}

$price = number_format((float)$price, 2, '.', '');
return $this->helper('affirm/util')->formatCents($price);
} else if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
$optionCol= $product->getTypeInstance(true)
->getOptionsCollection($product);
$selectionCol= $product->getTypeInstance(true)
->getSelectionsCollection(
$product->getTypeInstance(true)->getOptionsIds($product),
$product
);
$optionCol->appendSelections($selectionCol);
$price = $product->getPrice();

foreach ($optionCol as $option) {
if($option->required) {
$selections = $option->getSelections();
$minPrice = min(array_map(function ($s) {
return $s->price;
}, $selections));
if($product->getSpecialPrice() > 0) {
$minPrice *= $product->getSpecialPrice()/100;
}

$price += round($minPrice,2);
}
}
return $this->helper('affirm/util')->formatCents($price);
} else {
return "";
}
}

/**
Expand Down
133 changes: 122 additions & 11 deletions extension/app/code/community/Affirm/Affirm/Block/Promo/Promo.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,139 @@ protected function _construct()
}

/**
* Get snippet code
* Get product on PDP
*
* @return Mage_Catalog_Model_Product|null
*/
public function getProduct()
{
return $this->helper('catalog')->getProduct();
}

/**
* Get MFP value
*
* @return string
*/
public function getMFPValue()
{
$currentController = Mage::app()->getFrontController()->getRequest()->getControllerName();
$mfpHelper = Mage::helper('affirm/mfp');
switch($currentController) {
case 'product':
return $this->getProductMFPValue();
break;
case 'category':
$categoryId = Mage::registry('current_category')->getId();
$categoryIds = array();
$categoryIds[] = $categoryId;
return $this->helper('affirm/promo_asLowAs')->getAffirmMFPValue(array(), $categoryIds);
break;
case 'cart':
return $this->getCheckoutMFPValue();
break;
default:
if ($mfpHelper->isMFPValidCurrentDateALS()) {
return $mfpHelper->getPromoIdDateRange();
} else {
return $mfpHelper->getPromoIdDefault();
}
break;
}
}

/**
* Get Product MFP value
*
* @return string
*/
public function getProductMFPValue()
{
$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);
}

/**
* Get html code for promo snippet
* Get Cart MFP value
*
* @return string
*/
public function getSnippetCode()
public function getCheckoutMFPValue()
{
if (!$this->_helper->isPromoActive() || !$this->_helper->getSectionConfig()->getDisplay()) {
return '';
$cart = Mage::getModel('checkout/cart')->getQuote();
$productIds = array();
$productItemMFP = array();
$categoryItemsIds = array();
$categoryIds = array();
foreach ($cart->getAllVisibleItems() as $item) {
$productIds[] = $item->getProduct()->getId();
}
if($productIds) {
$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;
}

$sectionConfig = $this->_helper->getSectionConfig();
$container = $sectionConfig->getContainer();
$snippet = $this->getChildHtml('affirmpromo_snippet');
$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 = "";
}
}

if (!empty($container)) {
$snippet = str_replace('{container}', $snippet, $container);
$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 $snippet;

return Mage::helper('affirm/promo_asLowAs')->getAffirmMFPValue($productItemMFP, $categoryIds, $this->helper('checkout/cart')->getQuote()->getGrandTotal());
}
}
Loading

0 comments on commit ece7aae

Please sign in to comment.