Exemple #1
0
 public function testReset()
 {
     $model = $this->_model;
     $testCase = $this;
     $assertEmpty = function () use($model, $testCase) {
         $testCase->assertEquals(array(), $model->getData());
         $testCase->assertEquals(null, $model->getOrigData());
         $testCase->assertEquals(array(), $model->getCustomOptions());
         // impossible to test $_optionInstance
         $testCase->assertEquals(array(), $model->getOptions());
         $testCase->assertFalse($model->canAffectOptions());
         // impossible to test $_errors
     };
     $assertEmpty();
     $this->_model->setData('key', 'value');
     $this->_model->reset();
     $assertEmpty();
     $this->_model->setOrigData('key', 'value');
     $this->_model->reset();
     $assertEmpty();
     $this->_model->addCustomOption('key', 'value');
     $this->_model->reset();
     $assertEmpty();
     $this->_model->addOption(new Mage_Catalog_Model_Product_Option());
     $this->_model->reset();
     $assertEmpty();
     $this->_model->canAffectOptions(true);
     $this->_model->reset();
     $assertEmpty();
 }
Exemple #2
0
 /**
  * @magentoConfigFixture current_store catalog/price/scope 1
  * @magentoConfigFixture current_store currency/options/base GBP
  */
 public function testAfterSave()
 {
     $product = new Mage_Catalog_Model_Product();
     $product->load(1);
     $product->setOrigData();
     $product->setPrice(9.99);
     $product->setStoreId(0);
     $this->_model->setScope($this->_model->getAttribute());
     $this->_model->afterSave($product);
     $this->assertEquals('9.99', $product->getResource()->getAttributeRawValue($product->getId(), $this->_model->getAttribute()->getId(), Mage::app()->getStore()->getId()));
 }
Exemple #3
0
 /**
  * @test
  */
 public function testCalaogProductSaveAfter()
 {
     $this->_fpc->save('product1', 'product1_cache_id', array(sha1('product_1')));
     $this->_fpc->save('category1', 'category1_cache_id', array(sha1('category_1')));
     $this->_fpc->save('category2', 'category2_cache_id', array(sha1('category_2')));
     $product = new Mage_Catalog_Model_Product();
     $product->setOrigData(array());
     $product->setCategoryIds(array(1));
     $product->setId(1);
     Mage::dispatchEvent('catalog_product_save_after', array('product' => $product));
     $this->assertFalse($this->_fpc->load('product1_cache_id'));
     $this->assertFalse($this->_fpc->load('category1_cache_id'));
     $this->assertEquals('category2', $this->_fpc->load('category2_cache_id'));
 }
Exemple #4
0
 public function testReset()
 {
     $model = $this->_model;
     $this->_assertEmpty($model);
     $this->_model->setData('key', 'value');
     $this->_model->reset();
     $this->_assertEmpty($model);
     $this->_model->setOrigData('key', 'value');
     $this->_model->reset();
     $this->_assertEmpty($model);
     $this->_model->addCustomOption('key', 'value');
     $this->_model->reset();
     $this->_assertEmpty($model);
     $this->_model->addOption(new Mage_Catalog_Model_Product_Option());
     $this->_model->reset();
     $this->_assertEmpty($model);
     $this->_model->canAffectOptions(true);
     $this->_model->reset();
     $this->_assertEmpty($model);
 }
Exemple #5
0
 /**
  * Assign group prices to product data
  *
  * @param Mage_Catalog_Model_Product $object
  * @return Mage_Catalog_Model_Product_Attribute_Backend_Groupprice_Abstract
  */
 public function afterLoad($object)
 {
     $storeId = $object->getStoreId();
     $websiteId = null;
     if ($this->getAttribute()->isScopeGlobal()) {
         $websiteId = 0;
     } else {
         if ($storeId) {
             $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
         }
     }
     $data = $this->_getResource()->loadGroupData($object->getId(), $websiteId);
     foreach ($data as $k => $v) {
         //$data[$k]['website_price'] = $v['price'];
         if ($v['all_groups']) {
             $data[$k]['cust_group'] = Mage_Customer_Model_Group::CUST_GROUP_ALL;
         }
     }
     $object->setData($this->getAttribute()->getName(), $data);
     $object->setOrigData($this->getAttribute()->getName(), $data);
     $valueChangedKey = $this->getAttribute()->getName() . '_changed';
     $object->setOrigData($valueChangedKey, 0);
     $object->setData($valueChangedKey, 0);
     return $this;
 }
Exemple #6
0
 /**
  * @depends testAfterSave
  */
 public function testAfterSaveEmpty()
 {
     Mage::app()->setCurrentStore(Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID));
     $product = new Mage_Catalog_Model_Product();
     $product->load(1);
     $product->setOrigData();
     $product->setTierPrice(array());
     $this->_model->afterSave($product);
     $product = new Mage_Catalog_Model_Product();
     $product->setId(1);
     $this->_model->afterLoad($product);
     $this->assertEmpty($product->getTierPrice());
 }
 /**
  * Assign tier prices to product data
  *
  * @param Mage_Catalog_Model_Product $object
  * @return Mage_Catalog_Model_Product_Attribute_Backend_Tierprice
  */
 public function afterLoad($object)
 {
     $storeId = $object->getStoreId();
     $websiteId = null;
     if ($this->getAttribute()->isScopeGlobal()) {
         $websiteId = 0;
     } else {
         if ($storeId) {
             $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
         }
     }
     $data = $this->_getResource()->loadPriceData($object->getId(), $websiteId);
     foreach ($data as $k => $v) {
         $data[$k]['website_price'] = $v['price'];
         if ($v['all_groups']) {
             $data[$k]['cust_group'] = Mage_Customer_Model_Group::CUST_GROUP_ALL;
         }
     }
     if (!$object->getData('_edit_mode') && $websiteId) {
         $rates = $this->_getWebsiteRates();
         $full = $data;
         $data = array();
         foreach ($full as $v) {
             $key = join('-', array($v['cust_group'], $v['price_qty']));
             if ($v['website_id'] == $websiteId) {
                 $data[$key] = $v;
                 $data[$key]['website_price'] = $v['price'];
             } else {
                 if ($v['website_id'] == 0 && !isset($data[$key])) {
                     $data[$key] = $v;
                     $data[$key]['website_id'] = $websiteId;
                     if ($object->getPriceModel()->isTierPriceFixed()) {
                         $data[$key]['price'] = $v['price'] * $rates[$websiteId]['rate'];
                         $data[$key]['website_price'] = $v['price'] * $rates[$websiteId]['rate'];
                     }
                 }
             }
         }
     }
     $object->setData($this->getAttribute()->getName(), $data);
     $object->setOrigData($this->getAttribute()->getName(), $data);
     $valueChangedKey = $this->getAttribute()->getName() . '_changed';
     $object->setOrigData($valueChangedKey, 0);
     $object->setData($valueChangedKey, 0);
     return $this;
 }
 /**
  * Set original loaded data if needed
  *
  * @param string $key
  * @param mixed $data
  * @return Varien_Object
  */
 public function setOrigData($key = null, $data = null)
 {
     if (Mage::app()->getStore()->isAdmin()) {
         return parent::setOrigData($key, $data);
     }
     return $this;
 }