/** * After Save Attribute manipulation * * @param Mage_Catalog_Model_Product $object * @return Mage_Catalog_Model_Product_Attribute_Backend_Groupprice_Abstract */ public function afterSave($object) { $websiteId = Mage::app()->getStore($object->getStoreId())->getWebsiteId(); $isGlobal = $this->getAttribute()->isScopeGlobal() || $websiteId == 0; $groupRows = $object->getData($this->getAttribute()->getName()); if (empty($groupRows)) { $this->_getResource()->deleteGroupData($object->getId()); return $this; } $old = array(); $new = array(); $origGroupRows = $object->getOrigData($this->getAttribute()->getName()); if (!is_array($origGroupRows)) { $origGroupRows = array(); } foreach ($origGroupRows as $data) { if ($data['website_id'] > 0 || $data['website_id'] == '0' && $isGlobal) { $key = join('-', array_merge(array($data['website_id'], $data['cust_group']), $this->_getAdditionalUniqueFields($data))); $old[$key] = $data; } } // prepare data for save foreach ($groupRows as $data) { $hasEmptyData = false; foreach ($this->_getAdditionalUniqueFields($data) as $field) { if (empty($field)) { $hasEmptyData = true; break; } } if ($hasEmptyData || !isset($data['cust_group']) || !empty($data['delete'])) { continue; } if ($this->getAttribute()->isScopeGlobal() && $data['website_id'] > 0) { continue; } if (!$isGlobal && (int) $data['website_id'] == 0) { continue; } if (!isset($data['website_id'])) { $data['website_id'] = 0; } $key = join('-', array_merge(array($data['website_id'], $data['cust_group']), $this->_getAdditionalUniqueFields($data))); $useForAllGroups = $data['cust_group'] == Mage_Customer_Model_Group::CUST_GROUP_ALL; $customerGroupId = !$useForAllGroups ? $data['cust_group'] : 0; $new[$key] = array_merge(array('website_id' => $data['website_id'], 'all_groups' => $useForAllGroups ? 1 : 0, 'customer_group_id' => $customerGroupId, 'value' => $data['value']), $this->_getAdditionalUniqueFields($data)); } $delete = array_diff_key($old, $new); $insert = array_diff_key($new, $old); $update = array_intersect_key($new, $old); $isChanged = false; $productId = $object->getId(); if (!empty($delete)) { foreach ($delete as $data) { $this->_getResource()->deleteGroupData($productId, null, $data['group_id']); $isChanged = true; } } if (!empty($insert)) { foreach ($insert as $data) { $group = new Varien_Object($data); $group->setEntityId($productId); $this->_getResource()->saveGroupData($group); $isChanged = true; } } if (!empty($update)) { foreach ($update as $k => $v) { if ($old[$k]['value'] != $v['value']) { $group = new Varien_Object(array('value_id' => $old[$k]['value_id'], 'value' => $v['value'])); $this->_getResource()->saveGroupData($group); $isChanged = true; } } } if ($isChanged) { $valueChangedKey = $this->getAttribute()->getName() . '_changed'; $object->setData($valueChangedKey, 1); } /*$websiteId = Mage::app()->getStore($object->getStoreId())->getWebsiteId(); $isGlobal = $this->getAttribute()->isScopeGlobal() || $websiteId == 0; $priceRows = $object->getData($this->getAttribute()->getName()); if (empty($priceRows)) { if ($isGlobal) { $this->_getResource()->deletePriceData($object->getId()); } else { $this->_getResource()->deletePriceData($object->getId(), $websiteId); } return $this; } $old = array(); $new = array(); // prepare original data for compare $origGroupPrices = $object->getOrigData($this->getAttribute()->getName()); if (!is_array($origGroupPrices)) { $origGroupPrices = array(); } foreach ($origGroupPrices as $data) { if ($data['website_id'] > 0 || ($data['website_id'] == '0' && $isGlobal)) { $key = join('-', array_merge( array($data['website_id'], $data['cust_group']), $this->_getAdditionalUniqueFields($data) )); $old[$key] = $data; } } // prepare data for save foreach ($priceRows as $data) { $hasEmptyData = false; foreach ($this->_getAdditionalUniqueFields($data) as $field) { if (empty($field)) { $hasEmptyData = true; break; } } if ($hasEmptyData || !isset($data['cust_group']) || !empty($data['delete'])) { continue; } if ($this->getAttribute()->isScopeGlobal() && $data['website_id'] > 0) { continue; } if (!$isGlobal && (int)$data['website_id'] == 0) { continue; } $key = join('-', array_merge( array($data['website_id'], $data['cust_group']), $this->_getAdditionalUniqueFields($data) )); $useForAllGroups = $data['cust_group'] == Mage_Customer_Model_Group::CUST_GROUP_ALL; $customerGroupId = !$useForAllGroups ? $data['cust_group'] : 0; $new[$key] = array_merge(array( 'website_id' => $data['website_id'], 'all_groups' => $useForAllGroups ? 1 : 0, 'customer_group_id' => $customerGroupId, 'value' => $data['price'], ), $this->_getAdditionalUniqueFields($data)); } $delete = array_diff_key($old, $new); $insert = array_diff_key($new, $old); $update = array_intersect_key($new, $old); $isChanged = false; $productId = $object->getId(); if (!empty($delete)) { foreach ($delete as $data) { $this->_getResource()->deletePriceData($productId, null, $data['price_id']); $isChanged = true; } } if (!empty($insert)) { foreach ($insert as $data) { $price = new Varien_Object($data); $price->setEntityId($productId); $this->_getResource()->savePriceData($price); $isChanged = true; } } if (!empty($update)) { foreach ($update as $k => $v) { if ($old[$k]['price'] != $v['value']) { $price = new Varien_Object(array( 'value_id' => $old[$k]['price_id'], 'value' => $v['value'] )); $this->_getResource()->savePriceData($price); $isChanged = true; } } } if ($isChanged) { $valueChangedKey = $this->getAttribute()->getName() . '_changed'; $object->setData($valueChangedKey, 1); }*/ return $this; }
/** * Insert product Tier Price to storage * * @deprecated since 1.3.2.3 * * @param Mage_Catalog_Model_Product $product * @param array $data * @return Mage_Catalog_Model_Resource_Product_Attribute_Backend_Tierprice */ public function insertProductPrice($product, $data) { $priceObject = new Varien_Object($data); $priceObject->setEntityId($product->getId()); return $this->savePriceData($priceObject); }
public function match($pathInfo) { $identifier = trim($pathInfo, '/'); $parts = explode('/', $identifier); if (count($parts) == 1) { $parts[0] = $this->getUrlKeyWithoutSuffix($parts[0]); } if (isset($parts[0]) && !isset($this->config2[$parts[0]])) { return false; } $module = $this->config2[$parts[0]]; if (!$this->isEnabled($module)) { return false; } if (count($parts) > 1) { unset($parts[0]); $urlKey = implode('/', $parts); $urlKey = urldecode($urlKey); $urlKey = $this->getUrlKeyWithoutSuffix($urlKey); } else { $urlKey = ''; } //пÑовеÑÑем на ÑÑаÑиÑеÑкие ÑÑÐ»Ñ (ÑÑÐ»Ñ Ð¿Ð¾ÑÑоÑннÑÑ ÑÑÑаниÑ, напÑÐ¸Ð¼ÐµÑ ÑпиÑков) $type = $rewrite = false; foreach ($this->config[$module] as $t => $key) { if ($key === $urlKey) { $type = $t; break; } } // пÑовеÑÑем на динамиÑеÑкие ÑÑÐ»Ñ (ÑÑÐ»Ñ Ð¿ÑодÑкÑов, каÑегоÑий и Ñд) if (!$type) { $collection = Mage::getModel('mstcore/urlrewrite')->getCollection()->addFieldToFilter('url_key', $urlKey)->addFieldToFilter('module', $module); if ($collection->count()) { $rewrite = $collection->getFirstItem(); $type = $rewrite->getType(); } else { return false; } } if ($type) { $action = $this->config2[$module . '_' . $type]; $result = new Varien_Object(); $actionParts = explode('_', $action); $result->setRouteName($actionParts[0])->setModuleName($actionParts[0])->setControllerName($actionParts[1])->setActionName($actionParts[2]); if ($rewrite) { $result->setEntityId($rewrite->getEntityId()); } return $result; } return false; }
public function match($pathInfo) { $identifier = trim($pathInfo, '/'); $parts = explode('/', $identifier); if (count($parts) == 1) { $parts[0] = $this->getUrlKeyWithoutSuffix($parts[0]); } if (isset($parts[0]) && !isset($this->config2[$parts[0]])) { return false; } $module = $this->config2[$parts[0]]; if (!$this->isEnabled($module)) { return false; } if (count($parts) > 1) { unset($parts[0]); $urlKey = implode('/', $parts); $urlKey = urldecode($urlKey); $urlKey = $this->getUrlKeyWithoutSuffix($urlKey); } else { $urlKey = ''; } # check on static urls (urls for static pages, ex. lists) $type = $rewrite = false; foreach ($this->config[$module] as $t => $key) { if ($key === $urlKey) { if ($t == '_BASEPATH') { continue; } $type = $t; break; } } # check on dynamic urls (ex. urls of products, categories etc) if (!$type) { $collection = Mage::getModel('mstcore/urlrewrite')->getCollection()->addFieldToFilter('url_key', $urlKey)->addFieldToFilter('module', $module); if ($collection->count()) { $rewrite = $collection->getFirstItem(); $type = $rewrite->getType(); } else { return false; } } if ($type) { $action = $this->config2[$module . '_' . $type]['ACTION']; $params = $this->config2[$module . '_' . $type]['PARAMS']; $result = new Varien_Object(); $actionParts = explode('_', $action); $result->setRouteName($actionParts[0])->setModuleName($actionParts[0])->setControllerName($actionParts[1])->setActionName($actionParts[2])->setActionParams($params); if ($rewrite) { $result->setEntityId($rewrite->getEntityId()); } return $result; } return false; }
/** * After save * * @param Mage_Catalog_Model_Product $object * * @return Innoexts_StorePricing_Model_Catalog_Product_Attribute_Backend_Tierprice */ public function afterSave($object) { $helper = $this->getStorePricingHelper(); $priceHelper = $helper->getProductPriceHelper(); $resource = $this->_getResource(); $objectId = $object->getId(); $storeId = $object->getStoreId(); $websiteId = $helper->getWebsiteIdByStoreId($storeId); $attribute = $this->getAttribute(); $attributeName = $attribute->getName(); $tierPrices = $object->getData($attributeName); if (empty($tierPrices)) { if ($priceHelper->isGlobalScope() || $websiteId == 0) { $resource->deletePriceData2($objectId); } else { if ($priceHelper->isWebsiteScope()) { $resource->deletePriceData2($objectId, $websiteId); } else { if ($priceHelper->isStoreScope()) { $resource->deletePriceData2($objectId, $websiteId, $storeId); } } } return $this; } $old = array(); $new = array(); $origTierPrices = $object->getOrigData($attributeName); if (!is_array($origTierPrices)) { $origTierPrices = array(); } foreach ($origTierPrices as $data) { if (!$this->validateData($data, $storeId, false, false, true)) { continue; } $key = $this->getDataKey($data); $old[$key] = $data; } foreach ($tierPrices as $data) { if (!$this->validateData($data, $storeId, true, true, true)) { continue; } $key = $this->getDataKey($data); $useForAllGroups = $data['cust_group'] == Mage_Customer_Model_Group::CUST_GROUP_ALL; $customerGroupId = !$useForAllGroups ? $data['cust_group'] : 0; $new[$key] = array('website_id' => $data['website_id'], 'store_id' => $data['store_id'], 'all_groups' => $useForAllGroups ? 1 : 0, 'customer_group_id' => $customerGroupId, 'qty' => $data['price_qty'], 'value' => $data['price']); } $delete = array_diff_key($old, $new); $insert = array_diff_key($new, $old); $update = array_intersect_key($new, $old); $isChanged = false; $productId = $objectId; if (!empty($delete)) { foreach ($delete as $data) { $resource->deletePriceData2($productId, null, null, $data['price_id']); $isChanged = true; } } if (!empty($insert)) { foreach ($insert as $data) { $price = new Varien_Object($data); $price->setEntityId($productId); $resource->savePriceData($price); $isChanged = true; } } if (!empty($update)) { foreach ($update as $k => $v) { if ($old[$k]['price'] != $v['value']) { $price = new Varien_Object(array('value_id' => $old[$k]['price_id'], 'value' => $v['value'])); $resource->savePriceData($price); $isChanged = true; } } } if ($isChanged) { $valueChangedKey = $attributeName . '_changed'; $object->setData($valueChangedKey, 1); } return $this; }