Skip to content

Commit

Permalink
Adicionada opção de configurar os atributos do catálogo
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelpatro committed Aug 28, 2017
1 parent 1d10a8b commit e6f97a0
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 15 deletions.
23 changes: 13 additions & 10 deletions app/code/community/Quack/TntBrasil/Model/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ protected function _getProductAttribute($product, $attribute)
protected function _getFitHeight($item)
{
$product = $item->getProduct();
$height = $this->_getProductAttribute($product, 'volume_altura');
$fitSize = (float) $this->_getProductAttribute($product, 'fit_size');
$height = $this->_getProductAttribute($product, $this->getConfigData('attribute_height'));
$fitSize = (float) $this->_getProductAttribute($product, $this->getConfigData('attribute_fitsize'));

if ($item->getQty() > 1 && is_numeric($fitSize) && $fitSize > 0) {
$totalSize = $height + ($fitSize * ($item->getQty() - 1));
Expand All @@ -162,10 +162,10 @@ protected function _getFitHeight($item)
protected function _setFitItem($item)
{
$product = $item->getProduct();
$height = $this->_getProductAttribute($product, 'volume_altura');
$width = $this->_getProductAttribute($product, 'volume_largura');
$length = $this->_getProductAttribute($product, 'volume_comprimento');
$fitSize = $this->_getProductAttribute($product, 'fit_size');
$height = $this->_getProductAttribute($product, $this->getConfigData('attribute_height'));
$width = $this->_getProductAttribute($product, $this->getConfigData('attribute_width'));
$length = $this->_getProductAttribute($product, $this->getConfigData('attribute_length'));
$fitSize = $this->_getProductAttribute($product, $this->getConfigData('attribute_fitsize'));
$weight = $product->getWeight();
if (!(empty($fitSize) || empty($height) || empty($width) || empty($length))) {
$itemKey = "{$height}_{$width}_{$length}_{$fitSize}_{$weight}";
Expand Down Expand Up @@ -283,14 +283,17 @@ public function getPackageSize(Mage_Shipping_Model_Rate_Request $request)
if ($_product = $item->getProduct()) {
$_product->load($_product->getId());

$itemAltura = $this->_getProductAttribute($_product, 'volume_altura');
$itemLargura = $this->_getProductAttribute($_product, 'volume_largura');
$itemComprimento = $this->_getProductAttribute($_product, 'volume_comprimento');
$itemAltura = $this->_getProductAttribute($_product, $this->getConfigData('attribute_height'));
$itemLargura = $this->_getProductAttribute($_product, $this->getConfigData('attribute_width'));
$itemComprimento = $this->_getProductAttribute($_product, $this->getConfigData('attribute_length'));

$itemAltura = $this->_getFitHeight($item);
$volumeWeight += ($itemAltura * $itemLargura * $itemComprimento * $item->getTotalQty());

$this->_postingDays = max($this->_postingDays, (int) $this->_getProductAttribute($_product, 'posting_days'));
$this->_postingDays = max(
$this->_postingDays,
(int) $this->_getProductAttribute($_product, $this->getConfigData('attribute_postingdays'))
);
$this->_setFitItem($item);
}
}
Expand Down
59 changes: 59 additions & 0 deletions app/code/community/Quack/TntBrasil/Model/Source/Attribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Este arquivo é parte do programa Quack TntBrasil
*
* Quack TntBrasil é um software livre; você pode redistribuí-lo e/ou
* modificá-lo dentro dos termos da Licença Pública Geral GNU como
* publicada pela Fundação do Software Livre (FSF); na versão 3 da
* Licença, ou (na sua opinião) qualquer versão.
*
* Este programa é distribuído na esperança de que possa ser útil,
* mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO
* a qualquer MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença
* Pública Geral GNU para maiores detalhes.
*
* Você deve ter recebido uma cópia da Licença Pública Geral GNU junto
* com este programa, Se não, veja <http://www.gnu.org/licenses/>.
*
* @category Quack
* @package Quack_TntBrasil
* @author Rafael Patro <rafaelpatro@gmail.com>
* @copyright Copyright (c) 2017 Rafael Patro (rafaelpatro@gmail.com)
* @license http://www.gnu.org/licenses/gpl.txt
* @link https://github.com/rafaelpatro/Quack_TntBrasil
*/

class Quack_TntBrasil_Model_Source_Attribute extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
public function toOptionArray()
{
$optionArray = array(
array('value' => '', 'label' => Mage::helper('adminhtml')->__('Select'))
);
$collection = Mage::getResourceSingleton('catalog/product_attribute_collection');
/* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
foreach ($collection as $attribute) {
$code = $attribute->getAttributeCode();
$label = $attribute->getFrontendLabel();
if (empty($label)) {
$label = $code;
} else {
$label.= " ({$code})";
}
$optionArray[] = array(
'value' => $code,
'label' => $label,
);
}
return $optionArray;
}

/**
* (non-PHPdoc)
* @see Mage_Eav_Model_Entity_Attribute_Source_Interface::getAllOptions()
*/
public function getAllOptions()
{
return self::toOptionArray();
}
}
7 changes: 6 additions & 1 deletion app/code/community/Quack/TntBrasil/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<config>
<modules>
<Quack_TntBrasil>
<version>0.0.1</version>
<version>1.0.0</version>
</Quack_TntBrasil>
</modules>
<global>
Expand Down Expand Up @@ -109,6 +109,11 @@
<free_shipping_enable>0</free_shipping_enable>
<posting_days_increment>1</posting_days_increment>
<timeout>10</timeout>
<attribute_height>volume_altura</attribute_height>
<attribute_width>volume_largura</attribute_width>
<attribute_length>volume_comprimento</attribute_length>
<attribute_fitsize>fit_size</attribute_fitsize>
<attribute_postingdays>posting_days</attribute_postingdays>
</tntbrasil>
</carriers>
</default>
Expand Down
53 changes: 49 additions & 4 deletions app/code/community/Quack/TntBrasil/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,64 @@
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</allowed_zips>
<attribute_height translate="label">
<label>Atributo Altura</label>
<frontend_type>select</frontend_type>
<source_model>tntbrasil/source_attribute</source_model>
<sort_order>240</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</attribute_height>
<attribute_width translate="label">
<label>Atributo Largura</label>
<frontend_type>select</frontend_type>
<source_model>tntbrasil/source_attribute</source_model>
<sort_order>250</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</attribute_width>
<attribute_length translate="label">
<label>Atributo Comprimento</label>
<frontend_type>select</frontend_type>
<source_model>tntbrasil/source_attribute</source_model>
<sort_order>260</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</attribute_length>
<attribute_fitsize translate="label">
<label>Atributo Diferença de Encaixe</label>
<frontend_type>select</frontend_type>
<source_model>tntbrasil/source_attribute</source_model>
<sort_order>270</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</attribute_fitsize>
<attribute_postingdays translate="label">
<label>Atributo Prazo de Postagem</label>
<frontend_type>select</frontend_type>
<source_model>tntbrasil/source_attribute</source_model>
<sort_order>280</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</attribute_postingdays>
<debug translate="label">
<label>Debug</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>240</sort_order>
<sort_order>290</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</debug>
<showmethod translate="label">
<label>Show Method if Not Applicable</label>
<frontend_type>select</frontend_type>
<sort_order>250</sort_order>
<sort_order>300</sort_order>
<source_model>adminhtml/system_config_source_yesno</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
Expand All @@ -277,15 +322,15 @@
<specificerrmsg translate="label">
<label>Displayed Error Message</label>
<frontend_type>textarea</frontend_type>
<sort_order>260</sort_order>
<sort_order>310</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</specificerrmsg>
<sort_order translate="label">
<label>Sort Order</label>
<frontend_type>text</frontend_type>
<sort_order>270</sort_order>
<sort_order>320</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
Expand Down

0 comments on commit e6f97a0

Please sign in to comment.