Best Cucumber Common Library code snippet using Product
Configurable.php
Source:Configurable.php
...31 * @category Mage32 * @package Mage_Catalog33 * @author Magento Core Team <core@magentocommerce.com>34 */35class Mage_Catalog_Model_Product_Type_Configurable extends Mage_Catalog_Model_Product_Type_Abstract36{37 const TYPE_CODE = 'configurable';38 /**39 * Cache key for Used Product Attribute Ids40 *41 * @var string42 */43 protected $_usedProductAttributeIds = '_cache_instance_used_product_attribute_ids';44 /**45 * Cache key for Used Product Attributes46 *47 * @var string48 */49 protected $_usedProductAttributes = '_cache_instance_used_product_attributes';50 /**51 * Cache key for Used Attributes52 *53 * @var string54 */55 protected $_usedAttributes = '_cache_instance_used_attributes';56 /**57 * Cache key for configurable attributes58 *59 * @var string60 */61 protected $_configurableAttributes = '_cache_instance_configurable_attributes';62 /**63 * Cache key for Used product ids64 *65 * @var string66 */67 protected $_usedProductIds = '_cache_instance_product_ids';68 /**69 * Cache key for used products70 *71 * @var string72 */73 protected $_usedProducts = '_cache_instance_products';74 /**75 * Product is composite76 *77 * @var bool78 */79 protected $_isComposite = true;80 /**81 * Product is configurable82 *83 * @var bool84 */85 protected $_canConfigure = true;86 /**87 * Product attributes to include on the children of configurable products88 *89 * @var string90 */91 const XML_PATH_PRODUCT_CONFIGURABLE_CHILD_ATTRIBUTES = 'frontend/product/configurable/child/attributes';92 /**93 * Return relation info about used products94 *95 * @return Varien_Object Object with information data96 */97 public function getRelationInfo()98 {99 $info = new Varien_Object();100 $info->setTable('catalog/product_super_link')101 ->setParentFieldName('parent_id')102 ->setChildFieldName('product_id');103 return $info;104 }105 /**106 * Retrieve Required children ids107 * Return grouped array, ex array(108 * group => array(ids)109 * )110 *111 * @param int $parentId112 * @param bool $required113 * @return array114 */115 public function getChildrenIds($parentId, $required = true)116 {117 return Mage::getResourceSingleton('catalog/product_type_configurable')118 ->getChildrenIds($parentId, $required);119 }120 /**121 * Retrieve parent ids array by required child122 *123 * @param int|array $childId124 * @return array125 */126 public function getParentIdsByChild($childId)127 {128 return Mage::getResourceSingleton('catalog/product_type_configurable')129 ->getParentIdsByChild($childId);130 }131 /**132 * Retrieve product type attributes133 *134 * @param Mage_Catalog_Model_Product $product135 * @return array136 */137 public function getEditableAttributes($product = null)138 {139 if (is_null($this->_editableAttributes)) {140 $this->_editableAttributes = parent::getEditableAttributes($product);141 foreach ($this->_editableAttributes as $index => $attribute) {142 if ($this->getUsedProductAttributeIds($product)143 && in_array($attribute->getAttributeId(), $this->getUsedProductAttributeIds($product))) {144 unset($this->_editableAttributes[$index]);145 }146 }147 }148 return $this->_editableAttributes;149 }150 /**151 * Checkin attribute availability for create superproduct152 *153 * @param Mage_Eav_Model_Entity_Attribute $attribute154 * @return bool155 */156 public function canUseAttribute(Mage_Eav_Model_Entity_Attribute $attribute)157 {158 $allow = $attribute->getIsGlobal() == Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL159 && $attribute->getIsVisible()160 && $attribute->getIsConfigurable()161 && $attribute->usesSource()162 && $attribute->getIsUserDefined();163 return $allow;164 }165 /**166 * Declare attribute identifiers used for assign subproducts167 *168 * @param array $ids169 * @param Mage_Catalog_Model_Product $product170 * @return Mage_Catalog_Model_Product_Type_Configurable171 */172 public function setUsedProductAttributeIds($ids, $product = null)173 {174 $usedProductAttributes = array();175 $configurableAttributes = array();176 foreach ($ids as $attributeId) {177 $usedProductAttributes[] = $this->getAttributeById($attributeId);178 $configurableAttributes[] = Mage::getModel('catalog/product_type_configurable_attribute')179 ->setProductAttribute($this->getAttributeById($attributeId));180 }181 $this->getProduct($product)->setData($this->_usedProductAttributes, $usedProductAttributes);182 $this->getProduct($product)->setData($this->_usedProductAttributeIds, $ids);183 $this->getProduct($product)->setData($this->_configurableAttributes, $configurableAttributes);184 return $this;185 }186 /**187 * Retrieve identifiers of used product attributes188 *189 * @param Mage_Catalog_Model_Product $product190 * @return array191 */192 public function getUsedProductAttributeIds($product = null)193 {194 if (!$this->getProduct($product)->hasData($this->_usedProductAttributeIds)) {195 $usedProductAttributeIds = array();196 foreach ($this->getUsedProductAttributes($product) as $attribute) {197 $usedProductAttributeIds[] = $attribute->getId();198 }199 $this->getProduct($product)->setData($this->_usedProductAttributeIds, $usedProductAttributeIds);200 }201 return $this->getProduct($product)->getData($this->_usedProductAttributeIds);202 }203 /**204 * Retrieve used product attributes205 *206 * @param Mage_Catalog_Model_Product $product207 * @return array208 */209 public function getUsedProductAttributes($product = null)210 {211 if (!$this->getProduct($product)->hasData($this->_usedProductAttributes)) {212 $usedProductAttributes = array();213 $usedAttributes = array();214 foreach ($this->getConfigurableAttributes($product) as $attribute) {215 if (!is_null($attribute->getProductAttribute())) {216 $id = $attribute->getProductAttribute()->getId();217 $usedProductAttributes[$id] = $attribute->getProductAttribute();218 $usedAttributes[$id] = $attribute;219 }220 }221 $this->getProduct($product)->setData($this->_usedAttributes, $usedAttributes);222 $this->getProduct($product)->setData($this->_usedProductAttributes, $usedProductAttributes);223 }224 return $this->getProduct($product)->getData($this->_usedProductAttributes);225 }226 /**227 * Retrieve configurable attributes data228 *229 * @param Mage_Catalog_Model_Product $product230 * @return array231 */232 public function getConfigurableAttributes($product = null)233 {234 Varien_Profiler::start('CONFIGURABLE:'.__METHOD__);235 if (!$this->getProduct($product)->hasData($this->_configurableAttributes)) {236 $configurableAttributes = $this->getConfigurableAttributeCollection($product)237 ->orderByPosition()238 ->load();239 $this->getProduct($product)->setData($this->_configurableAttributes, $configurableAttributes);240 }241 Varien_Profiler::stop('CONFIGURABLE:'.__METHOD__);242 return $this->getProduct($product)->getData($this->_configurableAttributes);243 }244 /**245 * Retrieve Configurable Attributes as array246 *247 * @param Mage_Catalog_Model_Product $product248 * @return array249 */250 public function getConfigurableAttributesAsArray($product = null)251 {252 $res = array();253 foreach ($this->getConfigurableAttributes($product) as $attribute) {254 $res[] = array(255 'id' => $attribute->getId(),256 'label' => $attribute->getLabel(),257 'use_default' => $attribute->getUseDefault(),258 'position' => $attribute->getPosition(),259 'values' => $attribute->getPrices() ? $attribute->getPrices() : array(),260 'attribute_id' => $attribute->getProductAttribute()->getId(),261 'attribute_code' => $attribute->getProductAttribute()->getAttributeCode(),262 'frontend_label' => $attribute->getProductAttribute()->getFrontend()->getLabel(),263 'store_label' => $attribute->getProductAttribute()->getStoreLabel(),264 );265 }266 return $res;267 }268 /**269 * Retrieve configurable attribute collection270 *271 * @param Mage_Catalog_Model_Product $product272 * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute_Collection273 */274 public function getConfigurableAttributeCollection($product = null)275 {276 return Mage::getResourceModel('catalog/product_type_configurable_attribute_collection')277 ->setProductFilter($this->getProduct($product));278 }279 /**280 * Retrieve subproducts identifiers281 *282 * @param Mage_Catalog_Model_Product $product283 * @return array284 */285 public function getUsedProductIds($product = null)286 {287 if (!$this->getProduct($product)->hasData($this->_usedProductIds)) {288 $usedProductIds = array();289 foreach ($this->getUsedProducts(null, $product) as $product) {290 $usedProductIds[] = $product->getId();291 }292 $this->getProduct($product)->setData($this->_usedProductIds, $usedProductIds);293 }294 return $this->getProduct($product)->getData($this->_usedProductIds);295 }296 /**297 * Retrieve array of "subproducts"298 *299 * @param array300 * @param Mage_Catalog_Model_Product $product301 * @return array302 */303 public function getUsedProducts($requiredAttributeIds = null, $product = null)304 {305 Varien_Profiler::start('CONFIGURABLE:'.__METHOD__);306 if (!$this->getProduct($product)->hasData($this->_usedProducts)) {307 if (is_null($requiredAttributeIds)308 and is_null($this->getProduct($product)->getData($this->_configurableAttributes))) {309 // If used products load before attributes, we will load attributes.310 $this->getConfigurableAttributes($product);311 // After attributes loading products loaded too.312 Varien_Profiler::stop('CONFIGURABLE:'.__METHOD__);313 return $this->getProduct($product)->getData($this->_usedProducts);314 }315 $usedProducts = array();316 $collection = $this->getUsedProductCollection($product)317 ->addFilterByRequiredOptions();318 // Provides a mechanism for attaching additional attributes to the children of configurable products319 // Will primarily have affect on the configurable product view page320 $childAttributes = Mage::getConfig()->getNode(self::XML_PATH_PRODUCT_CONFIGURABLE_CHILD_ATTRIBUTES);321 if ($childAttributes) {322 $childAttributes = $childAttributes->asArray();323 $childAttributes = array_keys($childAttributes);324 $collection->addAttributeToSelect($childAttributes);325 }326 if (is_array($requiredAttributeIds)) {327 foreach ($requiredAttributeIds as $attributeId) {328 $attribute = $this->getAttributeById($attributeId, $product);329 if (!is_null($attribute))330 $collection->addAttributeToFilter($attribute->getAttributeCode(), array('notnull'=>1));331 }332 }333 foreach ($collection as $item) {334 $usedProducts[] = $item;335 }336 $this->getProduct($product)->setData($this->_usedProducts, $usedProducts);337 }338 Varien_Profiler::stop('CONFIGURABLE:'.__METHOD__);339 return $this->getProduct($product)->getData($this->_usedProducts);340 }341 /**342 * Retrieve related products collection343 *344 * @param Mage_Catalog_Model_Product $product345 * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Product_Collection346 */347 public function getUsedProductCollection($product = null)348 {349 $collection = Mage::getResourceModel('catalog/product_type_configurable_product_collection')350 ->setFlag('require_stock_items', true)351 ->setFlag('product_children', true)352 ->setProductFilter($this->getProduct($product));353 if (!is_null($this->getStoreFilter($product))) {354 $collection->addStoreFilter($this->getStoreFilter($product));355 }356 return $collection;357 }358 /**359 * Before save process360 *361 * @param Mage_Catalog_Model_Product $product362 * @return Mage_Catalog_Model_Product_Type_Configurable363 */364 public function beforeSave($product = null)365 {366 parent::beforeSave($product);367 $this->getProduct($product)->canAffectOptions(false);368 if ($this->getProduct($product)->getCanSaveConfigurableAttributes()) {369 $this->getProduct($product)->canAffectOptions(true);370 $data = $this->getProduct($product)->getConfigurableAttributesData();371 if (!empty($data)) {372 foreach ($data as $attribute) {373 if (!empty($attribute['values'])) {374 $this->getProduct($product)->setTypeHasOptions(true);375 $this->getProduct($product)->setTypeHasRequiredOptions(true);376 break;377 }378 }379 }380 }381 foreach ($this->getConfigurableAttributes($product) as $attribute) {382 $this->getProduct($product)->setData($attribute->getProductAttribute()->getAttributeCode(), null);383 }384 return $this;385 }386 /**387 * Save configurable product depended data388 *389 * @param Mage_Catalog_Model_Product $product390 * @return Mage_Catalog_Model_Product_Type_Configurable391 */392 public function save($product = null)393 {394 parent::save($product);395 /**396 * Save Attributes Information397 */398 if ($data = $this->getProduct($product)->getConfigurableAttributesData()) {399 foreach ($data as $attributeData) {400 $id = isset($attributeData['id']) ? $attributeData['id'] : null;401 Mage::getModel('catalog/product_type_configurable_attribute')402 ->setData($attributeData)403 ->setId($id)404 ->setStoreId($this->getProduct($product)->getStoreId())405 ->setProductId($this->getProduct($product)->getId())406 ->save();407 }408 }409 /**410 * Save product relations411 */412 $data = $this->getProduct($product)->getConfigurableProductsData();413 if (is_array($data)) {414 $productIds = array_keys($data);415 Mage::getResourceModel('catalog/product_type_configurable')416 ->saveProducts($this->getProduct($product), $productIds);417 }418 return $this;419 }420 /**421 * Check is product available for sale422 *423 * @param Mage_Catalog_Model_Product $product424 * @return bool425 */426 public function isSalable($product = null)427 {428 $salable = parent::isSalable($product);429 if ($salable !== false) {430 $salable = false;431 if (!is_null($product)) {432 $this->setStoreFilter($product->getStoreId(), $product);433 }434 foreach ($this->getUsedProducts(null, $product) as $child) {435 if ($child->isSalable()) {436 $salable = true;437 break;438 }439 }440 }441 return $salable;442 }443 /**444 * Check whether the product is available for sale445 * is alias to isSalable for compatibility446 *447 * @param Mage_Catalog_Model_Product $product448 * @return bool449 */450 public function getIsSalable($product = null)451 {452 return $this->isSalable($product);453 }454 /**455 * Retrieve used product by attribute values456 * $attrbutesInfo = array(457 * $attributeId => $attributeValue458 * )459 *460 * @param array $attributesInfo461 * @param Mage_Catalog_Model_Product $product462 * @return Mage_Catalog_Model_Product|null463 */464 public function getProductByAttributes($attributesInfo, $product = null)465 {466 if (is_array($attributesInfo) && !empty($attributesInfo)) {467 $productCollection = $this->getUsedProductCollection($product)->addAttributeToSelect('name');468 foreach ($attributesInfo as $attributeId => $attributeValue) {469 $productCollection->addAttributeToFilter($attributeId, $attributeValue);470 }471 $productObject = $productCollection->getFirstItem();472 if ($productObject->getId()) {473 return $productObject;474 }475 foreach ($this->getUsedProducts(null, $product) as $productObject) {476 $checkRes = true;477 foreach ($attributesInfo as $attributeId => $attributeValue) {478 $code = $this->getAttributeById($attributeId, $product)->getAttributeCode();479 if ($productObject->getData($code) != $attributeValue) {480 $checkRes = false;481 }482 }483 if ($checkRes) {484 return $productObject;485 }486 }487 }488 return null;489 }490 /**491 * Retrieve Selected Attributes info492 *493 * @param Mage_Catalog_Model_Product $product494 * @return array495 */496 public function getSelectedAttributesInfo($product = null)497 {498 $attributes = array();499 Varien_Profiler::start('CONFIGURABLE:'.__METHOD__);500 if ($attributesOption = $this->getProduct($product)->getCustomOption('attributes')) {501 $data = unserialize($attributesOption->getValue());502 $this->getUsedProductAttributeIds($product);503 $usedAttributes = $this->getProduct($product)->getData($this->_usedAttributes);504 foreach ($data as $attributeId => $attributeValue) {505 if (isset($usedAttributes[$attributeId])) {506 $attribute = $usedAttributes[$attributeId];507 $label = $attribute->getLabel();508 $value = $attribute->getProductAttribute();509 if ($value->getSourceModel()) {510 $value = $value->getSource()->getOptionText($attributeValue);511 }512 else {513 $value = '';514 }515 $attributes[] = array('label'=>$label, 'value'=>$value);516 }517 }518 }519 Varien_Profiler::stop('CONFIGURABLE:'.__METHOD__);520 return $attributes;521 }522 /**523 * Prepare product and its configuration to be added to some products list.524 * Perform standard preparation process and then add Configurable specific options.525 *526 * @param Varien_Object $buyRequest527 * @param Mage_Catalog_Model_Product $product528 * @param string $processMode529 * @return array|string530 */531 protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)532 {533 $attributes = $buyRequest->getSuperAttribute();534 if ($attributes || !$this->_isStrictProcessMode($processMode)) {535 if (!$this->_isStrictProcessMode($processMode)) {536 if (is_array($attributes)) {537 foreach ($attributes as $key => $val) {538 if (empty($val)) {539 unset($attributes[$key]);540 }541 }542 } else {543 $attributes = array();544 }545 }546 $result = parent::_prepareProduct($buyRequest, $product, $processMode);547 if (is_array($result)) {548 $product = $this->getProduct($product);549 /**550 * $attributes = array($attributeId=>$attributeValue)551 */552 $subProduct = true;553 if ($this->_isStrictProcessMode($processMode)) {554 foreach($this->getConfigurableAttributes($product) as $attributeItem){555 /* @var $attributeItem Varien_Object */556 $attrId = $attributeItem->getData('attribute_id');557 if(!isset($attributes[$attrId]) || empty($attributes[$attrId])) {558 $subProduct = null;559 break;560 }561 }562 }563 if( $subProduct ) {564 $subProduct = $this->getProductByAttributes($attributes, $product);565 }566 if ($subProduct) {567 $product->addCustomOption('attributes', serialize($attributes));568 $product->addCustomOption('product_qty_'.$subProduct->getId(), 1, $subProduct);569 $product->addCustomOption('simple_product', $subProduct->getId(), $subProduct);570 $_result = $subProduct->getTypeInstance(true)->_prepareProduct(571 $buyRequest,572 $subProduct,573 $processMode574 );575 if (is_string($_result) && !is_array($_result)) {576 return $_result;577 }578 if (!isset($_result[0])) {579 return Mage::helper('checkout')->__('Cannot add the item to shopping cart');580 }581 /**582 * Adding parent product custom options to child product583 * to be sure that it will be unique as its parent584 */585 if ($optionIds = $product->getCustomOption('option_ids')) {586 $optionIds = explode(',', $optionIds->getValue());587 foreach ($optionIds as $optionId) {588 if ($option = $product->getCustomOption('option_' . $optionId)) {589 $_result[0]->addCustomOption('option_' . $optionId, $option->getValue());590 }591 }592 }593 $_result[0]->setParentProductId($product->getId())594 // add custom option to simple product for protection of process595 //when we add simple product separately596 ->addCustomOption('parent_product_id', $product->getId());597 if ($this->_isStrictProcessMode($processMode)) {598 $_result[0]->setCartQty(1);599 }600 $result[] = $_result[0];601 return $result;602 } else if (!$this->_isStrictProcessMode($processMode)) {603 return $result;604 }605 }606 }607 return $this->getSpecifyOptionMessage();608 }609 /**610 * Check if product can be bought611 *612 * @param Mage_Catalog_Model_Product $product613 * @return Mage_Catalog_Model_Product_Type_Configurable614 * @throws Mage_Core_Exception615 */616 public function checkProductBuyState($product = null)617 {618 parent::checkProductBuyState($product);619 $product = $this->getProduct($product);620 $option = $product->getCustomOption('info_buyRequest');621 if ($option instanceof Mage_Sales_Model_Quote_Item_Option) {622 $buyRequest = new Varien_Object(unserialize($option->getValue()));623 $attributes = $buyRequest->getSuperAttribute();624 if (is_array($attributes)) {625 foreach ($attributes as $key => $val) {626 if (empty($val)) {627 unset($attributes[$key]);628 }629 }630 }631 if (empty($attributes)) {632 Mage::throwException($this->getSpecifyOptionMessage());633 }634 }635 return $this;636 }637 /**638 * Retrieve message for specify option(s)639 *640 * @return string641 */642 public function getSpecifyOptionMessage()643 {644 return Mage::helper('catalog')->__('Please specify the product\'s option(s).');645 }646 /**647 * Prepare additional options/information for order item which will be648 * created from this product649 *650 * @param Mage_Catalog_Model_Product $product651 * @return array652 */653 public function getOrderOptions($product = null)654 {655 $options = parent::getOrderOptions($product);656 $options['attributes_info'] = $this->getSelectedAttributesInfo($product);657 if ($simpleOption = $this->getProduct($product)->getCustomOption('simple_product')) {658 $options['simple_name'] = $simpleOption->getProduct($product)->getName();659 $options['simple_sku'] = $simpleOption->getProduct($product)->getSku();660 }661 $options['product_calculations'] = self::CALCULATE_PARENT;662 $options['shipment_type'] = self::SHIPMENT_TOGETHER;663 return $options;664 }665 /**666 * Check is virtual product667 *668 * @param Mage_Catalog_Model_Product $product669 * @return bool670 */671 public function isVirtual($product = null)672 {673 if ($productOption = $this->getProduct($product)->getCustomOption('simple_product')) {674 if ($optionProduct = $productOption->getProduct()) {675 /* @var $optionProduct Mage_Catalog_Model_Product */676 return $optionProduct->isVirtual();677 }678 }679 return parent::isVirtual($product);680 }681 /**682 * Return true if product has options683 *684 * @param Mage_Catalog_Model_Product $product685 * @return bool686 */687 public function hasOptions($product = null)688 {689 if ($this->getProduct($product)->getOptions()) {690 return true;691 }692 $attributes = $this->getConfigurableAttributes($product);693 if (count($attributes)) {694 foreach ($attributes as $attribute) {695 /** @var Mage_Catalog_Model_Product_Type_Configurable_Attribute $attribute */696 if ($attribute->getData('prices')) {697 return true;698 }699 }700 }701 return false;702 }703 /**704 * Return product weight based on simple product705 * weight or configurable product weight706 *707 * @param Mage_Catalog_Model_Product $product708 * @return decimal709 */710 public function getWeight($product = null)711 {712 if ($this->getProduct($product)->hasCustomOptions() &&713 ($simpleProductOption = $this->getProduct($product)->getCustomOption('simple_product'))714 ) {715 $simpleProduct = $simpleProductOption->getProduct($product);716 if ($simpleProduct) {717 return $simpleProduct->getWeight();718 }719 }720 return $this->getProduct($product)->getData('weight');721 }722 /**723 * Implementation of product specify logic of which product needs to be assigned to option.724 * For example if product which was added to option already removed from catalog.725 *726 * @param Mage_Catalog_Model_Product|null $optionProduct727 * @param Mage_Sales_Model_Quote_Item_Option $option728 * @param Mage_Catalog_Model_Product|null $product729 * @return Mage_Catalog_Model_Product_Type_Configurable730 */731 public function assignProductToOption($optionProduct, $option, $product = null)732 {733 if ($optionProduct) {734 $option->setProduct($optionProduct);735 } else {736 $option->getItem()->setHasConfigurationUnavailableError(true);737 }738 return $this;739 }740 /**741 * Retrieve products divided into groups required to purchase742 * At least one product in each group has to be purchased743 *744 * @param Mage_Catalog_Model_Product $product745 * @return array746 */747 public function getProductsToPurchaseByReqGroups($product = null)748 {749 $product = $this->getProduct($product);750 return array($this->getUsedProducts(null, $product));751 }752 /**753 * Get sku of product754 *755 * @param Mage_Catalog_Model_Product $product756 * @return string757 */758 public function getSku($product = null)759 {760 $simpleOption = $this->getProduct($product)->getCustomOption('simple_product');761 if($simpleOption) {762 $optionProduct = $simpleOption->getProduct($product);763 $simpleSku = null;764 if ($optionProduct) {765 $simpleSku = $simpleOption->getProduct($product)->getSku();766 }767 $sku = parent::getOptionSku($product, $simpleSku);768 } else {769 $sku = parent::getSku($product);770 }771 return $sku;772 }773 /**774 * Prepare selected options for configurable product775 *776 * @param Mage_Catalog_Model_Product $product777 * @param Varien_Object $buyRequest778 * @return array779 */780 public function processBuyRequest($product, $buyRequest)781 {782 $superAttribute = $buyRequest->getSuperAttribute();783 $superAttribute = (is_array($superAttribute)) ? array_filter($superAttribute, 'intval') : array();784 $options = array('super_attribute' => $superAttribute);785 return $options;786 }787 /**788 * Check if Minimum Advertise Price is enabled at least in one option789 *790 * @param Mage_Catalog_Model_Product $product791 * @param int $visibility792 * @return bool|null793 */794 public function isMapEnabledInOptions($product, $visibility = null)795 {796 return null;797 }798 /**799 * Prepare and retrieve options values with product data800 *801 * @param Mage_Catalog_Model_Product $product802 * @return array803 */804 public function getConfigurableOptions($product)805 {806 return Mage::getResourceSingleton('catalog/product_type_configurable')807 ->getConfigurableOptions($product, $this->getUsedProductAttributes($product));808 }809}...
Product_details_model.php
Source:Product_details_model.php
1<?php2error_reporting(0);3class Product_details_model extends CI_Model4{5 function __construct()6 {7 parent::__construct();8 }9 public function get_products_list($product_id,$product_url)10 {11 12 $this->db->select('product.product_id,product.product_url,product.shipping_time, product.quantity,product.set_description,info.product_feature_1,info.product_feature_2,info.product_feature_3,info.product_feature_4,info.product_feature_5,product.seller_id, product.product_sku,product.item_name,product.short_description As product_description, product.fabric, product.pack_of, product.cash_on_delivery, product.selling_price,product.standard_price,13 category.category_name,category.category_id,category.category_url,sub_category.sub_category_id,sub_category.sub_category_url,subtosub_category.subtosub_category_id,sub_category.sub_category_name,subtosub_category.subtosub_category_name, subtosub_category.subtosub_category_url,info.product_full_description,product.short_description,info.fabric_wash, info.search_terms ,info.product_feature_1 , info.product_feature_2,info.product_feature_3,info.product_feature_4,info.product_feature_5,product_keywords.product_keyword');14 $this->db->from('tblblk_product AS product'); 15 $this->db->join('tblblk_category AS category','category.category_id = product.category_id','LEFT');16 $this->db->join('tblblk_sub_category AS sub_category','sub_category.sub_category_id = product.sub_category_id','LEFT');17 $this->db->join('tblblk_subtosub_category AS subtosub_category','subtosub_category.subtosub_category_id = product.subtosub_category_id','LEFT');18 $this->db->join('tblblk_product_additional_info AS info','info.product_id = product.product_id','LEFT');19 $this->db->join('tblblk_product_keywords AS product_keywords','product_keywords.product_id = product.product_id','LEFT'); 20 $where = array('category.status'=>1,'sub_category.status'=>1,'subtosub_category.status'=>1,'product.product_status'=>4,'product.is_active'=>'Y');21 $this->db->where($where);22 $this->db->where(array('product.product_id'=>$product_id,'product.product_url'=>$product_url)); 23 $query = $this->db->get();24 //echo $this->db->last_query();exit;25 return $query->row();26 }27 public function getSimilarProducts($subtosub_cat_id)28 {29 $this->db->select('product.product_id,product.product_url, product.seller_id, product.product_sku, product.item_name, product.short_description As product_description, product.fabric, product.pack_of, product.cash_on_delivery, product.selling_price,product.standard_price,30 category.category_name, category.category_url, sub_category.sub_category_url, sub_category.sub_category_name, subtosub_category.subtosub_category_name, subtosub_category.subtosub_category_url,product_image.image_name');31 $this->db->from('tblblk_product AS product'); 32 $this->db->join('tblblk_category AS category','category.category_id = product.category_id','LEFT');33 $this->db->join('tblblk_sub_category AS sub_category','sub_category.sub_category_id = product.sub_category_id','LEFT');34 $this->db->join('tblblk_subtosub_category AS subtosub_category','subtosub_category.subtosub_category_id = product.subtosub_category_id','LEFT');35 $this->db->join("tblblk_product_images product_image",'product_image.product_id = product.product_id','LEFT');36 $where = array('category.status'=>1,'sub_category.status'=>1,'subtosub_category.status'=>1,'product.product_status'=>4,'product.is_active'=>'Y');37 $this->db->where($where);38 $this->db->where('product.subtosub_category_id',$subtosub_cat_id);39 $this->db->group_by(array('product.product_id'));40 $this->db->order_by("product.standard_price","ASC");41 $this->db->limit(12);42 $query = $this->db->get();43 //echo $this->db->last_query();exit;44 return $query->result();45 }46 public function get_product_images($product_id)47 {48 $this->db->select('image.image_name,image.product_id');49 $this->db->from('tblblk_product_images AS image');50 $this->db->where(array('image.product_id'=>$product_id,'image.status'=>1));51 $query = $this->db->get();52 return $query->result();53 }54 public function get_product_stock($product_id)55 {56 $status_array = array(1,2,3,4,5,6);57 $this->db->select('product_id,sum(quantity) as tot_sold');58 $this->db->from('tblblk_product_orders order');59 $this->db->join('tblblk_order_items AS items','items.order_id = order.order_id','LEFT');60 $this->db->where(array('items.product_id'=>$product_id,'items.order_item_status'=>1));61 $this->db->where_in('order.order_status',$status_array);62 $this->db->group_by('product_id');63 $query = $this->db->get();64 if($query->num_rows() > 0)65 return $query->row()->tot_sold;66 else67 return 0;68 }69 public function get_product_color($product_id)//Get color according to product group 70 { 71 $this->db->select('product.product_id, product.product_url,colors.color_id, colors.color_name, image.image_name,tblblk_product_size_color.color_id');72 $this->db->from('tblblk_product AS product');73 //$this->db->join('tblblk_colors AS colors','colors.color_id = product.color_id','LEFT');74 $this->db->join('tblblk_product_size_color','tblblk_product_size_color.product_id = product.product_id','LEFT');75 $this->db->join('tblblk_colors as colors','colors.color_id = tblblk_product_size_color.color_id','LEFT');76 // / $this->db->join('tblblk_colors AS colors','colors= color_id.color_id','LEFT');77 $this->db->join('tblblk_product_images AS image','image.product_id = product.product_id','LEFT');78 //$this->db->where(array('product.group_id'=>$group_id,'product.seller_id'=>$seller_id,'product.product_status'=>4,'product.is_active'=>'Y'));79 $this->db->where(array('product.product_id'=>$product_id,'product.product_status'=>4,'product.is_active'=>'Y'));80 $this->db->group_by('colors.color_id');81 $query = $this->db->get();82 //echo $this->db->last_query();exit;83 return $query->result();84 }85 public function get_product_size($product_id)86 {87 $this->db->select('product.product_id, product.product_url,product_size.size_id,product_size.size_name,color.color_id,color.color_name');88 $this->db->from('tblblk_product AS product');89 $this->db->join('tblblk_product_size_color AS size_color','size_color.product_id = product.product_id','LEFT');90 $this->db->join('tblblk_product_sizes AS product_size','product_size.size_id = size_color.size_id','LEFT'); 91 $this->db->join('tblblk_colors AS color','color.color_id = size_color.color_id','LEFT'); 92 $this->db->where(array('product.product_id'=>$product_id,'product.product_status'=>4,'product.is_active'=>'Y','available_in_pcs'=>1));93 //$this->db->group_by('product_size.size_id');94 $query = $this->db->get();95 //echo $this->db->last_query();exit;96 return $query->result();97 }98 public function check_pincode_availability($data)//product.color_id'99 {100 $this->db->select('pincode.pincode_id, pincode.pincode, pincode.cod, pincode.city, pincode.state,pincode.value_capping');101 $this->db->from('tblblk_city_pincode AS pincode');102 $this->db->where('pincode',$data);103 $query = $this->db->get();104 return $query->row();105 }106 107 public function Product_Buyer_Visitor($ip,$product_id)108 {109 $data = array('visitor_ip_address'=>$ip,'product_id'=>$product_id);110 $sql = $this->db->insert_string('tblblk_buyer_visitor', $data) . " ON DUPLICATE KEY UPDATE modified_date = '".date('Y-m-d h:s:m')."'";//2016-11-26 05:46:46111 $this->db->query($sql);112 //echo $this->db->last_query();exit;113 }114 public function getSubtoSubCategory($product_id,$product_url)115 {116 $this->db->select('product.subtosub_category_id'); 117 $this->db->from('tblblk_product AS product');118 $this->db->join('tblblk_subtosub_category AS subtosub_category','subtosub_category.subtosub_category_id = product.subtosub_category_id','LEFT');119 $where = array('subtosub_category.status'=>1,'product.product_status'=>4,'product.is_active'=>'Y');120 $this->db->where($where);121 $this->db->where(array('product.product_id'=>$product_id,'product.product_url'=>$product_url));...
admin.product.php
Source:admin.product.php
1<?php2$this->setCurrentSite('admin')3 ->setCurrentAccess('super')4 // product5 ->get('/product', ['as' => 'admin-product', 'action' => 'Admin\Ui\ProductController@index'])6 ->get('/product/search', ['as' => 'admin-product-search', 'action' => 'Admin\Ui\ProductController@search'])7 ->get('/product/add', ['as' => 'admin-product-add', 'action' => 'Admin\Ui\ProductController@add'])8 ->post('/product/add', ['as' => 'admin-product-add-post', 'action' => 'Admin\Ui\ProductController@addPost'])9 ->get('/product/{eid:[0-9]+}/delete', ['as' => 'admin-product-delete', 'action' => 'Admin\Ui\ProductController@delete'])10 ->post('/product/{eid:[0-9]+}/delete', ['as' => 'admin-product-delete-post', 'action' => 'Admin\Ui\ProductController@deletePost'])11 ->get('/product/{eid:[0-9]+}', ['as' => 'admin-product-show', 'action' => 'Admin\Ui\ProductController@show'])12 ->get('/product/{eid:[0-9]+}/content', ['as' => 'admin-product-content', 'action' => 'Admin\Ui\ProductController@content'])13 ->get('/product/{eid:[0-9]+}/edit', ['as' => 'admin-product-edit', 'action' => 'Admin\Ui\ProductController@edit'])14 ->post('/product/{eid:[0-9]+}/edit', ['as' => 'admin-product-edit-post', 'action' => 'Admin\Ui\ProductController@editPost'])15 ->get('/product/{eid:[0-9]+}/property', ['as' => 'admin-product-property', 'action' => 'Admin\Ui\ProductController@property'])16 ->get('/product/{eid:[0-9]+}/purchase', ['as' => 'admin-ui-product-purchase', 'action' => 'Admin\Ui\ProductPurchaseController@purchase'])17 ->get('/product/{eid:[0-9]+}/purchase/add', ['as' => 'admin-ui-product-purchase-add', 'action' => 'Admin\Ui\ProductPurchaseController@add'])18 ->post('/product/{eid:[0-9]+}/purchase/add', ['as' => 'admin-ui-product-purchase-add_post', 'action' => 'Admin\Ui\ProductPurchaseController@addPost'])19 ->get('/product/{eid:[0-9]+}/purchase/{pid:[0-9]+}/edit', ['as' => 'admin-ui-product-purchase-edit', 'action' => 'Admin\Ui\ProductPurchaseController@edit'])20 ->post('/product/{eid:[0-9]+}/purchase/{pid:[0-9]+}/edit', ['as' => 'admin-ui-product-purchase-edit_post', 'action' => 'Admin\Ui\ProductPurchaseController@editPost'])21 ->get('/product/{eid:[0-9]+}/purchase/{pid:[0-9]+}/delete', ['as' => 'admin-ui-product-purchase-delete', 'action' => 'Admin\Ui\ProductPurchaseController@delete'])22 ->post('/product/{eid:[0-9]+}/purchase/{pid:[0-9]+}/delete', ['as' => 'admin-ui-product-purchase-delete_post', 'action' => 'Admin\Ui\ProductPurchaseController@deletePost'])23 //product-feature24 ->get('/product/{eid:[0-9]+}/feature', ['as' => 'admin-product-feature', 'action' => 'Admin\Ui\ProductController@feature'])25 ->get('/product/{eid:[0-9]+}/feature/add', ['as' => 'admin-product-feature-add', 'action' => 'Admin\Ui\ProductController@addFeature'])26 ->post('/product/{eid:[0-9]+}/feature/add', ['as' => 'admin-product-feature-add-post', 'action' => 'Admin\Ui\ProductController@addFeaturePost'])27 //product-solved28 ->get('/product/{eid:[0-9]+}/solved', ['as' => 'admin-product-solved', 'action' => 'Admin\Ui\ProductController@solved'])29 ->get('/product/{eid:[0-9]+}/solved/add', ['as' => 'admin-product-solved-add', 'action' => 'Admin\Ui\ProductController@addSolved'])30 ->post('/product/{eid:[0-9]+}/solved/add', ['as' => 'admin-product-solved-add-post', 'action' => 'Admin\Ui\ProductController@addSolvedPost'])31 // product-improving32 ->get('/product/{eid:[0-9]+}/improving', ['as' => 'admin-product-improving', 'action' => 'Admin\Ui\ProductController@improving'])33 ->get('/product/{eid:[0-9]+}/improving/add', ['as' => 'admin-product-improving-add', 'action' => 'Admin\Ui\ProductController@addImproving'])34 ->post('/product/{eid:[0-9]+}/improving/add', ['as' => 'admin-product-improving-add-post', 'action' => 'Admin\Ui\ProductController@addImprovingPost'])35 // product-pbranch36 ->get('/product/{eid:[0-9]+}/pbranch', ['as' => 'admin-product-pbranch', 'action' => 'Admin\Ui\ProductController@pbranch'])37 ->get('/product/{eid:[0-9]+}/pbranch/add', ['as' => 'admin-product-pbranch-add', 'action' => 'Admin\Ui\ProductController@addPbranch'])38 ->post('/product/{eid:[0-9]+}/pbranch/add', ['as' => 'admin-product-pbranch-add-post', 'action' => 'Admin\Ui\ProductController@addPbranchPost'])39 ->get('/product/{eid:[0-9]+}/pbranch/{pbranch_id:[0-9]+}/edit', ['as' => 'admin-product-pbranch-edit', 'action' => 'Admin\Ui\ProductController@editPbranch'])40 ->post('/product/{eid:[0-9]+}/pbranch/{pbranch_id:[0-9]+}/edit', ['as' => 'admin-product-pbranch-edit-post', 'action' => 'Admin\Ui\ProductController@editPbranchPost'])41 // product-ptag42 ->get('/product/{eid:[0-9]+}/ptag', ['as' => 'admin-product-ptag', 'action' => 'Admin\Ui\ProductController@ptag'])43 ->get('/product/{eid:[0-9]+}/ptag/add', ['as' => 'admin-product-ptag-add', 'action' => 'Admin\Ui\ProductController@addPtag'])44 ->post('/product/{eid:[0-9]+}/ptag/add', ['as' => 'admin-product-ptag-add-post', 'action' => 'Admin\Ui\ProductController@addPtagPost'])45 ->get('/product/{eid:[0-9]+}/ptag/{ptag_id:[0-9]+}/edit', ['as' => 'admin-product-ptag-edit', 'action' => 'Admin\Ui\ProductController@editPtag'])46 ->post('/product/{eid:[0-9]+}/ptag/{ptag_id:[0-9]+}/edit', ['as' => 'admin-product-ptag-edit-post', 'action' => 'Admin\Ui\ProductController@editPtagPost'])47 // product-ptarget48 ->get('/product/{eid:[0-9]+}/ptarget', ['as' => 'admin-product-ptarget', 'action' => 'Admin\Ui\ProductController@ptarget'])49 ->get('/product/{eid:[0-9]+}/ptarget/add', ['as' => 'admin-product-ptarget-add', 'action' => 'Admin\Ui\ProductController@addPtarget'])50 ->post('/product/{eid:[0-9]+}/ptarget/add', ['as' => 'admin-product-improving-add-post', 'action' => 'Admin\Ui\ProductController@addPtargetPost'])51 ->get('/product/{eid:[0-9]+}/ptarget/{ptarget_id:[0-9]+}/edit', ['as' => 'admin-product-ptarget-edit', 'action' => 'Admin\Ui\ProductController@editPtarget'])52 ->post('/product/{eid:[0-9]+}/ptarget/{ptarget_id:[0-9]+}/edit', ['as' => 'admin-product-ptarget-edit-post', 'action' => 'Admin\Ui\ProductController@editPtargetPost'])53 //product-company54 ->get('/product/{eid:[0-9]+}/company',['as' => 'admin-ui-product_company','action' => 'Admin\Ui\ProductCompanyController@list'])55 ->get('/product/{eid:[0-9]+}/company/link',['as' => 'admin-ui-product_company-link','action' => 'Admin\Ui\ProductCompanyController@link'])56 ->post('/product/{eid:[0-9]+}/company/link',['as' => 'admin-ui-product_company-link_post','action' => 'Admin\Ui\ProductCompanyController@linkPost'])57 ->get('/product/{eid:[0-9]+}/company/{gid:[0-9]+}/unlink',['as' => 'admin-ui-product_company-unlink','action' => 'Admin\Ui\ProductCompanyController@unlink'])58 ->post('/product/{eid:[0-9]+}/company/{gid:[0-9]+}/unlink',['as' => 'admin-ui-product_company-unlink_post','action' => 'Admin\Ui\ProductCompanyController@unlinkPost'])59 //brand-tag60 ->get('/product/{eid:[0-9]+}/brand-tag',['as' => 'admin-ui-product_brand_tag-show','action' => 'Admin\Ui\ProductBrandTagController@show']);
Product
Using AI Code Generation
1require_once 'CucumberCommonLibrary.php';2use CucumberCommonLibrary\Product;3require_once 'CucumberCommonLibrary.php';4use CucumberCommonLibrary\Product;5require_once 'CucumberCommonLibrary.php';6use CucumberCommonLibrary\Product;7require_once 'CucumberCommonLibrary.php';8use CucumberCommonLibrary\Product;9require_once 'CucumberCommonLibrary.php';10use CucumberCommonLibrary\Product;11require_once 'CucumberCommonLibrary.php';12use CucumberCommonLibrary\Product;13require_once 'CucumberCommonLibrary.php';14use CucumberCommonLibrary\Product;15require_once 'CucumberCommonLibrary.php';16use CucumberCommonLibrary\Product;17require_once 'CucumberCommonLibrary.php';18use CucumberCommonLibrary\Product;19require_once 'CucumberCommonLibrary.php';20use CucumberCommonLibrary\Product;21require_once 'CucumberCommonLibrary.php';22use CucumberCommonLibrary\Product;23require_once 'CucumberCommonLibrary.php';24use CucumberCommonLibrary\Product;25require_once 'CucumberCommonLibrary.php';26use CucumberCommonLibrary\Product;27require_once 'CucumberCommonLibrary.php';28use CucumberCommonLibrary\Product;29require_once 'CucumberCommonLibrary.php';30use CucumberCommonLibrary\Product;31require_once 'CucumberCommonLibrary.php';32use CucumberCommonLibrary;33$product = new CucumberCommonLibrary\Product();
Product
Using AI Code Generation
1require_once 'cucumber-common/Product.php';2$prod = new Product();3$prod->setPrice(100);4echo $prod->getPrice();5require_once 'cucumber-common/Product.php';6$prod = new Product();7$prod->setPrice(100);8echo $prod->getPrice();9require_once 'cucumber-common/Product.php';10$prod = new Product();11$prod->setPrice(100);12echo $prod->getPrice();13require_once 'cucumber-common/Product.php';14$prod = new Product();15$prod->setPrice(100);16echo $prod->getPrice();17require_once 'cucumber-common/Product.php';18$prod = new Product();19$prod->setPrice(100);20echo $prod->getPrice();21require_once 'cucumber-common/Product.php';22$prod = new Product();23$prod->setPrice(100);24echo $prod->getPrice();25require_once 'cucumber-common/Product.php';26$prod = new Product();27$prod->setPrice(100);28echo $prod->getPrice();29require_once 'cucumber-common/Product.php';30$prod = new Product();31$prod->setPrice(100);32echo $prod->getPrice();33require_once 'cucumber-common/Product.php';34$prod = new Product();35$prod->setPrice(100);36echo $prod->getPrice();37require_once 'cucumber-common/Product.php';38$prod = new Product();39$prod->setPrice(100);40echo $prod->getPrice();41require_once 'cucumber-common/Product.php';
Product
Using AI Code Generation
1require_once('Cucumber/Common/Product.php');2$obj = new Cucumber\Common\Product();3$obj->setProduct('Cucumber');4echo $obj->getProduct();5require_once('Cucumber/Common/Product.php');6$obj = new Cucumber\Common\Product();7$obj->setProduct('Cucumber');8echo $obj->getProduct();9require_once('Cucumber/Common/Product.php');10$obj = new Cucumber\Common\Product();11$obj->setProduct('Cucumber');12echo $obj->getProduct();13require_once('Cucumber/Common/Product.php');14$obj = new Cucumber\Common\Product();15$obj->setProduct('Cucumber');16echo $obj->getProduct();17require_once('Cucumber/Common/Product.php');18$obj = new Cucumber\Common\Product();19$obj->setProduct('Cucumber');20echo $obj->getProduct();21require_once('Cucumber/Common/Product.php');22$obj = new Cucumber\Common\Product();23$obj->setProduct('Cucumber');24echo $obj->getProduct();25require_once('Cucumber/Common/Product.php');26$obj = new Cucumber\Common\Product();27$obj->setProduct('Cucumber');28echo $obj->getProduct();29require_once('Cucumber/Common/Product.php');30$obj = new Cucumber\Common\Product();
Product
Using AI Code Generation
1require_once 'Cucumber/Common/Product.php';2$product = new Cucumber\Common\Product();3$product->setPrice(1.99);4$product->setName('Cucumber');5$product->setDescription('Cucumber is a vegetable');6echo $product->getName();7require_once 'Cucumber/Common/Product.php';8$product = new Cucumber\Common\Product();9$product->setPrice(1.99);10$product->setName('Cucumber');11$product->setDescription('Cucumber is a vegetable');12echo $product->getName();13require_once 'Cucumber/Common/Product.php';14$product = new Cucumber\Common\Product();15$product->setPrice(1.99);16$product->setName('Cucumber');17$product->setDescription('Cucumber is a vegetable');18echo $product->getName();19require_once 'Cucumber/Common/Product.php';20$product = new Cucumber\Common\Product();21$product->setPrice(1.99);22$product->setName('Cucumber');23$product->setDescription('Cucumber is a vegetable');24echo $product->getName();25require_once 'Cucumber/Common/Product.php';26$product = new Cucumber\Common\Product();27$product->setPrice(1.99);28$product->setName('Cucumber');29$product->setDescription('Cucumber is a vegetable');30echo $product->getName();31require_once 'Cucumber/Common/Product.php';32$product = new Cucumber\Common\Product();33$product->setPrice(1.99);34$product->setName('Cucumber');35$product->setDescription('Cucumber is a vegetable');36echo $product->getName();37require_once 'Cucumber/Common/Product.php';38$product = new Cucumber\Common\Product();39$product->setPrice(1.99);40$product->setName('Cucumber');41$product->setDescription('Cucumber is a vegetable');42echo $product->getName();43require_once 'Cucumber/Common/Product.php';44$product = new Cucumber\Common\Product();45$product->setPrice(1
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!