Ejemplo n.º 1
0
 /**
  * Retrieve all attributes stored into the MongoDB collection for a given product and
  * append their values to the product
  *
  * @param Mage_Catalog_Model_Product $object The product to be loaded
  *
  * @return Smile_MongoCore_Model_Resource_Override_Catalog_Product Self reference
  */
 protected function _loadModelAttributes($object)
 {
     parent::_loadModelAttributes($object);
     if ($object->getEntityId()) {
         // Retrieve the collection to be updated
         // Provide a raw MongoCollection object pointing
         // to catalog_product_entity collection
         $collection = $this->_getDocumentCollection();
         // We load :
         // - object current store attributes values
         // - default store attributes values
         $storeIds = array('attr_' . $this->getDefaultStoreId());
         if ($object->getStoreId() && $object->getStoreId() != $this->getDefaultStoreId()) {
             $storeIds[] = 'attr_' . $object->getStoreId();
         }
         // Build filter on the product id
         $loadFilter = $this->getIdsFilter($object->getId());
         // Load document from collection
         $loadedData = $collection->findOne($loadFilter, $storeIds);
         // Merge document fields :
         //    if field exists into current store use it
         //    else look for it into the default store
         $attributeData = array();
         if ($loadedData) {
             foreach ($loadedData as $storeId => $attributeValues) {
                 if (in_array($storeId, $storeIds)) {
                     if (!is_array($attributeValues)) {
                         $attributeValues = array($storeId => $attributeValues);
                     }
                     foreach ($attributeValues as $attributeCode => $value) {
                         $attributeData[$attributeCode] = $value;
                     }
                 }
             }
         }
         // Append loaded attributes to the product
         $object->addData($attributeData);
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Retrieve all attributes stored into the MongoDB collection for a given product and
  * append their values to the product
  *
  * Also ensure to have correct behavior on "Use Default" checkbox on product edit
  *
  * @param Mage_Catalog_Model_Product $object The product to be loaded
  *
  * @return Smile_MongoCatalog_Model_Resource_Override_Catalog_Product Self reference
  */
 protected function _loadModelAttributes($object)
 {
     parent::_loadModelAttributes($object);
     if ($object->getEntityId()) {
         // Retrieve the collection to be updated
         // Provide a raw MongoCollection object pointing
         // to catalog_product_entity collection
         $collection = $this->_getDocumentCollection();
         // We load :
         // - object current store attributes values
         // - default store attributes values
         $storeIds = array('attr_' . $this->getDefaultStoreId());
         if ($object->getStoreId() && $object->getStoreId() != $this->getDefaultStoreId()) {
             $storeIds[] = 'attr_' . $object->getStoreId();
         }
         // Build filter on the product id
         $loadFilter = $this->getIdsFilter($object->getId());
         // Load document from collection
         $loadedData = $collection->findOne($loadFilter, $storeIds);
         // Merge document fields :
         //    if field exists into current store use it
         //    else look for it into the default store
         $attributeData = array();
         if ($loadedData) {
             foreach ($loadedData as $storeId => $attributeValues) {
                 if (in_array($storeId, $storeIds)) {
                     if (!is_array($attributeValues)) {
                         $attributeValues = array($storeId => $attributeValues);
                     }
                     foreach ($attributeValues as $attributeCode => $value) {
                         $attribute = $this->getAttribute($attributeCode);
                         $attributeData[$attributeCode] = $value;
                         /**
                          * If specific value exists for current store,
                          * flag it to have the product displaying correctly the "use default" checkbox
                          */
                         if ($attribute != null && !$attribute->isScopeWebsite() && !($object->getStoreId() == $this->getDefaultStoreId()) && $storeId !== 'attr_' . $this->getDefaultStoreId()) {
                             $object->setExistsStoreValueFlag($attributeCode);
                         }
                         if ($object->getStoreId() != $this->getDefaultStoreId() && ($storeId === 'attr_' . $this->getDefaultStoreId() && !in_array($attributeCode, $this->getSqlAttributesCodes()))) {
                             $object->setAttributeDefaultValue($attributeCode, $value);
                         }
                     }
                 }
             }
         }
         // Append loaded attributes to the product
         $object->addData($attributeData);
     }
     return $this;
 }