Ejemplo n.º 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);
 }
 /**
  * given a DOMNodeList and a Mage_Catalog_Model_Product make sure this is
  * a product of type configurable and then extract the configurable attribute from the node list
  * then get the configurable attribute array for each configured attributes
  * @param DOMNOdeList $nodes the node with configurableAttributes data
  * @param Mage_Catalog_Model_Product $product
  * @return array | null an array of configurable attribute data if the given product is configurable otherwise null
  */
 public function extractConfigurableAttributesData(DOMNodeList $nodes, Mage_Catalog_Model_Product $product)
 {
     // We are ensuring that the given product is a parent configurable product by first checking if the product sku
     // doesn't match the product style id. If this condition is met then we know we have a child product and we won't
     // proceed otherwise we know we have a parent product and proceed continue.
     if ($product->getSku() !== $this->_normalizeStyleId($product->getStyleId())) {
         return null;
     }
     $typeInstance = $product->getTypeInstance(true);
     // making sure the right type instance is set on the product
     if (!$typeInstance instanceof Mage_Catalog_Model_Product_Type_Configurable) {
         $product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)->setTypeInstance(Mage_Catalog_Model_Product_Type::factory($product, true), true);
     }
     $data = null;
     // purposely setting this to null just in cause all the attribute already exists
     // we need to know which configurable attribute we already have for this product
     // so that we don't try to create the same super attribute relationship which will
     // cause unique key duplication SQL constraint to be thrown
     $existedData = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
     foreach (explode(',', strtolower(Mage::helper('eb2ccore')->extractNodeVal($nodes))) as $attributeCode) {
         // if we don't currently have a super attribute relationship then get the
         // configurable attribute data
         if (!$this->_isSuperAttributeExists($existedData, $attributeCode) && $this->_isAttributeInSet($attributeCode, $product)) {
             $data[] = $this->_getConfiguredAttributeData($attributeCode);
         }
     }
     // At this point we know we are dealing with a configurable product; therefore,
     // this is the right place to make sure manage stock get turn off.
     $this->_turnOffManageStock($product);
     return $data;
 }
 /**
  * extract the first element of a dom node list make sure it is lower case
  * if there's no item in the DOMNodeList return the default simple product type constant value
  *
  * @param DOMNodeList $nodes
  * @param Mage_Catalog_Model_Product $product
  * @return string
  */
 public function extractProductTypeValue(DOMNodeList $nodes, Mage_Catalog_Model_Product $product)
 {
     $value = strtolower($this->coreHelper->extractNodeVal($nodes));
     $type = $this->_isValidProductType($value) ? $value : Mage_Catalog_Model_Product_Type::TYPE_SIMPLE;
     $product->setTypeId($type)->setTypeInstance(Mage_Catalog_Model_Product_Type::factory($product, true), true);
     return $type;
 }