예제 #1
0
 public function createIndexData(Mage_Catalog_Model_Product $object, Mage_Eav_Model_Entity_Attribute_Abstract $attribute = null)
 {
     $data = array();
     $data['store_id'] = $attribute->getStoreId();
     $data['entity_id'] = $object->getId();
     $data['attribute_id'] = $attribute->getId();
     $result = array();
     $values = $object->getData($attribute->getAttributeCode());
     if (!is_array($values)) {
         return $result;
     }
     foreach ($values as $row) {
         if (isset($row['delete']) && $row['delete']) {
             continue;
         }
         $data['qty'] = $row['price_qty'];
         $data['value'] = $row['price'];
         if ($row['cust_group'] == Mage_Customer_Model_Group::CUST_GROUP_ALL) {
             foreach ($this->_customerGroups as $group) {
                 $data['customer_group_id'] = $group->getId();
                 $result[] = $data;
             }
         } else {
             $data['customer_group_id'] = $row['cust_group'];
             $result[] = $data;
         }
     }
     return $result;
 }
예제 #2
0
 public function createIndexData(Mage_Catalog_Model_Product $object, Mage_Eav_Model_Entity_Attribute_Abstract $attribute = null)
 {
     $data = array();
     $data['store_id'] = $attribute->getStoreId();
     $data['entity_id'] = $object->getId();
     $data['attribute_id'] = $attribute->getId();
     $data['value'] = $object->getData($attribute->getAttributeCode());
     if ($attribute->getFrontendInput() == 'multiselect') {
         $origData = $data;
         $data = array();
         $value = explode(',', $origData['value']);
         foreach ($value as $item) {
             $row = $origData;
             $row['value'] = $item;
             $data[] = $row;
         }
     }
     //return $this->_spreadDataForStores($object, $attribute, $data);
     return $data;
 }
예제 #3
0
파일: Price.php 프로젝트: quyip8818/Mag
 public function createIndexData(Mage_Catalog_Model_Product $object, Mage_Eav_Model_Entity_Attribute_Abstract $attribute = null)
 {
     $data = array();
     $data['store_id'] = $attribute->getStoreId();
     $data['entity_id'] = $object->getId();
     $data['attribute_id'] = $attribute->getId();
     $data['value'] = $object->getData($attribute->getAttributeCode());
     if ($attribute->getAttributeCode() == 'price') {
         $result = array();
         foreach ($this->_customerGroups as $group) {
             $object->setCustomerGroupId($group->getId());
             $finalPrice = $object->getFinalPrice();
             $row = $data;
             $row['customer_group_id'] = $group->getId();
             $row['value'] = $finalPrice;
             $result[] = $row;
         }
         return $result;
     }
     return $data;
 }
예제 #4
0
 /**
  * Save Options prices (Depends from price save scope)
  *
  * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
  * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute
  */
 public function savePrices($attribute)
 {
     $newValues = $attribute->getValues();
     $oldValues = array();
     $valueIndexes = array();
     $select = $this->_getWriteAdapter()->select()->from($this->_priceTable)->where('product_super_attribute_id=?', $attribute->getId());
     $query = $this->_getWriteAdapter()->query($select);
     while ($row = $query->fetch()) {
         $key = join('-', array($row['website_id'], $row['value_index']));
         $oldValues[$key] = $row;
     }
     $delete = array();
     $insert = array();
     $update = array();
     foreach ($newValues as $value) {
         $valueIndexes[$value['value_index']] = $value['value_index'];
     }
     if ($this->getCatalogHelper()->isPriceGlobal()) {
         foreach ($oldValues as $row) {
             if (!isset($valueIndexes[$row['value_index']])) {
                 $delete[] = $row['value_id'];
                 continue;
             }
         }
         foreach ($newValues as $value) {
             $valueObject = new Varien_Object($value);
             $key = join('-', array(0, $value['value_index']));
             $pricingValue = $valueObject->getPricingValue();
             if ($pricingValue == '' || is_null($pricingValue)) {
                 $pricingValue = null;
             } else {
                 $pricingValue = Mage::app()->getLocale()->getNumber($pricingValue);
             }
             // update
             if (isset($oldValues[$key])) {
                 $oldValue = $oldValues[$key];
                 $update[$oldValue['value_id']] = array('pricing_value' => $pricingValue, 'is_percent' => intval($valueObject->getIsPercent()));
             } else {
                 if (!empty($value['pricing_value'])) {
                     $insert[] = array('product_super_attribute_id' => $attribute->getId(), 'value_index' => $valueObject->getValueIndex(), 'is_percent' => intval($valueObject->getIsPercent()), 'pricing_value' => $pricingValue, 'website_id' => 0);
                 }
             }
         }
     } else {
         $websiteId = Mage::app()->getStore($attribute->getStoreId())->getWebsiteId();
         foreach ($oldValues as $row) {
             if (!isset($valueIndexes[$row['value_index']])) {
                 $delete[] = $row['value_id'];
                 continue;
             }
         }
         foreach ($newValues as $value) {
             $valueObject = new Varien_Object($value);
             $key = join('-', array($websiteId, $value['value_index']));
             $pricingValue = $valueObject->getPricingValue();
             if ($pricingValue == '' || is_null($pricingValue)) {
                 $pricingValue = null;
             } else {
                 $pricingValue = Mage::app()->getLocale()->getNumber($pricingValue);
             }
             // update
             if (isset($oldValues[$key])) {
                 $oldValue = $oldValues[$key];
                 if ($websiteId && $valueObject->getUseDefaultValue()) {
                     $delete[] = $oldValue['value_id'];
                 } else {
                     $update[$oldValue['value_id']] = array('pricing_value' => $pricingValue, 'is_percent' => intval($valueObject->getIsPercent()));
                 }
             } else {
                 if ($websiteId && $valueObject->getUseDefaultValue()) {
                     continue;
                 }
                 $insert[] = array('product_super_attribute_id' => $attribute->getId(), 'value_index' => $valueObject->getValueIndex(), 'is_percent' => intval($valueObject->getIsPercent()), 'pricing_value' => $pricingValue, 'website_id' => $websiteId);
             }
             $key = join('-', array(0, $value['value_index']));
             if (!isset($oldValues[$key])) {
                 $insert[] = array('product_super_attribute_id' => $attribute->getId(), 'value_index' => $valueObject->getValueIndex(), 'is_percent' => 0, 'pricing_value' => null, 'website_id' => 0);
             }
         }
     }
     if (!empty($delete)) {
         $where = $this->_getWriteAdapter()->quoteInto('value_id IN(?)', $delete);
         $this->_getWriteAdapter()->delete($this->_priceTable, $where);
     }
     if (!empty($update)) {
         foreach ($update as $valueId => $valueData) {
             $where = $this->_getWriteAdapter()->quoteInto('value_id=?', $valueId);
             $this->_getWriteAdapter()->update($this->_priceTable, $valueData, $where);
         }
     }
     if (!empty($insert)) {
         foreach ($insert as $valueData) {
             $this->_getWriteAdapter()->insert($this->_priceTable, $valueData);
         }
     }
     return $this;
 }