Skip to content
This repository was archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #238 from flagbit/feature/FFSD-59
Browse files Browse the repository at this point in the history
feature/FFSD-59
  • Loading branch information
mbraeuner authored Apr 23, 2019
2 parents e9fb726 + c5513d6 commit 49b9853
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/app/code/community/FACTFinder/Core/Helper/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class FACTFinder_Core_Helper_Export extends Mage_Core_Helper_Abstract
const EXPORT_IMAGE_TYPE = 'suggest_image_type';
const EXPORT_URLS_IMAGES = 'urls';
const EXPORT_URLS_IMAGES_CHILD = 'urls_child';
const EXPORT_BUNDLE_WITH_CHILD = 'suggest_export_bundle_with_child_attributes';
const OUT_OF_STOCK_PRODUCTS = 'out_of_stock_products';
const VALIDATION_DISABLED = 'disabled_validation';
const EXPLICIT_ATTRIBUTES = 'explicit_attributes';
Expand Down Expand Up @@ -351,6 +352,18 @@ public function shouldExportImagesOfChild($storeId = 0)
return $this->getExportConfigValue(self::EXPORT_URLS_IMAGES_CHILD, $storeId);
}

/**
* Check if child attributes of bundles should be exported
*
* @param int $storeId
*
* @return null|string
*/
public function shouldExportBundleWithChildAttributes($storeId = 0)
{
return $this->getExportConfigValue(self::EXPORT_BUNDLE_WITH_CHILD, $storeId);
}

/**
* Check if out of stock products should be exported
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ public function doExport($storeId = null)
Mage::app()->setCurrentStore($storeId);
}

$exportBundle = $this->getHelper()->shouldExportBundleWithChildAttributes($storeId);

$idFieldName = Mage::helper('factfinder/search')->getIdFieldName();

$header = $this->_getHeader($storeId);
Expand Down Expand Up @@ -314,13 +316,21 @@ public function doExport($storeId = null)
$productId = $productData['entity_id'];

$productAttributes = $attributeValues[$productId];

$categoryPath = $this->_getCategoryPath($productId, $storeId);

if ($categoryPath == '' && !$this->_isExportProductsWithoutCategories($storeId)) {
continue;
}

if($exportBundle && $productData['type_id'] == 'bundle' ) {
$productAttributes = $this->addAttributesOfBundledProducts(
$storeId,
$productData['entity_id'],
$dynamicFields,
$productAttributes
);
}

$productIndex = array(
$productId,
$productData[$idFieldName],
Expand All @@ -331,6 +341,8 @@ public function doExport($storeId = null)
$this->_formatAttributes('numerical', $productAttributes, $storeId),
);

$productAttributes = $attributeValues[$productId];

$productIndex = $this->_exportImage($productIndex, $productData, $storeId);
$productIndex[] = $this->getProductUrl($productData['entity_id'], $storeId);
$productIndex = $this->getAttributeModel()
Expand Down Expand Up @@ -752,4 +764,41 @@ public function isEnabled()
{
return true;
}

/**
* @param $storeId
* @param $entityId
* @param $dynamicFields
* @param $productAttributes
* @return mixed
*/
protected function addAttributesOfBundledProducts($storeId, $entityId, $dynamicFields, $productAttributes)
{
$bundledProduct = new Mage_Catalog_Model_Product();
$bundledProduct->load($entityId);

$selectionCollection = $bundledProduct->getTypeInstance(true)->getSelectionsCollection(
$bundledProduct->getTypeInstance(true)->getOptionsIds($bundledProduct), $bundledProduct
);

$bundledItemsIds = array();
foreach ($selectionCollection as $option) {
$bundledItemsIds[] = $option->getId();
}

$optionValues = $this->getAttributeModel()
->getProductAttributes($storeId, $bundledItemsIds, $dynamicFields);

foreach ($optionValues as $optionId => $optionAttributeValues) {
foreach ($optionAttributeValues as $optionAttributeId => $optionAttributeValue) {
if (!is_array($productAttributes[$optionAttributeId])) {
$productAttributes[$optionAttributeId] = array($productAttributes[$optionAttributeId]);
}
if (!in_array($optionAttributeValue, $productAttributes[$optionAttributeId])) {
array_push($productAttributes[$optionAttributeId], $optionAttributeValue);
}
}
}
return $productAttributes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Class FACTFinder_Core_Model_Export_Type_Product_Attribute
*
*
* @method FACTFinder_Core_Model_Resource_Attribute getResource()
*/
class FACTFinder_Core_Model_Export_Type_Product_Attribute extends Mage_Core_Model_Abstract
Expand Down Expand Up @@ -175,7 +175,15 @@ public function getAttributeValue($attributeId, $value, $storeId)
}

$attribute->setStoreId($storeId);
$value = $attribute->getSource()->getOptionText($value);
if(is_array($value)) {
foreach ($value as $k => $val) {
$value[$k] = $attribute->getSource()->getOptionText($val);
}
}
else {
$value = $attribute->getSource()->getOptionText($value);
}

if (!is_array($value) && empty($value)) {
$inputType = $attribute->getFrontend()->getInputType();
if ($inputType == 'select' || $inputType == 'multiselect') {
Expand Down
2 changes: 1 addition & 1 deletion src/app/code/community/FACTFinder/Core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<config>
<modules>
<FACTFinder_Core>
<version>4.2.2</version>
<version>4.2.3</version>
</FACTFinder_Core>
</modules>
<global>
Expand Down
1 change: 1 addition & 0 deletions src/app/code/community/FACTFinder/Suggest/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
</config>
<export>
<urls_child>0</urls_child>
<suggest_export_bundle_with_child_attributes>0</suggest_export_bundle_with_child_attributes>
<suggest_image_size>60</suggest_image_size>
</export>
</factfinder>
Expand Down
10 changes: 10 additions & 0 deletions src/app/code/community/FACTFinder/Suggest/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
<show_in_store>1</show_in_store>
<comment><![CDATA[This will export images of child products of configurable products]]></comment>
</urls_child>
<suggest_export_bundle_with_child_attributes translate="label comment">
<label>Export bundle with child attributes</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>8</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment><![CDATA[This will export images of child products of configurable products]]></comment>
</suggest_export_bundle_with_child_attributes>
<suggest_image_size translate="label comment">
<label>Size of Suggest images</label>
<comment>Please enter the desired edge length of the Suggest images in pixels. If you do not want them to be resized, enter 0.</comment>
Expand Down

0 comments on commit 49b9853

Please sign in to comment.