Magento Özel Seçenekler programatik almak nasıl

7 Cevap php

Ben kodu ile onlar için seçilen özel tüm seçenekleri elde edebilmek için gereken kasada bir kaç ürün var.

Herhangi bir yardım çok takdir!

7 Cevap

Sana sadece bir ürünün bir örnek vereceğim. Lütfen gereken ürünün (örneğin, "ABCDE" olsun) Diyelim SKU biliyorum diyelim. Yani bu ürünün kimliği almak mümkün olacak.

Kod biraz gibi olacak: -

$productSku = "ABCDE";
$product = Mage::getModel('catalog/product');
$productId = $product->getIdBySku( $productSku );
$product->load($productId);

/**
 * In Magento Models or database schema level, the product's Custom Options are
 * executed & maintained as only "options". So, when checking whether any product has
 * Custom Options or not, we should check by using this method "hasOptions()" only.
 */
if($product->hasOptions()) {
    echo '<pre>';

    foreach ($product->getOptions() as $o) {
        $optionType = $o->getType();
        echo 'Type = '.$optionType;

        if ($optionType == 'drop_down') {
            $values = $o->getValues();

            foreach ($values as $k => $v) {
                print_r($v);
            }
        }
        else {
            print_r($o);
        }
    }

    echo '</pre>';
}

Ben bu başlamanıza izin düşünüyorum.

Değişkeninde seçeneği türüne bağlı olarak "$optionType", başka bir iç içe "foreach" döngü aramak gerekir. Ben metin kutuları, metin alanları, açılan çıkışlar, ancak diğer türleri üzerinde çalıştım. Bu yüzden biraz daha kendiniz RND yapmak gerekir herhalde.

For those who want to see selected custom options later in admin panel in Order/Invoice/Shipment/Creditmemo, find files: /app/design/adminhtml/[default]/default/template/sales/order/view/items/renderer/default.phtml
/app/design/adminhtml/[default]/default/template/sales/order/invoice/view/items/renderer/default.phtml /app/design/adminhtml/[default]/default/template/sales/order/shipment/view/items/renderer/default.phtml /app/design/adminhtml/[default]/default/template/sales/order/creditmemo/view/items/renderer/default.phtml PS: I haven't changed configurated.phtml files for invoice/shipment/creditmemo

and insert code somewhere after <?php echo $_item->getSku(); ?></div> and before it's row's closing tag </td> (be careful, it's different for each file)

Kodu eklemek:

        <?php  
    //---------start:---------------          
    // if ($allOptions = $_item->_getData('product_options')) {             // only for order item
    if ($allOptions = $_item->getOrderItem()->getData('product_options')) { // for invoice, shipping, creditmemo
        $options = unserialize($allOptions);

        if (isset($options['options'])) { 
            foreach ($options['options'] as $optionValues) {
                if ($optionValues['value']) {
                    echo '&nbsp;<strong><i>'. $optionValues['label'].'</i></strong>: ';

                    $_printValue = isset($optionValues['print_value']) ? $optionValues['print_value'] : strip_tags($optionValues['value']);
                    $values = explode(', ', $_printValue);
                    foreach ($values as $value) {
                        if (is_array($value))
                          foreach ($value as $_value) 
                              echo $_value;
                        else echo $value; 
                    }
                    echo '<br />';
                }
            }    
        }
    }
    //---------end:---------------                  
    ?>        

Also note that in code there is a line (if sentence) that works only in order default.phtml file, and the second if sentence works in invoice/shipping/creditmemo files. It depends where you post the code, make sure the right sentence is commented out.

hope this helps, thanks also to Knowledge Craving whose code helped me quite a bit :-) jazkat

Lütfen dikkat

$product->hasCustomOptions()

"Bilgi Craving" 's her zaman çözüm (en azından benim durumumda, Magento 1.6.2 olarak) return false gelmez. Bu nedenle eğer koşulu yerine asla ve aşağıdaki blok yürütülür.

    $quote=$observer->getEvent()->getQuote();
    $quoteid=$quote->getId();
    $session= Mage::getSingleton('checkout/session');
    $getotal = Mage::helper('checkout')->getQuote()->getGrandTotal();

    foreach($session->getQuote()->getAllItems() as $item)
        {

         $sellcheck = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getissellbool();
         $options = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getProductOptionsCollection();
         foreach ($options as $o) 
             { 
                $title = $o->getTitle();
                $values = $o->getValues();
                foreach($values as $v)
                  {
                     $mydata = $v->getPrice();
                     echo 'options price: ' . $mydata;                      
                        }

               } 

          }

Alışveriş sepeti, ürün özel seçeneklere erişmek için bu kodu kullanabilir.

Ben size yararlı olacak Ürün sayfasında sadece Custom açılan değerleri almak için umut

Sadece geçen bu dosyaya aşağıdaki kodu yapıştırın

app / tasarım / frontend / baz / default / template / katalog / ürün / view / options.phtml

<?php
    $product = Mage::getModel("catalog/product")->load($this->getProduct()->getId()); //product id
    foreach ($product->getOptions() as $_option) {
        $values = $_option->getValues();
        foreach ($values as $v) {
            print_r($v->getTitle());
            echo "<br />";
        }
    }
?>

Biz de ödeme sayfasında görüntülemek ki, böyle çözebilir.

 $items = Mage::getModel('checkout/cart')->getQuote()->getAllVisibleItems();
 foreach($items as $product) {
     $options = $product->getProduct()->getTypeInstance(true)->getOrderOptions($product->getProduct());
     if ($options)
     {
        if (isset($options['options']))
        {
           $result = $options['options'];
        }
        if(count($result)>0){
           foreach($result as $key =>$value){
                $resultoption =  $value['value'];
           }
        }
    }

Şablon / çıkış / sepeti / item / default.php bu kodu deneyebilirsiniz:

if($Product->hasOptions)
            {
                $optionsArr = $Product->getOptions();
                 foreach ($optionsArr as  $optionKey => $optionVal)
                {
                          $optStr.= "<select style='display:block; clear:both;' name='options[".$optionVal->getId()."]'>";    
                  foreach($optionVal->getValues() as $valuesKey => $valuesVal)
                    {
                          $optStr.= "<option value='".$valuesVal->getId()."'>".$valuesVal->getTitle()."</option>";
                    }
                    $optStr.= "</select>";
                    }
   echo($optStr ); 
            }