Example #1
0
 /**
  * @param sring|null $typeId
  * @dataProvider factoryReturnsSingletonDataProvider
  */
 public function testFactoryReturnsSingleton($typeId)
 {
     $product = new Varien_Object();
     if ($typeId) {
         $product->setTypeId($typeId);
     }
     $type = Mage_Catalog_Model_Product_Type::factory($product);
     $otherType = Mage_Catalog_Model_Product_Type::factory($product);
     $this->assertSame($otherType, $type);
 }
 /**
  * Retrieve Product Type Instances
  * as key - type code, value - instance model
  *
  * @return array
  */
 public function getProductTypeInstances()
 {
     if (is_null($this->_productTypes)) {
         $this->_productTypes = array();
         $productEmulator = new Varien_Object();
         foreach (array_keys(Mage_Catalog_Model_Product_Type::getTypes()) as $typeId) {
             $productEmulator->setTypeId($typeId);
             $this->_productTypes[$typeId] = Mage::getSingleton('catalog/product_type')->factory($productEmulator);
         }
     }
     return $this->_productTypes;
 }
Example #3
0
 /**
  * Retrieve Product Type Instance
  *
  * @return Mage_Catalog_Model_Product_Type_Abstract
  */
 public function getTypeInstance()
 {
     if (is_null($this->_typeInstance)) {
         $product = new Varien_Object();
         $product->setTypeId($this->getTypeCode());
         $this->_typeInstance = Mage::getSingleton('catalog/product_type')->factory($product, true);
     }
     return $this->_typeInstance;
 }
 /**
  * @test
  * @loadFixture
  * @loadFixture order
  * @loadFixture orderItem
  * @loadFixture downloadableData
  * @dataProvider provider__testAdditionalProductProcessing
  * This is core function processing downloadable products links statuses
  * 1. IF product is downloadable
  * 2. IF its statue is closed && successed => All of its links shoud be set as available, otherwise shoud be suspended
  */
 public function testAdditionalProductProcessing($data)
 {
     $product = new Varien_Object();
     $product->setTypeId(Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE);
     /* Create and prepare mock object */
     $dealMock = $this->getModelMock('collpur/deal', array('getProduct', 'isClosed'));
     $dealMock->expects($this->any())->method('getProduct')->will($this->returnValue($product));
     $dealMock->expects($this->any())->method('isClosed')->will($this->returnValue(AW_Collpur_Model_Deal::STATE_CLOSED == $data['close']));
     $dealMock->setId(1);
     $dealMock->setData('is_success', $data['success']);
     /*         * ****************************************************************** */
     $dealMock->additionalProductProcessing();
     $link = Mage::getModel('downloadable/link_purchased_item')->load(1);
     $this->assertEquals($data['status'], $link->getStatus());
 }
Example #5
0
 /**
  * Return all product children ids
  *
  * @param int $productId Product Entity Id
  * @param string $typeId Super Product Link Type
  * @return array
  */
 protected function _getProductChildIds($productId, $typeId)
 {
     if (!isset($this->_productTypes[$typeId])) {
         $productEmulator = new Varien_Object();
         $productEmulator->setTypeId($typeId);
         $typeInstance = Mage::getSingleton('catalog/product_type')->factory($productEmulator);
         $this->_productTypes[$typeId] = $typeInstance->isComposite() ? $typeInstance->getRelationInfo() : false;
     }
     $relation = $this->_productTypes[$typeId];
     if ($relation && $relation->getTable() && $relation->getParentFieldName() && $relation->getChildFieldName()) {
         $select = $this->_getReadAdapter()->select()->from(array('main' => $this->getTable($relation->getTable())), array($relation->getChildFieldName()))->where("{$relation->getParentFieldName()}=?", $productId);
         if (!is_null($relation->getWhere())) {
             $select->where($relation->getWhere());
         }
         return $this->_getReadAdapter()->fetchCol($select);
     }
     return null;
 }
 /**
  * Retrieve entities children ids (simple products for configurable, grouped and bundles).
  *
  * @param array $entityIds Parent entities ids.
  * @param int   $websiteId Current website ids
  *
  * @return array
  */
 protected function _getChildrenIds($entityIds, $websiteId)
 {
     $children = array();
     $productTypes = array_keys(Mage::getModel('catalog/product_type')->getOptionArray());
     foreach ($productTypes as $productType) {
         $productEmulator = new Varien_Object();
         $productEmulator->setIdFieldName('entity_id');
         $productEmulator->setTypeId($productType);
         $typeInstance = Mage::getSingleton('catalog/product_type')->factory($productEmulator);
         $relation = $typeInstance->isComposite() ? $typeInstance->getRelationInfo() : false;
         if ($relation && $relation->getTable() && $relation->getParentFieldName() && $relation->getChildFieldName()) {
             $select = $this->getConnection()->select()->from(array('main' => $this->getTable($relation->getTable())), array($relation->getParentFieldName(), $relation->getChildFieldName()))->where("main.{$relation->getParentFieldName()} in (?)", $entityIds);
             if (!is_null($relation->getWhere())) {
                 $select->where($relation->getWhere());
             }
             Mage::dispatchEvent('prepare_product_children_id_list_select', array('select' => $select, 'entity_field' => 'main.product_id', 'website_field' => $websiteId));
             $data = $this->getConnection()->fetchAll($select);
             foreach ($data as $link) {
                 $parentId = $link[$relation->getParentFieldName()];
                 $childId = $link[$relation->getChildFieldName()];
                 if (!isset($children[$parentId])) {
                     $children[$parentId] = array();
                 }
                 $children[$parentId][] = $childId;
             }
         }
     }
     return $children;
 }
/** @var $indexHelper Enterprise_Index_Helper_Data */
$indexHelper = Mage::helper('enterprise_index');
/** @var $client Enterprise_Mview_Model_Client */
$client = Mage::getModel('enterprise_mview/client');
$client->init('catalogsearch_fulltext');
$client->getMetadata()->setKeyColumn('product_id')->setViewName('catalogsearch_fulltext_cl')->setStatus(Enterprise_Mview_Model_Metadata::STATUS_INVALID)->setGroupCode('catalogsearch_fulltext')->save();
$client->execute('enterprise_index/action_index_changelog_create');
$subscriptions = array($this->getTable('catalog/product') => 'entity_id', $this->getTable(array('catalog/product', 'decimal')) => 'entity_id', $this->getTable(array('catalog/product', 'int')) => 'entity_id', $this->getTable(array('catalog/product', 'text')) => 'entity_id', $this->getTable(array('catalog/product', 'varchar')) => 'entity_id', $this->getTable(array('catalog/product', 'datetime')) => 'entity_id');
/** @var $resources mage_core_model_resource */
$resources = Mage::getSingleton('core/resource');
/** @var $productType mage_catalog_model_product_type */
$productType = Mage::getSingleton('catalog/product_type');
$productEmulator = new Varien_Object();
$productEmulator->setIdFieldName('entity_id');
foreach (Mage_Catalog_Model_Product_Type::getCompositeTypes() as $typeId) {
    $productEmulator->setTypeId($typeId);
    /** @var $typeInstance Mage_Catalog_Model_Product_Type_Abstract */
    $typeInstance = $productType->factory($productEmulator);
    /** @var $relation bool|Varien_Object */
    $relation = $typeInstance->isComposite() ? $typeInstance->getRelationInfo() : false;
    if ($relation && $relation->getTable()) {
        $tableName = $resources->getTableName($relation->getTable());
        $subscriptions[$tableName] = $relation->getParentFieldName();
    }
}
foreach ($subscriptions as $targetTable => $targetColumn) {
    $arguments = array('target_table' => $targetTable, 'target_column' => $targetColumn);
    $client->execute('enterprise_mview/action_changelog_subscription_create', $arguments);
}
$events = array();
/** @var $eventCollection Enterprise_Mview_Model_Resource_Event_Collection*/