I have defined some custom attributes and assigned them to products via the Opencart admin panel. I'm trying to retrieve these attributes upon checkout to adjust some shipping costs.
I'm currently working in the catalog/model/shipping/ups.php file in the getQuote function. I'm getting close with this:
print_r($this->cart->getProducts());
Which gives me the following product data:
Array
(
[59] => Array
(
[key] => 59
[product_id] => 59
[name] => My Product Name
[model] => ABC
[shipping] => 1
[image] => data/myproduct.jpg
[option] => Array
(
)
[download] => Array
(
)
[quantity] => 1
[minimum] => 1
[subtract] => 1
[stock] => 1
[price] => 29.99
[total] => 29.99
[reward] => 0
[points] => 0
[tax_class_id] => 0
[weight] => 3.75
[weight_class_id] => 5
[length] => 0.00
[width] => 0.00
[height] => 0.00
[length_class_id] => 3
)
)
However, no custom attributes are returned. I'm sure there is a nice way to pass the product ID to an attribute-getting function, but I can't find it. The Opencart docs are a little lacking for the development side and no luck on Google.
Usually I'd grep the hell out of the whole directory structure to find what I'm looking for, but shell access is disabled on this particular web host :(.
EDIT
I believe Attributes are a newer feature that is built into Opencart. Its like a custom field.
Anyway, on the admin side I went to Catalog > Attributes and created a custom attribute called "Shipping Box Type". Then, under a specific product I can set the attribute. See screenshot. My goal is to retrieve the value of "Shipping Box Type". Does that answer your question #Cleverbot? I'm sure I can do a custom db query to grab it, but theres got to be a built-in function to grab attributes?
Retrieve attributes for a given product_id
$this->load->model('catalog/product');
$attributes = $this->model_catalog_product->getProductAttributes(59);
print_r($attributes);
Output
Array
(
[0] => Array
(
[attribute_group_id] => 9
[name] => Shipping Fields
[attribute] => Array
(
[0] => Array
(
[attribute_id] => 16
[name] => Shipping Box Type
[text] => SM2
)
)
)
)
Taking it further, here is an example of looping through the products currently in the cart to see what attributes they have:
$this->load->model('catalog/product');
$cart_products = $this->cart->getProducts();
// get attributes for each product in the cart
foreach($cart_products as $product) {
$attributes = $this->model_catalog_product->getProductAttributes($product['product_id']);
print_r($attributes);
}
This is not the most intuitive feature in Opencart. First you have to go catalog>attributes>attribute groups and you have to create a group name that will be a title for your attribute. For this it might be "Shipping Specifications".
Then you need to go to catalog>attributes>attributes> and create a new attribute under "Shipping Specifications" named "Shipping Box Type".
Now you are ready to go to catalog>products and add the attribute to a product.
The catch is that it won't be displayed how you were hoping I think. It will show up under the specifications tab next to description on your products page. You have the easy option of changing "Specifications" to the Heading of your choice in catalog/view/*your_theme*/products/products.tpl or you can edit the same tpl file to change the container/format that the data output goes.
Related
I've a problem. I'm currently writing a WordPress plugin for WooCommerce which reads out an order for a booking system.
The booking system has an own field for cod costs (costs on delivery / Nachnahmegbühr (deutsch)). The problem is that I can't find a method to read this cost from an order.
If I read out the fees from the order via $order->get_fees(), I can see the cod costs but this is not safe enough cause the fee name is always in the shop language which makes it nearly impossible to read out the cod costs this way (in an international plugin):
[data:protected] => Array
(
[order_id] => 24
[name] => Zahlungsgebühr
[tax_class] => 0
[tax_status] => taxable
[amount] => 2.16
[total] => 2.16
[total_tax] => 0.34
[taxes] => Array
(
[total] => Array
(
[6] => 0.344828
)
)
)
So is there any known way to get this kind of costs?
Iam developing a codeigniter POS system project.
I have separate sections to product sale and product GRN. both are using codeigniter cart library
in product sale section I created instance called : ocart
$this->load->library('cart','','ocart');
$ocart = $this->ocart->contents();
$this->ocart->destroy();
$this->ocart->insert($data);
product GRN section I created separate instance called : pcart
$this->load->library('cart','','pcart');
$pcart = $this->pcart->contents();
$this->pcart->destroy();
$this->pcart->insert($data);
When Im going to add product to the cart in sale section, same time same product added to the product GRN cart also. and wise versa.
then I checked array contents using print_r($pcart) and print_r($ocart);
both giving same output
Array
(
[6b913a2317d00f7bfa0abdaff1a1f67f] => Array
(
[rowid] => 6b913a2317d00f7bfa0abdaff1a1f67f
[id] => 22020
[pcode] => DS141
[note] => PLATE
[qty] => 20
[price] => 1
[name] => 97280
[subtotal] => 20
)
)
what is wrong with above code, please advice.
There is no built-in method to destroy loaded library object.
You can do simply like that by using unset or setting null.
unset($this->my_library);
OR
$this->my_library = null;
I'm working on a WordPress custom theme and stuck in achieving the following functionality. I don't even know is that even possible!
I want to display child categories when I click on a a parent category and then clicking child category will bring you posts from it. Doing it in archive.php will be suitable or a custom template?
Help and suggestions would greatly appreciated :)
Found a solution myself and sharing it so it will help someone who is in need:
Well I have done it using archive.php and I used get_queried_object() to get the currently-queried object which gives me an object by doing the following:
$obj = get_queried_object();
print_r($obj);
and it will gives us the following object:
WP_Term Object
(
[term_id] => 24
[name] => BRIDAL
[slug] => bridal
[term_group] => 0
[term_taxonomy_id] => 24
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 0
[filter] => raw
[cat_ID] => 24
[category_count] => 0
[category_description] =>
[cat_name] => BRIDAL
[category_nicename] => bridal
[category_parent] => 0
)
You can see that there is a [parent] => 0 in the object above. So in my case I did it like this:
$obj = get_queried_object();
if ($obj->parent == 0) {
// Display child categories on this cat
} else {
// Display posts of the child category
}
Hope it will be helpful to someone 🙂
I am currently trying to export a number of products from a custom CMS MYSQL database into a Magento compatible database.
The products include product descriptions which is stored as HTML that was serialised in a "ob_data" array with some other info when they were added through CMS system. Here is an example of one:
Array
(
[id] => 1085
[type] => 9
[url_key] => royal-worcester-mikado-milk-jug
[name] => Royal Worcester Mikado 1/2 Pint Milk Jug
[pattern] => Mikado
[manufacturer] => Royal Worcester
[stock] => 0
[content] => <p>Bone china<br />Holds approx1/2 pint.<br />Excellent condition.</p>
[weight] => 0.75
[price] => 20.00
[image] => /media/dContent/eCommerce/old/165.jpg
)
Using unserialze I can extract this and some other info into an array which can be written to the CSV. However when I write this information to a CSV file with fputcsv I get the following:
1085,9,royal-worcester-mikado-milk-jug,"Royal Worcester Mikado 1/2 Pint Milk Jug",Mikado,"Royal Worcester",0,"<p>Bone china<br />
Holds approx 1/2 pint.<br />
Excellent condition.</p>",0.75,20.00,/media/dContent/eCommerce/old/165.jpg
Essentially the <br/> tags that are in the description are also adding new lines in my CSV breaking its format and making it impossible to import.
Is there anyway that I can stop this happening and format the content so that it can comfortably written into the CSV?
I'm using weight based shipping but I don't want the weight information to be displayed in the checkout page. Right now the displayed information is "USA (Weight: 0.00kg) $24.30", but all I want to be displayed is "USA $24.30".
In controller/checkout/shipping I'm printing the $this->data['shipping_methods'] variable, getting the following array:
Array
(
[weight] => Array
(
[title] => Weight Based Shipping
[quote] => Array
(
[weight_11] => Array
(
[id] => weight.weight_11
[title] => USA (Weight: 0.00kg)
[cost] => 24.3
[tax_class_id] => 0
[text] => $24.30
)
)
[sort_order] => 1
[error] =>
)
)
What I need is to, for each $this->data['shipping_methods']['weight']['quote'], change the title to a substr to minus 16 characters, in order display only the country info (USA, in this case).
How can I do this?
Open up file catalog/model/shipping/weight.php, find this line:
'title' => $result['name'] . ' (' . $this->language->get('text_weight') . ' ' . $this->weight->format($weight, $this->config->get('config_weight_class_id')) . ')',
replace with
'title' => $result['name'],
done.
Best when applied via vQmod extension.