Created
July 23, 2015 11:52
-
-
Save WENKz/046b1765c85ec6b0a63e to your computer and use it in GitHub Desktop.
qty_increments_export.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('memory_limit','2048M'); | |
error_reporting(E_ALL | E_STRICT); | |
define('MAGENTO_ROOT', getcwd()); | |
$mageFilename = MAGENTO_ROOT . '/app/Mage.php'; | |
require_once $mageFilename; | |
Mage::setIsDeveloperMode(true); | |
ini_set('display_errors', 1); | |
Mage::app(); | |
$visibility = array( | |
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, | |
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG | |
); | |
// var_dump($storeId); | |
$products = Mage::getModel('catalog/product')->getCollection()->setStoreId(1) | |
->addAttributeToSelect("name") | |
->addAttributeToSelect("sku") | |
->addAttributeToSelect("*") | |
->addAttributeToFilter('type_id', 'bundle') | |
->addStoreFilter(1) | |
->addAttributeToFilter('visibility', $visibility); | |
foreach ($products as $_product) { | |
$data = getQty($_product); | |
echo $_product->getSku()."_".$_product->getName()."_".$data["enable_qty_increments"]."_".$data["qty_increments"]."<br/>"; | |
} | |
function getQty($_product){ | |
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product); | |
return $stock->getData(); | |
} | |
function getPriceRange($product) { | |
$totalPrice= array(); | |
//get all configurable attributes | |
$attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product); | |
//array to keep the price differences for each attribute value | |
$pricesByAttributeValues = array(); | |
//base price of the configurable product | |
$basePrice = $product->getFinalPrice(); | |
//loop through the attributes and get the price adjustments specified in the configurable product admin page | |
foreach ($attributes as $attribute){ | |
$prices = $attribute->getPrices(); | |
foreach ($prices as $price){ | |
if ($price['is_percent']){ //if the price is specified in percents | |
$pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100; | |
} | |
else { //if the price is absolute value | |
$pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value']; | |
} | |
} | |
} | |
//get all simple products | |
$simple = $product->getTypeInstance()->getUsedProducts(); | |
//loop through the products | |
foreach ($simple as $sProduct){ | |
/*$totalPrice = $basePrice;*/ | |
//loop through the configurable attributes | |
foreach ($attributes as $attribute){ | |
//get the value for a specific attribute for a simple product | |
$value = $sProduct->getData($attribute->getProductAttribute()->getAttributeCode()); | |
//add the price adjustment to the total price of the simple product | |
if (isset($pricesByAttributeValues[$value])){ | |
array_push( $totalPrice,$pricesByAttributeValues[$value]); | |
} | |
} | |
//in $totalPrice you should have now the price of the simple product | |
//do what you want/need with it | |
} | |
return $totalPrice; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment